From ec97e17ad58044c1112789b95dc3be97478049ce Mon Sep 17 00:00:00 2001 From: kwaroran Date: Sun, 9 Jun 2024 20:04:34 +0900 Subject: [PATCH] chore: Update characterCards.ts to improve asset path handling --- src/ts/characterCards.ts | 48 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/ts/characterCards.ts b/src/ts/characterCards.ts index b22c4e9c..1ef598ab 100644 --- a/src/ts/characterCards.ts +++ b/src/ts/characterCards.ts @@ -939,6 +939,7 @@ export async function exportCharacterCard(char:character, type:'png'|'json'|'cha } else{ let type = 'other' + let itype = 'other' switch(card.data.assets[i].type){ case 'emotion': type = 'emotion' @@ -953,13 +954,56 @@ export async function exportCharacterCard(char:character, type:'png'|'json'|'cha type = 'icon' break } + switch(card.data.assets[i].ext){ + case 'png': + case 'jpg': + case 'jpeg': + case 'gif': + case 'webp': + case 'avif': + itype = 'image' + break + case 'mp3': + case 'wav': + case 'ogg': + case 'flac': + itype = 'audio' + break + case 'mp4': + case 'webm': + case 'mov': + case 'avi': + case 'mkv': + itype = 'video' + break + case 'mmd': + case 'obj': + itype = 'model' + break + case 'safetensors': + case 'cpkt': + case 'onnx': + itype = 'ai' + break + case 'otf': + case 'ttf': + case 'woff': + case 'woff2': + itype = 'fonts' + break + case 'js': + case 'ts': + case 'lua': + itype = 'code' + } + let path = '' const name = `${assetIndex}` if(card.data.assets[i].ext === 'unknown'){ - path = `assets/${type}/${name}.png` + path = `assets/${type}/image/${name}.png` } else{ - path = `assets/${type}/${name}.${card.data.assets[i].ext}` + path = `assets/${type}/${itype}/${name}.${card.data.assets[i].ext}` } card.data.assets[i].uri = 'embeded://' + path await writer.write(path, rData)