Rework catalog and add trash

This commit is contained in:
kwaroran
2024-05-23 08:13:20 +09:00
parent f1b9247f20
commit d126e52788
6 changed files with 156 additions and 58 deletions

View File

@@ -1,6 +1,6 @@
import { get, writable } from "svelte/store";
import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdDataFunc } from "./storage/database";
import { alertError, alertNormal, alertSelect, alertStore } from "./alert";
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore } from "./alert";
import { language } from "../lang";
import { decode as decodeMsgpack } from "msgpackr";
import { checkNullish, findCharacterbyId, selectMultipleFile, selectSingleFile, sleep } from "./util";
@@ -508,4 +508,29 @@ export async function addDefaultCharacters() {
type: 'none',
msg: ''
})
}
export async function removeChar(index:number,name:string, type:'normal'|'permanent'|'permanentForce' = 'normal'){
const db = get(DataBase)
if(type !== 'permanentForce'){
const conf = await alertConfirm(language.removeConfirm + name)
if(!conf){
return
}
const conf2 = await alertConfirm(language.removeConfirm2 + name)
if(!conf2){
return
}
}
let chars = db.characters
if(type === 'normal'){
chars[index].trashTime = Date.now()
}
else{
chars.splice(index, 1)
}
checkCharOrder()
db.characters = chars
setDatabase(db)
selectedCharID.set(-1)
}

View File

@@ -772,6 +772,7 @@ export interface character{
vits?: OnnxModelFiles
realmId?:string
imported?:boolean
trashTime?:number
}
@@ -815,6 +816,7 @@ export interface groupChat{
oneAtTime?:boolean
virtualscript?:string
lorePlus?:boolean
trashTime?:number
}
export interface botPreset{

View File

@@ -977,6 +977,14 @@ async function checkNewFormat() {
if(db.mainPrompt === oldJailbreak){
db.mainPrompt = defaultJailbreak
}
for(let i=0;i<db.characters.length;i++){
const trashTime = db.characters[i].trashTime
const targetTrashTime = trashTime ? trashTime + 1000 * 60 * 60 * 24 * 3 : 0
if(trashTime && targetTrashTime < Date.now()){
db.characters.splice(i,1)
i--
}
}
setDatabase(db)
checkCharOrder()
}
@@ -997,10 +1005,13 @@ export function checkCharOrder() {
let charIdList:string[] = []
for(let i=0;i<db.characters.length;i++){
const charId = db.characters[i].chaId
charIdList.push(charId)
const char = db.characters[i]
const charId = char.chaId
if(!char.trashTime){
charIdList.push(charId)
}
if(!ordered.includes(charId)){
if(charId !== '§temp' && charId !== '§playground'){
if(charId !== '§temp' && charId !== '§playground' && !char.trashTime){
db.characterOrder.push(charId)
}
}