Added cache-control headers

This commit is contained in:
Filip Znachor 2024-09-17 09:53:28 +02:00
parent 244e522b9b
commit f42944ce64

View file

@ -12,20 +12,20 @@ fastify.register(cors, {
fastify.all("/search", async (req, r) => {
let { q } = (req.query as any);
let res = await backend.getSearch(q);
return res;
r.header("cache-control", "max-age=604800");
return await backend.getSearch(q);
});
fastify.all("/search/suggestions", async (req, r) => {
let { q } = (req.query as any);
let res = await backend.getSearchSuggestions(q);
return res;
r.header("cache-control", "max-age=604800");
return await backend.getSearchSuggestions(q);
});
fastify.get("/track/:id", async (req, r) => {
let { id } = (req.params as any);
let res = await backend.getInfo(id);
return res;
r.header("cache-control", "max-age=604800");
return await backend.getInfo(id);
});
fastify.get("/tracks/:ids", async (req, r) => {
@ -39,19 +39,21 @@ fastify.get("/tracks/:ids", async (req, r) => {
if (i == list.length) resolve(tracks);
});
});
r.header("cache-control", "max-age=604800");
return await res;
});
fastify.get("/track/:id/cover/:size", async (req, r) => {
let { id, size } = (req.params as any);
let res = await backend.getThumbnail(id, size);
r.header("cache-control", "max-age=604800");
return await fetch(res);
});
fastify.get("/track/:id/stream", async (req, r) => {
let { id } = (req.params as any);
let res = await backend.stream(id);
return res;
r.header("cache-control", "max-age=604800");
return await backend.stream(id);
});
fastify.get("/track/:id/download", async (req, r) => {
@ -59,6 +61,7 @@ fastify.get("/track/:id/download", async (req, r) => {
let data = await backend.download(id);
r.header("content-disposition", `inline; filename="${data.filename}"`);
r.header("content-type", "application/octet-stream");
r.header("cache-control", "max-age=604800");
return data.stream;
});