[feat] node hosting support
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store"
|
||||
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore } from "./alert"
|
||||
import { DataBase, defaultSdDataFunc, type character, setDatabase, type customscript, type loreSettings, type loreBook } from "./database"
|
||||
import { DataBase, defaultSdDataFunc, type character, setDatabase, type customscript, type loreSettings, type loreBook } from "./storage/database"
|
||||
import { checkNullish, selectMultipleFile, selectSingleFile, sleep } from "./util"
|
||||
import { language } from "src/lang"
|
||||
import { encode as encodeMsgpack, decode as decodeMsgpack } from "@msgpack/msgpack";
|
||||
@@ -8,7 +8,7 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
import exifr from 'exifr'
|
||||
import { PngMetadata } from "./exif"
|
||||
import { characterFormatUpdate } from "./characters"
|
||||
import { checkCharOrder, downloadFile, readImage, saveAsset } from "./globalApi"
|
||||
import { checkCharOrder, downloadFile, readImage, saveAsset } from "./storage/globalApi"
|
||||
import { cloneDeep } from "lodash"
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdDataFunc } from "./database";
|
||||
import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdDataFunc } from "./storage/database";
|
||||
import exifr from 'exifr'
|
||||
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore } from "./alert";
|
||||
import { language } from "../lang";
|
||||
@@ -8,7 +8,7 @@ import { encode as encodeMsgpack, decode as decodeMsgpack } from "@msgpack/msgpa
|
||||
import { checkNullish, findCharacterbyId, selectMultipleFile, selectSingleFile, sleep } from "./util";
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { selectedCharID } from "./stores";
|
||||
import { checkCharOrder, downloadFile, getFileSrc, readImage } from "./globalApi";
|
||||
import { checkCharOrder, downloadFile, getFileSrc, readImage } from "./storage/globalApi";
|
||||
|
||||
export function createNewCharacter() {
|
||||
let db = get(DataBase)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { get } from "svelte/store";
|
||||
import { alertError, alertInput, alertNormal, alertSelect, alertStore } from "../alert";
|
||||
import { DataBase, setDatabase, type Database } from "../database";
|
||||
import { forageStorage, getUnpargeables, isTauri } from "../globalApi";
|
||||
import { DataBase, setDatabase, type Database } from "../storage/database";
|
||||
import { forageStorage, getUnpargeables, isTauri } from "../storage/globalApi";
|
||||
import pako from "pako";
|
||||
import { BaseDirectory, exists, readBinaryFile, readDir, writeBinaryFile } from "@tauri-apps/api/fs";
|
||||
import { language } from "../../lang";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store"
|
||||
import { alertToast, doingAlert } from "./alert"
|
||||
import { DataBase, changeToPreset as changeToPreset2 } from "./database"
|
||||
import { DataBase, changeToPreset as changeToPreset2 } from "./storage/database"
|
||||
|
||||
export function initHotkey(){
|
||||
document.addEventListener('keydown', (ev) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import DOMPurify from 'isomorphic-dompurify';
|
||||
import showdown from 'showdown';
|
||||
import type { character, groupChat } from './database';
|
||||
import { getFileSrc } from './globalApi';
|
||||
import type { character, groupChat } from './storage/database';
|
||||
import { getFileSrc } from './storage/globalApi';
|
||||
import { processScript } from './process/scripts';
|
||||
|
||||
const convertor = new showdown.Converter({
|
||||
|
||||
@@ -19,6 +19,9 @@ export function polyfill() {
|
||||
forceApply: true
|
||||
});
|
||||
}
|
||||
else{
|
||||
console.log("supports dragdrop")
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { OpenAIChat } from ".";
|
||||
import type { character } from "../database";
|
||||
import type { character } from "../storage/database";
|
||||
import { replacePlaceholders } from "../util";
|
||||
|
||||
export function exampleMessage(char:character):OpenAIChat[]{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase, setDatabase, type character } from "../database";
|
||||
import { DataBase, setDatabase, type character } from "../storage/database";
|
||||
import { CharEmotion, selectedCharID } from "../stores";
|
||||
import { tokenize, tokenizeNum } from "../tokenizer";
|
||||
import { language } from "../../lang";
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { get } from "svelte/store";
|
||||
import {selectedCharID} from '../stores'
|
||||
import { DataBase, setDatabase, type loreBook } from "../database";
|
||||
import { DataBase, setDatabase, type loreBook } from "../storage/database";
|
||||
import { tokenize } from "../tokenizer";
|
||||
import { selectSingleFile } from "../util";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "../../lang";
|
||||
import { downloadFile } from "../globalApi";
|
||||
import { downloadFile } from "../storage/globalApi";
|
||||
|
||||
export function addLorebook(type:number) {
|
||||
let selectedID = get(selectedCharID)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { language } from "../../lang";
|
||||
import { alertError } from "../alert";
|
||||
import { DataBase } from "../database";
|
||||
import { DataBase } from "../storage/database";
|
||||
import { checkNullish, selectSingleFile, sleep } from "../util";
|
||||
import type { OpenAIChat } from ".";
|
||||
import { globalFetch } from "../globalApi";
|
||||
import { globalFetch } from "../storage/globalApi";
|
||||
import { selectedCharID } from "../stores";
|
||||
|
||||
export const customProviderStore = writable([] as string[])
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { get } from "svelte/store";
|
||||
import type { OpenAIChat } from ".";
|
||||
import { DataBase, setDatabase, type character } from "../database";
|
||||
import { DataBase, setDatabase, type character } from "../storage/database";
|
||||
import { pluginProcess } from "./plugins";
|
||||
import { language } from "../../lang";
|
||||
import { stringlizeChat, unstringlizeChat } from "./stringlize";
|
||||
import { globalFetch, isTauri } from "../globalApi";
|
||||
import { globalFetch, isTauri } from "../storage/globalApi";
|
||||
import { alertError } from "../alert";
|
||||
import { sleep } from "../util";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { get } from "svelte/store";
|
||||
import { CharEmotion, selectedCharID } from "../stores";
|
||||
import { DataBase, setDatabase, type character, type customscript } from "../database";
|
||||
import { downloadFile } from "../globalApi";
|
||||
import { DataBase, setDatabase, type character, type customscript } from "../storage/database";
|
||||
import { downloadFile } from "../storage/globalApi";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
import { selectSingleFile } from "../util";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { get } from "svelte/store"
|
||||
import { DataBase, type character } from "../database"
|
||||
import { DataBase, type character } from "../storage/database"
|
||||
import { requestChatData } from "./request"
|
||||
import { alertError } from "../alert"
|
||||
import { globalFetch } from "../globalApi"
|
||||
import { globalFetch } from "../storage/globalApi"
|
||||
import { CharEmotion } from "../stores"
|
||||
import type { OpenAIChat } from "."
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import type { OpenAIChat } from ".";
|
||||
import { DataBase, type Chat, type character, type groupChat } from "../database";
|
||||
import { DataBase, type Chat, type character, type groupChat } from "../storage/database";
|
||||
import { tokenize } from "../tokenizer";
|
||||
import { findCharacterbyId } from "../util";
|
||||
import { requestChatData } from "./request";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import { alertError } from "../alert";
|
||||
import { DataBase, type character } from "../database";
|
||||
import { DataBase, type character } from "../storage/database";
|
||||
import { translateVox } from "../translator/translator";
|
||||
|
||||
let sourceNode:AudioBufferSourceNode = null
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { checkNullish } from './util';
|
||||
import { changeLanguage } from '../lang';
|
||||
import type { RisuPlugin } from './process/plugins';
|
||||
import { checkNullish } from '../util';
|
||||
import { changeLanguage } from '../../lang';
|
||||
import type { RisuPlugin } from '../process/plugins';
|
||||
import { saveAsset as saveImageGlobal } from './globalApi';
|
||||
import { cloneDeep } from 'lodash';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { writeBinaryFile,BaseDirectory, readBinaryFile, exists, createDir, readDir, removeFile } from "@tauri-apps/api/fs"
|
||||
import { changeFullscreen, checkNullish, findCharacterbyId, sleep } from "./util"
|
||||
import { changeFullscreen, checkNullish, findCharacterbyId, sleep } from "../util"
|
||||
import localforage from 'localforage'
|
||||
import { convertFileSrc, invoke } from "@tauri-apps/api/tauri"
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
@@ -9,19 +9,22 @@ import {open} from '@tauri-apps/api/shell'
|
||||
import { DataBase, loadedStore, setDatabase, type Database, updateTextTheme, defaultSdDataFunc } from "./database";
|
||||
import pako from "pako";
|
||||
import { appWindow } from "@tauri-apps/api/window";
|
||||
import { checkOldDomain, checkUpdate } from "./update";
|
||||
import { selectedCharID } from "./stores";
|
||||
import { checkOldDomain, checkUpdate } from "../update";
|
||||
import { selectedCharID } from "../stores";
|
||||
import { Body, ResponseType, fetch as TauriFetch } from "@tauri-apps/api/http";
|
||||
import { loadPlugins } from "./process/plugins";
|
||||
import { alertError, alertStore } from "./alert";
|
||||
import { checkDriverInit } from "./drive/drive";
|
||||
import { hasher } from "./parser";
|
||||
import { characterHubImport } from "./characterCards";
|
||||
import { loadPlugins } from "../process/plugins";
|
||||
import { alertError, alertStore } from "../alert";
|
||||
import { checkDriverInit } from "../drive/drive";
|
||||
import { hasher } from "../parser";
|
||||
import { characterHubImport } from "../characterCards";
|
||||
import { cloneDeep } from "lodash";
|
||||
import { NodeStorage } from "./nodeStorage";
|
||||
|
||||
//@ts-ignore
|
||||
export const isTauri = !!window.__TAURI__
|
||||
export const forageStorage = localforage.createInstance({
|
||||
//@ts-ignore
|
||||
export const isNodeServer = !!globalThis.__NODE__
|
||||
export const forageStorage = isNodeServer ? new NodeStorage() : localforage.createInstance({
|
||||
name: "risuai"
|
||||
})
|
||||
|
||||
@@ -554,7 +557,8 @@ export async function globalFetch(url:string, arg:{body?:any,headers?:{[key:stri
|
||||
const da = await fetch(furl, {
|
||||
body: JSON.stringify(arg.body),
|
||||
headers: {
|
||||
"risu-header": encodeURIComponent(JSON.stringify(arg.headers))
|
||||
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
method: method
|
||||
})
|
||||
@@ -571,7 +575,8 @@ export async function globalFetch(url:string, arg:{body?:any,headers?:{[key:stri
|
||||
const da = await fetch(furl, {
|
||||
body: JSON.stringify(arg.body),
|
||||
headers: {
|
||||
"risu-header": encodeURIComponent(JSON.stringify(arg.headers))
|
||||
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
method: method
|
||||
})
|
||||
73
src/ts/storage/nodeStorage.ts
Normal file
73
src/ts/storage/nodeStorage.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
export class NodeStorage{
|
||||
async setItem(key:string, value:Uint8Array) {
|
||||
const da = await fetch('/api/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')
|
||||
}
|
||||
})
|
||||
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<Buffer> {
|
||||
const da = await fetch('/api/read', {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'file-path': Buffer.from(key, 'utf-8').toString('hex')
|
||||
}
|
||||
})
|
||||
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<string[]>{
|
||||
const da = await fetch('/api/list', {
|
||||
method: "GET",
|
||||
})
|
||||
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){
|
||||
const da = await fetch('/api/list', {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'file-path': Buffer.from(key, 'utf-8').toString('hex')
|
||||
}
|
||||
})
|
||||
if(da.status < 200 || da.status >= 300){
|
||||
throw "removeItem Error"
|
||||
}
|
||||
const data = await da.json()
|
||||
if(data.error){
|
||||
throw data.error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
listItem = this.keys
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Tiktoken } from "@dqbd/tiktoken";
|
||||
import type { character } from "./database";
|
||||
import type { character } from "./storage/database";
|
||||
|
||||
async function encode(data:string):Promise<(number[]|Uint32Array)>{
|
||||
return await tikJS(data)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store"
|
||||
import { translatorPlugin } from "../process/plugins"
|
||||
import { DataBase } from "../database"
|
||||
import { DataBase } from "../storage/database"
|
||||
|
||||
let cache={
|
||||
origin: [''],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { fetch } from "@tauri-apps/api/http";
|
||||
import { DataBase, appVer, setDatabase } from "./database";
|
||||
import { DataBase, appVer, setDatabase } from "./storage/database";
|
||||
import { alertConfirm, alertMd } from "./alert";
|
||||
import { language } from "../lang";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { get } from "svelte/store"
|
||||
import type { Database, Message } from "./database"
|
||||
import { DataBase } from "./database"
|
||||
import type { Database, Message } from "./storage/database"
|
||||
import { DataBase } from "./storage/database"
|
||||
import { selectedCharID } from "./stores"
|
||||
import {open} from '@tauri-apps/api/dialog'
|
||||
import { readBinaryFile } from "@tauri-apps/api/fs"
|
||||
import { basename } from "@tauri-apps/api/path"
|
||||
import { createBlankChar, getCharImage } from "./characters"
|
||||
import { appWindow } from '@tauri-apps/api/window';
|
||||
import { isTauri } from "./globalApi"
|
||||
import { isTauri } from "./storage/globalApi"
|
||||
|
||||
export interface Messagec extends Message{
|
||||
index: number
|
||||
|
||||
Reference in New Issue
Block a user