This commit is contained in:
amy 2024-10-26 21:11:15 +03:30
parent fb72b4e357
commit 40ed4d2e27
No known key found for this signature in database
2 changed files with 8 additions and 4 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
node_modules node_modules
.idea

View file

@ -17,7 +17,7 @@ app.get('/', async (req, res) => {
const url = req.query.url; const url = req.query.url;
if (!url) { if (!url) {
res.status(400).send("nop"); res.status(400).contentType("text/plain").send("nop");
return; return;
} }
@ -30,7 +30,7 @@ app.get('/', async (req, res) => {
if (row) { if (row) {
const currentTime = getCurrentUnixTimestamp(); const currentTime = getCurrentUnixTimestamp();
const twoHoursInSeconds = 10; const twoHoursInSeconds = 7200;
if (currentTime - row.time > twoHoursInSeconds) { if (currentTime - row.time > twoHoursInSeconds) {
db.run(`DELETE FROM cache WHERE id = ?`, [url], async (err) => { db.run(`DELETE FROM cache WHERE id = ?`, [url], async (err) => {
@ -51,6 +51,7 @@ app.get('/', async (req, res) => {
return; return;
} }
res.contentType("application/json"); res.contentType("application/json");
res.header("cache", "stale - invalidated");
res.send(resp) res.send(resp)
console.log("old response (entry readded)"); console.log("old response (entry readded)");
}); });
@ -58,7 +59,7 @@ app.get('/', async (req, res) => {
insertStmt.finalize(); insertStmt.finalize();
}); });
} else { } else {
console.log("cache valid") res.header("cache", "fresh");
res.contentType("application/json"); res.contentType("application/json");
res.send(row.response); res.send(row.response);
} }
@ -73,7 +74,9 @@ app.get('/', async (req, res) => {
return; return;
} }
res.contentType("application/json"); res.contentType("application/json");
res.header("cache", "wasnt");
res.send(resp) res.send(resp)
console.log("New entry added"); console.log("New entry added");
}); });