Skip to content

Commit

Permalink
Allow removing cache entries
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Jan 30, 2025
1 parent 9f32971 commit bb3ec8c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/http.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { sub } from "date-fns";
import DOMPurify from "isomorphic-dompurify";
import ws from "ws";
import { createServer } from "http";
import { FileSystemCache, getCacheKey } from "node-fetch-cache";

import * as registry from "./chainstate/registry.mjs";
import log from "./logger.mjs";
Expand Down Expand Up @@ -308,6 +309,34 @@ export async function launch(trie, libp2p) {
reply.send(weeklySales);
}
});
app.delete("/api/v1/cache", async (req, res) => {
const { url } = req.body;

if (!url) {
const code = 400;
const message = "Invalid request";
const details = "URL required";
return sendError(res, code, message, details);
}

const cache = new FileSystemCache({
cacheDirectory: path.resolve(env.CACHE_DIR),
});

try {
const key = getCacheKey(url);
await cache.remove(key);

const code = 200;
const message = "Cache entry removed";
const details = "Successfully removed cache entry";
return sendStatus(res, code, message, details);
} catch (err) {
const code = 500;
const message = "Cache removal failed";
return sendError(res, code, message);
}
});
app.get("/unsubscribe/:secret", async (req, res) => {
const { secret } = req.params;

Expand Down

0 comments on commit bb3ec8c

Please sign in to comment.