first commit
This commit is contained in:
parent
7135ea4ce2
commit
7f6549bd35
6
app.js
6
app.js
|
@ -1,6 +1,6 @@
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const request = require("request");
|
const request = require("request");
|
||||||
const fs = require("fs");
|
const log = require("./log")
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 9000;
|
const port = 9000;
|
||||||
const { getDecryptionArray } = require("./decode");
|
const { getDecryptionArray } = require("./decode");
|
||||||
|
@ -27,6 +27,8 @@ function xorTransform(decryptionArray) {
|
||||||
|
|
||||||
app.get("/download", (req, res) => {
|
app.get("/download", (req, res) => {
|
||||||
const { url, decodeKey } = req.query;
|
const { url, decodeKey } = req.query;
|
||||||
|
log.info(`download url:${url}`);
|
||||||
|
log.info(`download decodeKey:${decodeKey}`);
|
||||||
let xorStream = xorTransform(
|
let xorStream = xorTransform(
|
||||||
getDecryptionArray(decodeURIComponent(decodeKey))
|
getDecryptionArray(decodeURIComponent(decodeKey))
|
||||||
);
|
);
|
||||||
|
@ -34,5 +36,5 @@ app.get("/download", (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Example app listening at http://localhost:${port}`);
|
log.info(`Example app listening at http://localhost:${port}`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
const winston = require('winston');
|
||||||
|
function thisLine() {
|
||||||
|
try {
|
||||||
|
const e = new Error();
|
||||||
|
const regex = /\((.*):(\d+):(\d+)\)$/
|
||||||
|
const stacks = e.stack.split("\n")
|
||||||
|
const temp = []
|
||||||
|
stacks.forEach(stack => {
|
||||||
|
if (!stack.includes("node_modules")) {
|
||||||
|
temp.push(stack)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const match = regex.exec(temp[3]);
|
||||||
|
return {
|
||||||
|
filepath: match[1],
|
||||||
|
line: match[2],
|
||||||
|
column: match[3]
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
filepath: "unknow",
|
||||||
|
line: "0",
|
||||||
|
column: "0"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const logger = winston.createLogger({
|
||||||
|
level: 'info',
|
||||||
|
transports: [
|
||||||
|
new winston.transports.Console(),
|
||||||
|
new winston.transports.File({
|
||||||
|
dirname: 'log', filename: 'server.log'
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
datePattern: 'YYYY-MM-DD',
|
||||||
|
zippedArchive: true,
|
||||||
|
format: winston.format.combine(
|
||||||
|
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss,SSS" }),
|
||||||
|
winston.format.align(),
|
||||||
|
winston.format.splat(),
|
||||||
|
winston.format.printf(
|
||||||
|
(info) => {
|
||||||
|
const { timestamp, level, message } = info;
|
||||||
|
const { filepath, line } = thisLine()
|
||||||
|
return `[${timestamp}] [${level.toUpperCase()}] [${filepath}:${line}] ${message}`; // 包括文件名和行号
|
||||||
|
}
|
||||||
|
)
|
||||||
|
),
|
||||||
|
maxSize: '1000m', // 每个日志文件最大尺寸
|
||||||
|
maxFiles: '14d' // 保留的日志文件天数
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = logger
|
Loading…
Reference in New Issue