This commit is contained in:
2025-09-04 15:52:26 +08:00
parent 500eab86eb
commit 7675a18c91
2 changed files with 2 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@@ -229,7 +229,7 @@ async function handleMainRequest(req, res) {
reqPath = 'app'; // Default to 'app' if only one path segment is provided
}
const ALLOWED_PATHS = ['avatar', 'go', 'bbs', 'www', 'url', 'thumb', 'app', 'qrcode'];
const ALLOWED_PATHS = ['avatar', 'go', 'bbs', 'www', 'url', 'thumb', 'app', 'qrcode', 'school'];
if (!ALLOWED_PATHS.includes(reqPath) || !token) {
return sendErrorResponse(res, HTTP_STATUS.BAD_REQUEST, `Bad Request: Invalid path or missing token.`);
}
@@ -416,17 +416,6 @@ const fetchAndServe = async (data, tempCacheContentFile, cacheContentFile, cache
// 确保 content-length 是有效的
const contentLength = realRes.headers['content-length'];
if (contentLength) {
// contentLength 小于 2KB 且与缓存文件大小不一致时,重新获取
if (contentLength < 2048 && data.headers['content-length'] !== contentLength) {
console.warn('Warning: content-length is different for the response from:', data.realUrl);
sendErrorResponse(res, HTTP_STATUS.BAD_GATEWAY, `Bad Gateway: Content-Length mismatch for ${data.realUrl}`);
// Clean up temp file if stream hasn't started or failed early
fs.promises.access(tempCacheContentFile)
.then(() => fs.promises.unlink(tempCacheContentFile))
.catch(() => {}); // 忽略文件不存在的错误
return;
}
data.headers['content-length'] = contentLength;
// 异步更新 data 到缓存 cacheMetaFile
fs.promises.writeFile(cacheMetaFile, JSON.stringify(data))