From 4f4d93a8d6d5e49c7e3f102357b6b2bb5f30cc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E5=B0=8F=E9=99=8C?= Date: Fri, 30 Aug 2024 10:29:02 +0800 Subject: [PATCH] 1111 --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c2c1f50..9391964 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ const cache = {}; const PORT = process.env.PORT || 9001; const server = http.createServer((req, res) => { + if (req.url === '/favicon.ico') { res.writeHead(204); res.end(); @@ -21,6 +22,13 @@ const server = http.createServer((req, res) => { const path = parsedUrl.pathname; const sign = parsedUrl.query.sign || ''; + if (sign == '' || path == '/') { + res.writeHead(400, { 'Content-Type': 'text/plain' }); + res.end('Bad Request: Missing sign or path'); + return; + } + + // Check if the data is in cache and not expired const cacheEntry = cache[path]; if (cacheEntry && cacheEntry.expiration > Date.now()) { @@ -58,7 +66,6 @@ const server = http.createServer((req, res) => { const apiData = JSON.parse(data); if (apiData.code === 200 && apiData.data && apiData.data.url) { const { url: realUrl, cloudtype, expiration } = apiData.data; - // Cache the response if expiration is greater than 0 if (expiration > 0) { cache[path] = { @@ -67,7 +74,6 @@ const server = http.createServer((req, res) => { expiration: Date.now() + expiration * 1000 }; } - fetchAndServe(realUrl, cloudtype, res); } else { res.writeHead(502, { 'Content-Type': 'text/plain' });