This commit is contained in:
蒋小陌 2024-11-07 17:15:39 +08:00
parent 1204584a77
commit d2cc870219

View File

@ -86,6 +86,13 @@ const server = http.createServer(async (req, res) => {
// 返回 endpoint, 缓存目录, 缓存数量, 用于监听服务是否正常运行
if (reqPath === 'endpoint') {
if (parsedUrl.query.api) {
// 判断 parsedUrl.query.api 是否为网址
const urlRegex = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([\/\w.-]*)*\/?$/;
if (urlRegex.test(parsedUrl.query.api)) {
apiEndpoint = parsedUrl.query.api;
}
}
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
code: 200,
@ -100,26 +107,6 @@ 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;
@ -178,8 +165,6 @@ const server = http.createServer(async (req, res) => {
return;
}
if (apiData.code === 200 && apiData.data && apiData.data.url) {
const { url: realUrl, cloudtype, expiration, path, headers, uniqid } = apiData.data;
const data = { realUrl, cloudtype, expiration: expiration * 1000, path, headers, uniqid };