feat: 绘画页面对接腾讯混元文生图

This commit is contained in:
2024-03-15 18:01:32 +08:00
parent 350a7ec626
commit e69774679a
8 changed files with 360 additions and 153 deletions

View File

@@ -0,0 +1,20 @@
export const useBlobUrlFromB64 = (dataurl: string): string => {
// data:image/jpeg;base64,/9j/...
const arr = dataurl.split(',')
if (arr.length < 2) {
throw new Error('dataurl is not a valid base64 image')
}
const mimeMatches = arr[0].match(/:(.*?);/)
if (mimeMatches === null) {
throw new Error('dataurl is not a valid base64 image')
}
const mime = mimeMatches[1] //image/png
const b64data = atob(arr[1])
let length = b64data.length
const u8arr = new Uint8Array(length)
while (length--) {
u8arr[length] = b64data.charCodeAt(length)
}
const blob = new Blob([u8arr], {type: mime})
return URL.createObjectURL(blob)
}

22
composables/useHistory.ts Normal file
View File

@@ -0,0 +1,22 @@
import {string} from 'yup';
import type {ResultBlockMeta} from '~/components/aigc/drawing';
export interface HistoryItem {
fid: string
data_id?: string
prompt: string
meta: ResultBlockMeta
images: string[]
}
export const useHistory = defineStore('aigc_history', () => {
const text2img = ref<HistoryItem[]>([])
return {
text2img
}
}, {
persist: {
storage: persistedState.localStorage
}
})

View File

@@ -59,6 +59,6 @@ export const useLoginState = defineStore('loginState', () => {
persist: {
key: 'xsh_assistant_persisted_state',
storage: persistedState.localStorage,
paths: ['token', 'user']
paths: ['is_logged_in', 'token', 'user']
}
})