Enhance Node Version RisuAI Backend Server File I/O Performance (#485)

# PR Checklist
- [ ] Did you check if it works normally in all models? *ignore this
when it dosen't uses models*
- [x] Did you check if it works normally in all of web, local and node
hosted versions? if it dosen't, did you blocked it in those versions?
- [ ] Did you added a type def?

# Description
노드리스의 /api/write와 /api/read에서 base64를 제거해 파일 용량 과 I/O에 필요한 연산량을 줄였습니다.
Removed base64 from /api/write and /api/read on node version rise to
reduce file size and the amount of computation required for I/O.
This commit is contained in:
kwaroran
2024-06-05 16:39:38 +09:00
committed by GitHub
2 changed files with 12 additions and 21 deletions

View File

@@ -9,11 +9,9 @@ export class NodeStorage{
await this.checkAuth()
const da = await fetch('/api/write', {
method: "POST",
body: JSON.stringify({
content: Buffer.from(value).toString('base64')
}),
body: value,
headers: {
'content-type': 'application/json',
'content-type': 'application/octet-stream',
'file-path': Buffer.from(key, 'utf-8').toString('hex'),
'risu-auth': auth
}
@@ -35,17 +33,15 @@ export class NodeStorage{
'risu-auth': 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){
const data = Buffer.from(await da.arrayBuffer())
if (data.length == 0){
return null
}
return Buffer.from(data.content, 'base64')
return data
}
async keys():Promise<string[]>{
await this.checkAuth()