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 config = require('../../config-handler');
|
||||
const database = require('../../database');
|
||||
@ -8,8 +9,8 @@ const bodyParser = require('body-parser');
|
||||
//router.use(require('cookie-parser')());
|
||||
|
||||
// Парсим 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 stackId = new Date().getTime();
|
||||
|
@ -20,5 +20,7 @@
|
||||
|
||||
"authors_blacklist" : [
|
||||
"Монеточка", "Monetochka"
|
||||
]
|
||||
],
|
||||
|
||||
"request_size_limit" : "150mb"
|
||||
}
|
@ -84,6 +84,7 @@ class Api {
|
||||
xhr.onreadystatechange = function (event) {
|
||||
//console.log(event);
|
||||
if (this.readyState != 4) return;
|
||||
console.log(this.responseText);
|
||||
cb(JSON.parse(this.responseText).response);
|
||||
};
|
||||
xhr.send(
|
||||
|
69
server.js
69
server.js
@ -6,64 +6,25 @@ const config = require("./config-handler");
|
||||
// const http = require("http");
|
||||
const { Database } = require("./database");
|
||||
const { Logger } = require('./logger');
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
const app = express();
|
||||
// Выставляем адекватное ограничение на тело запроса
|
||||
app.use(bodyParser.json({limit: config().request_size_limit}));
|
||||
|
||||
// global.database = new Database(
|
||||
// config().database.address,
|
||||
// config().database.port,
|
||||
// config().database.username,
|
||||
// config().database.password,
|
||||
// config().database.database
|
||||
// );
|
||||
|
||||
/*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);
|
||||
app.use(
|
||||
(req, res, next) => {
|
||||
// Поставил по-умолчанию
|
||||
res.result = function (data, isErr = false, code = 200) {
|
||||
this.status(code).json(!isErr ? {
|
||||
response : data
|
||||
} : {
|
||||
error : data
|
||||
});
|
||||
};
|
||||
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();
|
||||
},
|
||||
);
|
||||
});*/
|
||||
);
|
||||
|
||||
app.use(async (req, res, next) => {
|
||||
req.logger = new Logger();
|
||||
|
Loading…
Reference in New Issue
Block a user