feat: Add @risuai/ccardlib dependency and update characterCards.ts
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
"@dqbd/tiktoken": "^1.0.7",
|
||||
"@huggingface/jinja": "^0.2.2",
|
||||
"@mlc-ai/web-tokenizers": "^0.1.2",
|
||||
"@risuai/ccardlib": "^0.3.0",
|
||||
"@smithy/protocol-http": "^3.0.12",
|
||||
"@smithy/signature-v4": "^2.0.19",
|
||||
"@tauri-apps/api": "1.5.3",
|
||||
|
||||
8245
pnpm-lock.yaml
generated
8245
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@ import { characterFormatUpdate } from "./characters"
|
||||
import { AppendableBuffer, checkCharOrder, downloadFile, loadAsset, LocalWriter, readImage, saveAsset, VirtualWriter } from "./storage/globalApi"
|
||||
import { CurrentCharacter, selectedCharID } from "./stores"
|
||||
import { convertImage, hasher } from "./parser"
|
||||
|
||||
import { CCardLib } from '@risuai/ccardlib'
|
||||
import { reencodeImage } from "./process/files/image"
|
||||
import { PngChunk } from "./pngChunk"
|
||||
import type { OnnxModelFiles } from "./process/transformers"
|
||||
@@ -70,6 +70,7 @@ async function importCharacterProcess(f:{
|
||||
|
||||
// const readed = PngChunk.read(img, ['chara'])?.['chara']
|
||||
let readedChara = ''
|
||||
let readedCCv3 = ''
|
||||
let img:Uint8Array
|
||||
const readGenerator = PngChunk.readGenerator(f.data, {
|
||||
returnTrimed: true
|
||||
@@ -85,12 +86,18 @@ async function importCharacterProcess(f:{
|
||||
break
|
||||
}
|
||||
if(chunk.key === 'chara'){
|
||||
//For memory reason, limit to 2MB
|
||||
if(readedChara.length < 2 * 1024 * 1024){
|
||||
//For memory reason, limit to 5MB
|
||||
if(readedChara.length < 5 * 1024 * 1024){
|
||||
readedChara = chunk.value
|
||||
}
|
||||
continue
|
||||
}
|
||||
if(chunk.key === 'ccv3'){
|
||||
if(readedCCv3.length < 5 * 1024 * 1024){
|
||||
readedCCv3 = chunk.value
|
||||
}
|
||||
continue
|
||||
}
|
||||
if(chunk.key.startsWith('chara-ext-asset_')){
|
||||
const assetIndex = (chunk.key.replace('chara-ext-asset_', ''))
|
||||
alertWait('Loading... (Reading Asset ' + assetIndex + ')' )
|
||||
@@ -99,11 +106,15 @@ async function importCharacterProcess(f:{
|
||||
assets[assetIndex] = assetId
|
||||
}
|
||||
}
|
||||
if(!readedChara){
|
||||
if(!readedChara && !readedCCv3){
|
||||
alertError(language.errors.noData)
|
||||
return
|
||||
}
|
||||
|
||||
if(!readedChara){
|
||||
readedChara = readedCCv3
|
||||
}
|
||||
|
||||
if(!img){
|
||||
console.error("No Image Found")
|
||||
alertError(language.errors.noData)
|
||||
@@ -164,10 +175,20 @@ async function importCharacterProcess(f:{
|
||||
}
|
||||
}
|
||||
else {
|
||||
const charaData:CharacterCardV2 = JSON.parse(Buffer.from(readedChara, 'base64').toString('utf-8'))
|
||||
if(await importSpecv2(charaData, img, "normal", assets)){
|
||||
let db = get(DataBase)
|
||||
return db.characters.length - 1
|
||||
const parsed = JSON.parse(Buffer.from(readedChara, 'base64').toString('utf-8'))
|
||||
const checkedVersion = CCardLib.character.check(parsed)
|
||||
if(checkedVersion === 'v2' || checkedVersion === 'v3'){
|
||||
const charaData:CharacterCardV2 = CCardLib.character.convert(parsed, {
|
||||
from: checkedVersion,
|
||||
to: 'v2',
|
||||
options: {
|
||||
convertRisuFields: true
|
||||
}
|
||||
})
|
||||
if(await importSpecv2(charaData, img, "normal", assets)){
|
||||
let db = get(DataBase)
|
||||
return db.characters.length - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
const charaData:OldTavernChar = JSON.parse(Buffer.from(readedChara, 'base64').toString('utf-8'))
|
||||
|
||||
Reference in New Issue
Block a user