Merge branch 'main' of https://github.com/kwaroran/RisuAI
This commit is contained in:
@@ -7,7 +7,8 @@ const bodyParser = require('body-parser');
|
||||
const fs = require('fs/promises')
|
||||
const crypto = require('crypto')
|
||||
app.use(express.static(path.join(process.cwd(), 'dist'), {index: false}));
|
||||
app.use(bodyParser.json({ limit: 100000000 }));
|
||||
app.use(bodyParser.raw({ limit: 100000000 }));
|
||||
app.use(bodyParser.json())
|
||||
const {pipeline} = require('stream/promises')
|
||||
|
||||
let password = ''
|
||||
@@ -148,17 +149,11 @@ app.get('/api/read', async (req, res, next) => {
|
||||
}
|
||||
try {
|
||||
if(!existsSync(path.join(savePath, filePath))){
|
||||
res.send({
|
||||
success: true,
|
||||
content: null
|
||||
});
|
||||
res.send();
|
||||
}
|
||||
else{
|
||||
const data = await fs.readFile(path.join(savePath, filePath));
|
||||
res.send({
|
||||
success: true,
|
||||
content: data.toString('base64')
|
||||
});
|
||||
res.setHeader('Content-Type','application/octet-stream');
|
||||
res.sendFile(path.join(savePath, filePath));
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -227,7 +222,7 @@ app.post('/api/write', async (req, res, next) => {
|
||||
return
|
||||
}
|
||||
const filePath = req.headers['file-path'];
|
||||
const fileContent = Buffer.from(req.body.content, 'base64');
|
||||
const fileContent = req.body
|
||||
if (!filePath || !fileContent) {
|
||||
res.status(400).send({
|
||||
error:'File path required'
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user