feat: add preset sharing

This commit is contained in:
kwaroran
2024-05-24 11:28:32 +09:00
parent 0ce01d8ca1
commit 96ccc1cdd8
10 changed files with 124 additions and 74 deletions

View File

@@ -205,11 +205,12 @@ export async function alertConfirm(msg:string){
return get(alertStore).msg === 'yes'
}
export async function alertCardExport(){
export async function alertCardExport(type:string = ''){
alertStore.set({
'type': 'cardexport',
'msg': ''
'msg': '',
'submsg': type
})
while(true){

View File

@@ -293,35 +293,27 @@ function convertOldTavernAndJSON(charaData:OldTavernChar, imgp:string|undefined
}
}
export async function exportChar(charaID:number) {
export async function exportChar(charaID:number):Promise<string> {
const db = get(DataBase)
let char = structuredClone(db.characters[charaID])
if(char.type === 'group'){
return
return ''
}
if(!char.image){
alertError('Image Required')
return
}
const conf = await alertConfirm(language.exportConfirm)
if(!conf){
return
return ''
}
const option = await alertCardExport()
if(option.type === 'cancel'){
return
}
else if(option.type === 'rcc'){
char.license = option.license
exportSpecV2(char, 'rcc', {password:option.password})
}
else{
if(option.type === ''){
exportSpecV2(char,'png')
}
return
else{
return option.type
}
return ''
}

View File

@@ -1222,7 +1222,7 @@ import type { OnnxModelFiles } from '../process/transformers';
import type { RisuModule } from '../process/modules';
import type { HypaV2Data } from '../process/memory/hypav2';
export async function downloadPreset(id:number){
export async function downloadPreset(id:number, type:'json'|'risupreset'|'return' = 'json'){
saveCurrentPreset()
let db = get(DataBase)
let pres = structuredClone(db.botPresets[id])
@@ -1233,21 +1233,37 @@ export async function downloadPreset(id:number){
pres.proxyKey = ''
pres.textgenWebUIStreamURL= ''
pres.textgenWebUIBlockingURL= ''
const sel = parseInt(await alertSelect(['RISUPRESET (recommended)','JSON']))
if(sel === 1){
if(type === 'json'){
downloadFile(pres.name + "_preset.json", Buffer.from(JSON.stringify(pres, null, 2)))
}
else{
downloadFile(pres.name + "_preset.risupreset", fflate.compressSync(encodeMsgpack({
else if(type === 'risupreset' || type === 'return'){
const buf = fflate.compressSync(encodeMsgpack({
presetVersion: 0,
type: 'preset',
pres: await encryptBuffer(
encodeMsgpack(pres),
'risupreset'
)
})))
}))
if(type === 'risupreset'){
downloadFile(pres.name + "_preset.risupreset", buf)
}
else{
return {
data: pres,
buf
}
}
}
alertNormal(language.successExport)
return {
data: pres,
buf: null
}
}

View File

@@ -40,6 +40,7 @@ export const ShowVN = writable(false)
export const SettingsMenuIndex = writable(-1)
export const CurrentVariablePointer = writable({} as {[key:string]: string|number|boolean})
export const OpenRealmStore = writable(false)
export const ShowRealmFrameStore = writable('')
export const PlaygroundStore = writable(0)
function createSimpleCharacter(char:character|groupChat){