[fix] fix requesting zip
This commit is contained in:
60
pnpm-lock.yaml
generated
60
pnpm-lock.yaml
generated
@@ -71,6 +71,9 @@ dependencies:
|
||||
isomorphic-dompurify:
|
||||
specifier: ^1.8.0
|
||||
version: 1.8.0
|
||||
jszip:
|
||||
specifier: ^3.10.1
|
||||
version: 3.10.1
|
||||
libsodium-wrappers-sumo:
|
||||
specifier: ^0.7.11
|
||||
version: 0.7.11
|
||||
@@ -1537,6 +1540,10 @@ packages:
|
||||
requiresBuild: true
|
||||
dev: false
|
||||
|
||||
/core-util-is@1.0.3:
|
||||
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
|
||||
dev: false
|
||||
|
||||
/cors@2.8.5:
|
||||
resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==}
|
||||
engines: {node: '>= 0.10'}
|
||||
@@ -2238,6 +2245,10 @@ packages:
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/isarray@1.0.0:
|
||||
resolution: {integrity: sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==}
|
||||
dev: false
|
||||
|
||||
/isexe@2.0.0:
|
||||
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
|
||||
dev: true
|
||||
@@ -2298,6 +2309,15 @@ packages:
|
||||
- utf-8-validate
|
||||
dev: false
|
||||
|
||||
/jszip@3.10.1:
|
||||
resolution: {integrity: sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==}
|
||||
dependencies:
|
||||
lie: 3.3.0
|
||||
pako: 1.0.11
|
||||
readable-stream: 2.3.8
|
||||
setimmediate: 1.0.5
|
||||
dev: false
|
||||
|
||||
/kleur@4.1.5:
|
||||
resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==}
|
||||
engines: {node: '>=6'}
|
||||
@@ -2319,6 +2339,12 @@ packages:
|
||||
immediate: 3.0.6
|
||||
dev: false
|
||||
|
||||
/lie@3.3.0:
|
||||
resolution: {integrity: sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==}
|
||||
dependencies:
|
||||
immediate: 3.0.6
|
||||
dev: false
|
||||
|
||||
/lil-gui@0.17.0:
|
||||
resolution: {integrity: sha512-MVBHmgY+uEbmJNApAaPbtvNh1RCAeMnKym82SBjtp5rODTYKWtM+MXHCifLe2H2Ti1HuBGBtK/5SyG4ShQ3pUQ==}
|
||||
dev: true
|
||||
@@ -2730,6 +2756,10 @@ packages:
|
||||
p-finally: 1.0.0
|
||||
dev: true
|
||||
|
||||
/pako@1.0.11:
|
||||
resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==}
|
||||
dev: false
|
||||
|
||||
/parent-module@1.0.1:
|
||||
resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==}
|
||||
engines: {node: '>=6'}
|
||||
@@ -2931,6 +2961,10 @@ packages:
|
||||
tunnel-agent: 0.6.0
|
||||
dev: false
|
||||
|
||||
/process-nextick-args@2.0.1:
|
||||
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
|
||||
dev: false
|
||||
|
||||
/protobufjs@6.11.3:
|
||||
resolution: {integrity: sha512-xL96WDdCZYdU7Slin569tFX712BxsxslWwAfAhCYjQKGTq7dAU91Lomy6nLLhh/dyGhk/YH4TwTSRxTzhuHyZg==}
|
||||
hasBin: true
|
||||
@@ -3035,6 +3069,18 @@ packages:
|
||||
pify: 2.3.0
|
||||
dev: true
|
||||
|
||||
/readable-stream@2.3.8:
|
||||
resolution: {integrity: sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==}
|
||||
dependencies:
|
||||
core-util-is: 1.0.3
|
||||
inherits: 2.0.4
|
||||
isarray: 1.0.0
|
||||
process-nextick-args: 2.0.1
|
||||
safe-buffer: 5.1.2
|
||||
string_decoder: 1.1.1
|
||||
util-deprecate: 1.0.2
|
||||
dev: false
|
||||
|
||||
/readable-stream@3.6.2:
|
||||
resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==}
|
||||
engines: {node: '>= 6'}
|
||||
@@ -3105,6 +3151,10 @@ packages:
|
||||
mri: 1.2.0
|
||||
dev: true
|
||||
|
||||
/safe-buffer@5.1.2:
|
||||
resolution: {integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==}
|
||||
dev: false
|
||||
|
||||
/safe-buffer@5.2.1:
|
||||
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
|
||||
dev: false
|
||||
@@ -3174,6 +3224,10 @@ packages:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/setimmediate@1.0.5:
|
||||
resolution: {integrity: sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==}
|
||||
dev: false
|
||||
|
||||
/setprototypeof@1.2.0:
|
||||
resolution: {integrity: sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==}
|
||||
dev: false
|
||||
@@ -3276,6 +3330,12 @@ packages:
|
||||
queue-tick: 1.0.1
|
||||
dev: false
|
||||
|
||||
/string_decoder@1.1.1:
|
||||
resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==}
|
||||
dependencies:
|
||||
safe-buffer: 5.1.2
|
||||
dev: false
|
||||
|
||||
/string_decoder@1.3.0:
|
||||
resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
|
||||
dependencies:
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
export function generateRandomSeed(length) {
|
||||
let result = '';
|
||||
const characters = '0123456789';
|
||||
const charactersLength = characters.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import JSZip from "jszip";
|
||||
|
||||
export async function processZip(dataArray: Uint8Array): Promise<string> {
|
||||
const jszip = await import("jszip");
|
||||
const blob = new Blob([dataArray], { type: "application/zip" });
|
||||
const zip = new JSZip();
|
||||
const zip = new jszip.default();
|
||||
const zipData = await zip.loadAsync(blob);
|
||||
|
||||
const imageFile = Object.keys(zipData.files).find(fileName => /\.(jpg|jpeg|png)$/.test(fileName));
|
||||
|
||||
@@ -6,8 +6,6 @@ import { globalFetch, readImage } from "../storage/globalApi"
|
||||
import { CharEmotion } from "../stores"
|
||||
import type { OpenAIChat } from "."
|
||||
import { processZip } from "./processzip"
|
||||
import type { List } from "lodash"
|
||||
import { generateRandomSeed } from "./generateSeed"
|
||||
export async function stableDiff(currentChar:character,prompt:string){
|
||||
const mainPrompt = "assistant is a chat analyzer.\nuser will input a data of situation with key and values before chat, and a chat of a user and character.\nView the status of the chat and change the data.\nif data's key starts with $, it must change it every time.\nif data value is none, it must change it."
|
||||
let db = get(DataBase)
|
||||
@@ -190,8 +188,7 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
base64img = Buffer.from(await readImage(db.NAIImgConfig.image)).toString('base64');
|
||||
}
|
||||
|
||||
let randomseed = generateRandomSeed(10);
|
||||
let seed = parseInt(randomseed, 10);
|
||||
let seed = Math.floor(Math.random() * 100000000000)
|
||||
reqlist = {
|
||||
body: {
|
||||
"action": "img2img",
|
||||
@@ -223,7 +220,8 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
},
|
||||
headers:{
|
||||
"Authorization": "Bearer " + db.NAIApiKey
|
||||
}
|
||||
},
|
||||
rawResponse: true
|
||||
}
|
||||
}else{
|
||||
reqlist = {
|
||||
@@ -243,13 +241,15 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
},
|
||||
headers:{
|
||||
"Authorization": "Bearer " + db.NAIApiKey
|
||||
}
|
||||
},
|
||||
rawResponse: true
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
const da = await globalFetch(db.NAIImgUrl, reqlist)
|
||||
|
||||
if(da){
|
||||
if(da.ok){
|
||||
let charemotions = get(CharEmotion)
|
||||
const img = await processZip(da.data);
|
||||
const emos:[string, string,number][] = [[img, img, Date.now()]]
|
||||
@@ -257,7 +257,7 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
CharEmotion.set(charemotions)
|
||||
}
|
||||
else{
|
||||
alertError(JSON.stringify(da.data))
|
||||
alertError(Buffer.from(da.data).toString())
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -685,16 +685,6 @@ export async function globalFetch(url:string, arg:{
|
||||
headers: headers,
|
||||
method: method
|
||||
})
|
||||
if(da.headers.get('content-type')?.includes('application/x-zip-compressed')){
|
||||
const daText = await da.blob()
|
||||
|
||||
addFetchLog(daText, da.ok && da.status >= 200 && da.status < 300)
|
||||
return {
|
||||
ok: da.ok && da.status >= 200 && da.status < 300,
|
||||
data: daText,
|
||||
headers: Object.fromEntries(da.headers)
|
||||
}
|
||||
}
|
||||
const daText = await da.text()
|
||||
try {
|
||||
const dat = JSON.parse(daText)
|
||||
|
||||
Reference in New Issue
Block a user