refactor: remove some duplicated code
This commit is contained in:
@ -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);
|
||||
};
|
||||
|
Reference in New Issue
Block a user