Fix bug with upload files
This commit is contained in:
parent
86c2a35a31
commit
9db7a4127f
@ -1,4 +1,5 @@
|
|||||||
const router = require("express").Router();
|
const express = require("express");
|
||||||
|
const router = express.Router();
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const config = require('../../config-handler');
|
const config = require('../../config-handler');
|
||||||
const database = require('../../database');
|
const database = require('../../database');
|
||||||
@ -8,8 +9,8 @@ const bodyParser = require('body-parser');
|
|||||||
//router.use(require('cookie-parser')());
|
//router.use(require('cookie-parser')());
|
||||||
|
|
||||||
// Парсим JSON
|
// Парсим JSON
|
||||||
router.use(bodyParser.json({ type: 'application/*+json' }))
|
router.use(bodyParser.json({ type: 'application/*+json' }));
|
||||||
router.use(bodyParser.json({ type: 'application/json' }))
|
router.use(bodyParser.json({ type: 'application/json' }));
|
||||||
|
|
||||||
const unknownError = (err) => {
|
const unknownError = (err) => {
|
||||||
const stackId = new Date().getTime();
|
const stackId = new Date().getTime();
|
||||||
|
@ -20,5 +20,7 @@
|
|||||||
|
|
||||||
"authors_blacklist" : [
|
"authors_blacklist" : [
|
||||||
"Монеточка", "Monetochka"
|
"Монеточка", "Monetochka"
|
||||||
]
|
],
|
||||||
|
|
||||||
|
"request_size_limit" : "150mb"
|
||||||
}
|
}
|
@ -84,6 +84,7 @@ class Api {
|
|||||||
xhr.onreadystatechange = function (event) {
|
xhr.onreadystatechange = function (event) {
|
||||||
//console.log(event);
|
//console.log(event);
|
||||||
if (this.readyState != 4) return;
|
if (this.readyState != 4) return;
|
||||||
|
console.log(this.responseText);
|
||||||
cb(JSON.parse(this.responseText).response);
|
cb(JSON.parse(this.responseText).response);
|
||||||
};
|
};
|
||||||
xhr.send(
|
xhr.send(
|
||||||
|
65
server.js
65
server.js
@ -6,64 +6,25 @@ const config = require("./config-handler");
|
|||||||
// const http = require("http");
|
// const http = require("http");
|
||||||
const { Database } = require("./database");
|
const { Database } = require("./database");
|
||||||
const { Logger } = require('./logger');
|
const { Logger } = require('./logger');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
// Выставляем адекватное ограничение на тело запроса
|
||||||
|
app.use(bodyParser.json({limit: config().request_size_limit}));
|
||||||
|
|
||||||
// global.database = new Database(
|
app.use(
|
||||||
// config().database.address,
|
(req, res, next) => {
|
||||||
// config().database.port,
|
// Поставил по-умолчанию
|
||||||
// config().database.username,
|
res.result = function (data, isErr = false, code = 200) {
|
||||||
// config().database.password,
|
this.status(code).json(!isErr ? {
|
||||||
// config().database.database
|
response : data
|
||||||
// );
|
} : {
|
||||||
|
error : data
|
||||||
/*http.ServerResponse.prototype.errorModeOn = function () {
|
|
||||||
this.isError = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
http.ServerResponse.prototype.bindNext = function (next) {
|
|
||||||
this.next = next;
|
|
||||||
};
|
|
||||||
|
|
||||||
http.ServerResponse.prototype.sendModed = function (sendData) {
|
|
||||||
// Модифицируем res.send
|
|
||||||
if (sendData !== undefined && config().logger_mode) {
|
|
||||||
this.responseData = sendData;
|
|
||||||
require("./logger")(this.req, this, this.next);
|
|
||||||
}
|
|
||||||
this.send(sendData);
|
|
||||||
};
|
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
|
||||||
res.bindNext(next);
|
|
||||||
next();
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
app.use((req, res, next) => {
|
|
||||||
// Для добавления оригинального тела запроса
|
|
||||||
const body = bodyHand(
|
|
||||||
req,
|
|
||||||
res,
|
|
||||||
{
|
|
||||||
limit: 9999999999,
|
|
||||||
cache: false,
|
|
||||||
encoding: "base64",
|
|
||||||
},
|
|
||||||
(err, body) => {
|
|
||||||
if (!err) {
|
|
||||||
req.byteBody = Buffer.from(body, "base64");
|
|
||||||
|
|
||||||
// Запись в req.json при json
|
|
||||||
if (!!req.headers && req.headers["content-type"]?.includes("json")) {
|
|
||||||
try {
|
|
||||||
req.json = JSON.parse(req.byteBody.toString("utf8"));
|
|
||||||
} catch (_e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
next();
|
next();
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});*/
|
|
||||||
|
|
||||||
app.use(async (req, res, next) => {
|
app.use(async (req, res, next) => {
|
||||||
req.logger = new Logger();
|
req.logger = new Logger();
|
||||||
|
Loading…
Reference in New Issue
Block a user