first commit

This commit is contained in:
YSASM 2024-12-18 20:33:58 +08:00
parent 7135ea4ce2
commit 7f6549bd35
2 changed files with 57 additions and 2 deletions

6
app.js
View File

@ -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}`);
}); });

53
log.js Normal file
View File

@ -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