mirror of
https://github.com/woodchen-ink/Random-Api.git
synced 2025-07-19 14:32:04 +08:00
Update app.js
This commit is contained in:
parent
037dbb7127
commit
8d9c0dfc87
@ -7,6 +7,11 @@ import 'winston-daily-rotate-file';
|
|||||||
import cluster from 'cluster';
|
import cluster from 'cluster';
|
||||||
import { cpus } from 'os';
|
import { cpus } from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
// 处理 __dirname
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const numCPUs = cpus().length;
|
const numCPUs = cpus().length;
|
||||||
|
|
||||||
@ -22,14 +27,14 @@ const CSV_PATHS_URL = 'https://random-api.czl.net/url.json';
|
|||||||
// 设置缓存
|
// 设置缓存
|
||||||
let csvPathsCache = null;
|
let csvPathsCache = null;
|
||||||
let lastFetchTime = 0;
|
let lastFetchTime = 0;
|
||||||
const CACHE_DURATION = 60 * 1000 *60 * 24; // 24小时
|
const CACHE_DURATION = 60 * 1000 * 60 * 24; // 24小时
|
||||||
|
|
||||||
const csvCache = new LRU({
|
const csvCache = new LRU({
|
||||||
max: 100, // 最多缓存100个CSV文件
|
max: 100, // 最多缓存100个CSV文件
|
||||||
maxAge: 1000 * 60 * 60 * 24 // 缓存24小时
|
maxAge: 1000 * 60 * 60 * 24 // 缓存24小时
|
||||||
});
|
});
|
||||||
|
|
||||||
//日志名称格式
|
// 日志名称格式
|
||||||
const consoleFormat = winston.format.printf(({ level, message, timestamp }) => {
|
const consoleFormat = winston.format.printf(({ level, message, timestamp }) => {
|
||||||
return `${timestamp} ${level}: ${message}`;
|
return `${timestamp} ${level}: ${message}`;
|
||||||
});
|
});
|
||||||
@ -62,7 +67,7 @@ const logger = winston.createLogger({
|
|||||||
filename: 'logs/application-%DATE%.log',
|
filename: 'logs/application-%DATE%.log',
|
||||||
datePattern: 'YYYY-MM-DD-HH',
|
datePattern: 'YYYY-MM-DD-HH',
|
||||||
maxSize: '20m',
|
maxSize: '20m',
|
||||||
maxFiles: '7d', //日志保存的时间,超过这个时间的会自动删除旧文件
|
maxFiles: '7d', // 日志保存的时间,超过这个时间的会自动删除旧文件
|
||||||
zippedArchive: false // 禁用压缩
|
zippedArchive: false // 禁用压缩
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user