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 fs = require('fs/promises')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
app.use(express.static(path.join(process.cwd(), 'dist'), {index: false}));
|
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')
|
const {pipeline} = require('stream/promises')
|
||||||
|
|
||||||
let password = ''
|
let password = ''
|
||||||
@@ -148,17 +149,11 @@ app.get('/api/read', async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if(!existsSync(path.join(savePath, filePath))){
|
if(!existsSync(path.join(savePath, filePath))){
|
||||||
res.send({
|
res.send();
|
||||||
success: true,
|
|
||||||
content: null
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
const data = await fs.readFile(path.join(savePath, filePath));
|
res.setHeader('Content-Type','application/octet-stream');
|
||||||
res.send({
|
res.sendFile(path.join(savePath, filePath));
|
||||||
success: true,
|
|
||||||
content: data.toString('base64')
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
@@ -227,7 +222,7 @@ app.post('/api/write', async (req, res, next) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const filePath = req.headers['file-path'];
|
const filePath = req.headers['file-path'];
|
||||||
const fileContent = Buffer.from(req.body.content, 'base64');
|
const fileContent = req.body
|
||||||
if (!filePath || !fileContent) {
|
if (!filePath || !fileContent) {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
error:'File path required'
|
error:'File path required'
|
||||||
|
|||||||
@@ -9,11 +9,9 @@ export class NodeStorage{
|
|||||||
await this.checkAuth()
|
await this.checkAuth()
|
||||||
const da = await fetch('/api/write', {
|
const da = await fetch('/api/write', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: value,
|
||||||
content: Buffer.from(value).toString('base64')
|
|
||||||
}),
|
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/octet-stream',
|
||||||
'file-path': Buffer.from(key, 'utf-8').toString('hex'),
|
'file-path': Buffer.from(key, 'utf-8').toString('hex'),
|
||||||
'risu-auth': auth
|
'risu-auth': auth
|
||||||
}
|
}
|
||||||
@@ -35,17 +33,15 @@ export class NodeStorage{
|
|||||||
'risu-auth': auth
|
'risu-auth': auth
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const data = await da.json()
|
|
||||||
if(da.status < 200 || da.status >= 300){
|
if(da.status < 200 || da.status >= 300){
|
||||||
throw "getItem Error"
|
throw "getItem Error"
|
||||||
}
|
}
|
||||||
if(data.error){
|
|
||||||
throw data.error
|
const data = Buffer.from(await da.arrayBuffer())
|
||||||
}
|
if (data.length == 0){
|
||||||
if(data.content === null){
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return Buffer.from(data.content, 'base64')
|
return data
|
||||||
}
|
}
|
||||||
async keys():Promise<string[]>{
|
async keys():Promise<string[]>{
|
||||||
await this.checkAuth()
|
await this.checkAuth()
|
||||||
|
|||||||
Reference in New Issue
Block a user