From fa6f5fb027dfec2529900a08fb007a359264728d Mon Sep 17 00:00:00 2001 From: kwaroran Date: Fri, 30 Jun 2023 02:50:51 +0900 Subject: [PATCH] [feat] accountstorage template --- src/ts/process/request.ts | 4 +- src/ts/storage/accountStorage.ts | 95 ++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/ts/storage/accountStorage.ts diff --git a/src/ts/process/request.ts b/src/ts/process/request.ts index 29a2f5b7..f7517db4 100644 --- a/src/ts/process/request.ts +++ b/src/ts/process/request.ts @@ -750,8 +750,8 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model' ] }, "trusted_workers": false, - "slow_workers": true, - "worker_blacklist": false, + "workerslow_workers": true, + "_blacklist": false, "dry_run": false, "models": [realModel, realModel.trim(), ' ' + realModel, realModel + ' '] } diff --git a/src/ts/storage/accountStorage.ts b/src/ts/storage/accountStorage.ts new file mode 100644 index 00000000..60fc68c9 --- /dev/null +++ b/src/ts/storage/accountStorage.ts @@ -0,0 +1,95 @@ +import { get } from "svelte/store" +import { DataBase } from "./database" +import { hubURL } from "../characterCards" + +export class AccountStorage{ + auth:string + + async setItem(key:string, value:Uint8Array) { + await this.checkAuth() + const da = await fetch(hubURL + '/api/account/write', { + method: "POST", + body: JSON.stringify({ + content: Buffer.from(value).toString('base64') + }), + headers: { + 'content-type': 'application/json', + 'file-path': Buffer.from(key, 'utf-8').toString('hex'), + 'risu-auth': this.auth + } + }) + if(da.status < 200 || da.status >= 300){ + throw "setItem Error" + } + const data = await da.json() + if(data.error){ + throw data.error + } + } + async getItem(key:string):Promise { + if(key.startsWith('assets/')){ + return Buffer.from(await (await fetch(`${hubURL}/resource/` + key)).arrayBuffer()) + } + await this.checkAuth() + const da = await fetch(hubURL + '/api/account/read', { + method: "GET", + headers: { + 'file-path': Buffer.from(key, 'utf-8').toString('hex'), + 'risu-auth': this.auth + } + }) + const data = await da.json() + if(da.status < 200 || da.status >= 300){ + throw "getItem Error" + } + if(data.error){ + throw data.error + } + if(data.content === null){ + return null + } + return Buffer.from(data.content, 'base64') + } + async keys():Promise{ + await this.checkAuth() + const da = await fetch(hubURL + '/api/account/list', { + method: "GET", + headers:{ + 'risu-auth': this.auth + } + }) + const data = await da.json() + if(da.status < 200 || da.status >= 300){ + throw "listItem Error" + } + if(data.error){ + throw data.error + } + return data.content + } + async removeItem(key:string){ + await this.checkAuth() + const da = await fetch(hubURL + '/api/account/remove', { + method: "GET", + headers: { + 'file-path': Buffer.from(key, 'utf-8').toString('hex'), + 'risu-auth': this.auth + } + }) + if(da.status < 200 || da.status >= 300){ + throw "removeItem Error" + } + const data = await da.json() + if(data.error){ + throw data.error + } + } + + private async checkAuth(){ + this.auth = get(DataBase)?.account?.token + + } + + + listItem = this.keys +} \ No newline at end of file