feat: Enable dynamic assets for processing data and replace missing asset names with the closest match
This commit is contained in:
@@ -77,7 +77,7 @@ DOMPurify.addHook("uponSanitizeAttribute", (node, data) => {
|
||||
})
|
||||
|
||||
|
||||
const assetRegex = /{{(raw|img|video|audio|bg|emotion|asset|video-img)::(.+?)}}/g
|
||||
export const assetRegex = /{{(raw|img|video|audio|bg|emotion|asset|video-img)::(.+?)}}/g
|
||||
|
||||
async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|character, mode:'normal'|'back', mode2:'unset'|'pre'|'post' = 'unset'){
|
||||
const db = get(DataBase)
|
||||
|
||||
@@ -5,12 +5,13 @@ import { downloadFile } from "../storage/globalApi";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
import { selectSingleFile } from "../util";
|
||||
import { risuChatParser as risuChatParserOrg, type simpleCharacterArgument } from "../parser";
|
||||
import { assetRegex, risuChatParser as risuChatParserOrg, type simpleCharacterArgument } from "../parser";
|
||||
import { autoMarkPlugin } from "../plugins/automark";
|
||||
import { runCharacterJS } from "../plugins/embedscript";
|
||||
import { metricaPlugin } from "../plugins/metrica";
|
||||
import { OaiFixKorean } from "../plugins/fixer";
|
||||
import { getModuleRegexScripts } from "./modules";
|
||||
import { HypaProcesser } from "./memory/hypamemory";
|
||||
|
||||
const dreg = /{{data}}/g
|
||||
const randomness = /\|\|\|/g
|
||||
@@ -211,6 +212,26 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(db.dynamicAssets && (char.type === 'simple' || char.type === 'character') && char.additionalAssets && char.additionalAssets.length > 0){
|
||||
const assetNames = char.additionalAssets.map((v) => v[0])
|
||||
const processer = new HypaProcesser('MiniLM')
|
||||
await processer.addText(assetNames)
|
||||
const matches = data.matchAll(assetRegex)
|
||||
|
||||
for(const match of matches){
|
||||
const type = match[1]
|
||||
const assetName = match[2]
|
||||
if(!assetNames.includes(assetName)){
|
||||
const searched = await processer.similaritySearch(assetName)
|
||||
const bestMatch = searched[0]
|
||||
if(bestMatch){
|
||||
data = data.replaceAll(match[0], `{{${type}::${bestMatch}}}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {data, emoChanged}
|
||||
}
|
||||
|
||||
|
||||
46
src/ts/realm.ts
Normal file
46
src/ts/realm.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { get } from "svelte/store";
|
||||
import { exportSpecV2 } from "./characterCards";
|
||||
import { VirtualWriter } from "./storage/globalApi";
|
||||
import { sleep } from "./util";
|
||||
import { CurrentCharacter } from "./stores";
|
||||
import { DataBase, type character } from "./storage/database";
|
||||
import { alertStore } from "./alert";
|
||||
|
||||
let pong = false;
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event.origin === "https://realm.risuai.net") {
|
||||
if (event.data === "pong") {
|
||||
pong = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export async function shareRealmCard() {
|
||||
const char = structuredClone(get(CurrentCharacter)) as character
|
||||
const writer = new VirtualWriter()
|
||||
await exportSpecV2(char, 'png', {writer: writer})
|
||||
openRealm(char.name, writer.buf.buffer)
|
||||
}
|
||||
|
||||
export async function openRealm(name:string,data:ArrayBuffer) {
|
||||
const tk = get(DataBase)?.account?.token;
|
||||
const id = get(DataBase)?.account?.id
|
||||
const win = window.open(`https://realm.risuai.net/upload?token=${tk}&token_id=${id}`, "_blank");
|
||||
pong = false;
|
||||
while(true){
|
||||
if(pong){
|
||||
break;
|
||||
}
|
||||
win.postMessage("ping", "https://realm.risuai.net")
|
||||
await sleep(500);
|
||||
}
|
||||
alertStore.set({
|
||||
type: 'none',
|
||||
msg: ''
|
||||
})
|
||||
|
||||
const nameBuf = new TextEncoder().encode(name);
|
||||
|
||||
win.postMessage("filedata", "https://realm.risuai.net", [nameBuf,data]);
|
||||
}
|
||||
@@ -655,6 +655,7 @@ export interface Database{
|
||||
sideBarSize:number
|
||||
textAreaTextSize:number
|
||||
combineTranslation:boolean
|
||||
dynamicAssets:boolean
|
||||
}
|
||||
|
||||
export interface customscript{
|
||||
|
||||
Reference in New Issue
Block a user