This commit is contained in:
蒋小陌 2024-11-03 13:38:02 +08:00
parent 7b1971da4e
commit f243697788
2 changed files with 21 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -91,6 +91,26 @@ const server = http.createServer(async (req, res) => {
return;
}
// 清理缓存
if (reqPath === 'clean') {
// 删除缓存目录下的所有文件
const files = fs.readdirSync(cacheDir);
for (const file of files) {
const filePath = pathModule.join(cacheDir, file);
fs.unlinkSync(filePath);
}
res.writeHead(200, { 'Content-Type': 'text/plain;charset=UTF-8' });
res.end(JSON.stringify({
code: 200,
data: {
cacheDir: cacheDir,
pathIndexCount: Object.keys(pathIndex).length,
files: files.length,
}
}));
return;
}
// 当没有 token 或 undefined
if (token === '' || typeof token === 'undefined') {
token = reqPath;