Migrate all DataBase to DBState
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store"
|
||||
import { translatorPlugin } from "../plugins/plugins"
|
||||
import { DataBase, type character, type customscript, type groupChat } from "../storage/database.svelte"
|
||||
import { getDatabase, type character, type customscript, type groupChat } from "../storage/database.svelte"
|
||||
import { globalFetch, isTauri } from "../storage/globalApi"
|
||||
import { alertError } from "../alert"
|
||||
import { requestChatData } from "../process/request"
|
||||
@@ -10,7 +10,6 @@ import { selectedCharID } from "../stores"
|
||||
import { getModuleRegexScripts } from "../process/modules"
|
||||
import { getNodetextToSentence, sleep } from "../util"
|
||||
import { processScriptFull } from "../process/scripts"
|
||||
import { Capacitor } from "@capacitor/core"
|
||||
|
||||
let cache={
|
||||
origin: [''],
|
||||
@@ -20,7 +19,7 @@ let cache={
|
||||
let waitTrans = 0
|
||||
|
||||
export async function translate(text:string, reverse:boolean) {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const plug = await translatorPlugin(text, reverse ? db.translator: 'en', reverse ? 'en' : db.translator)
|
||||
if(plug){
|
||||
return plug.content
|
||||
@@ -105,7 +104,7 @@ export async function runTranslator(text:string, reverse:boolean, from:string,ta
|
||||
}
|
||||
|
||||
async function translateMain(text:string, arg:{from:string, to:string, host:string}){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(db.translatorType === 'llm'){
|
||||
const tr = db.translator || 'en'
|
||||
return translateLLM(text, {to: tr})
|
||||
@@ -208,7 +207,7 @@ async function jaTrans(text:string) {
|
||||
}
|
||||
|
||||
export function isExpTranslator(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return db.translatorType === 'llm' || db.translatorType === 'deepl' || db.translatorType === 'deeplX'
|
||||
}
|
||||
|
||||
@@ -216,7 +215,7 @@ export async function translateHTML(html: string, reverse:boolean, charArg:simpl
|
||||
let alwaysExistChar: character | groupChat | simpleCharacterArgument;
|
||||
if(charArg !== ''){
|
||||
if(typeof(charArg) === 'string'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const charId = get(selectedCharID)
|
||||
alwaysExistChar = db.characters[charId]
|
||||
}
|
||||
@@ -232,7 +231,7 @@ export async function translateHTML(html: string, reverse:boolean, charArg:simpl
|
||||
chaId: 'simple'
|
||||
}
|
||||
}
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let DoingChat = get(doingChat)
|
||||
if(DoingChat){
|
||||
if(isExpTranslator()){
|
||||
@@ -440,7 +439,7 @@ export async function translateHTML(html: string, reverse:boolean, charArg:simpl
|
||||
}
|
||||
|
||||
function needSuperChunkedTranslate(){
|
||||
return get(DataBase).translatorType === 'deeplX'
|
||||
return getDatabase().translatorType === 'deeplX'
|
||||
}
|
||||
|
||||
let llmCache = new Map<string, string>()
|
||||
@@ -455,7 +454,7 @@ async function translateLLM(text:string, arg:{to:string}){
|
||||
return `<style-data style-index="${styleDecodes.length-1}"></style-data>`
|
||||
})
|
||||
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const charIndex = get(selectedCharID)
|
||||
const currentChar = db.characters[charIndex]
|
||||
let translatorNote
|
||||
|
||||
Reference in New Issue
Block a user