[feat] apply yuso

This commit is contained in:
kwaroran
2023-07-24 20:55:43 +09:00
parent ca2096b4b8
commit 0d8dab3564
6 changed files with 103 additions and 133 deletions

View File

@@ -1,14 +1,13 @@
import { get, writable } from "svelte/store";
import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdDataFunc } from "./storage/database";
import exifr from 'exifr'
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore } from "./alert";
import { language } from "../lang";
import { PngMetadata } from "./exif";
import { encode as encodeMsgpack, decode as decodeMsgpack } from "msgpackr";
import { checkNullish, findCharacterbyId, selectMultipleFile, selectSingleFile, sleep } from "./util";
import { v4 as uuidv4 } from 'uuid';
import { selectedCharID } from "./stores";
import { checkCharOrder, downloadFile, getFileSrc, readImage } from "./storage/globalApi";
import * as yuso from 'yuso'
export function createNewCharacter() {
let db = get(DataBase)
@@ -493,9 +492,9 @@ export async function addDefaultCharacters() {
for(const img of imgs){
const imgBuffer = await (await img).arrayBuffer()
const readed = (await exifr.parse(imgBuffer, true))
const readed = yuso.decode(Buffer.from(imgBuffer), "risuai")
await sleep(10)
const va = decodeMsgpack(Buffer.from(readed.risuai, 'base64')) as any
const va = decodeMsgpack(Buffer.from(readed,'base64')) as any
if(va.type !== 101){
alertError(language.errors.noData)
return
@@ -521,7 +520,7 @@ export async function addDefaultCharacters() {
}
char.chatPage = 0
char.image = await saveImage(PngMetadata.filter(Buffer.from(imgBuffer)))
char.image = await saveImage(yuso.trim(Buffer.from(imgBuffer)))
char.chaId = uuidv4()
db.characters.push(characterFormatUpdate(char))
setDatabase(db)