From d2cc8702195cc0072778a18bd895238b7339604c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E5=B0=8F=E9=99=8C?= Date: Thu, 7 Nov 2024 17:15:39 +0800 Subject: [PATCH] 11 --- source.js | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/source.js b/source.js index 12a83c1..dcbd065 100644 --- a/source.js +++ b/source.js @@ -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 };