refactor: remove some duplicated code

This commit is contained in:
2023-08-01 17:50:00 +02:00
parent 01697a6686
commit c5cf629482
30 changed files with 377 additions and 321 deletions

View File

@ -1,6 +1,7 @@
import { HandlerContext } from "$fresh/server.ts";
import { getMovieCredits } from "@lib/tmdb.ts";
import * as cache from "@lib/cache/cache.ts";
import { json } from "@lib/helpers.ts";
type CachedMovieCredits = {
lastUpdated: number;
@ -21,9 +22,6 @@ export const handler = async (
});
}
const headers = new Headers();
headers.append("Content-Type", "application/json");
console.log("[api] getting movie credits");
const cacheId = `/movie/credits/${id}`;
@ -32,7 +30,7 @@ export const handler = async (
if (
cachedResponse && Date.now() < (cachedResponse.lastUpdated + CACHE_INTERVAL)
) {
return new Response(JSON.stringify(cachedResponse.data), { headers });
return json(cachedResponse.data);
}
const res = await getMovieCredits(+id);
@ -44,5 +42,5 @@ export const handler = async (
}),
);
return new Response(JSON.stringify(res));
return json(res);
};