1111
This commit is contained in:
13
source.js
13
source.js
@@ -229,7 +229,7 @@ async function handleMainRequest(req, res) {
|
|||||||
reqPath = 'app'; // Default to 'app' if only one path segment is provided
|
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) {
|
if (!ALLOWED_PATHS.includes(reqPath) || !token) {
|
||||||
return sendErrorResponse(res, HTTP_STATUS.BAD_REQUEST, `Bad Request: Invalid path or missing 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 是有效的
|
// 确保 content-length 是有效的
|
||||||
const contentLength = realRes.headers['content-length'];
|
const contentLength = realRes.headers['content-length'];
|
||||||
if (contentLength) {
|
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.headers['content-length'] = contentLength;
|
||||||
// 异步更新 data 到缓存 cacheMetaFile
|
// 异步更新 data 到缓存 cacheMetaFile
|
||||||
fs.promises.writeFile(cacheMetaFile, JSON.stringify(data))
|
fs.promises.writeFile(cacheMetaFile, JSON.stringify(data))
|
||||||
|
|||||||
Reference in New Issue
Block a user