feat: trying to add hashes to scripts
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { getMovieCredits } from "@lib/tmdb.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { createLogger } from "@lib/log/index.ts";
|
||||
import { createCache } from "@lib/cache.ts";
|
||||
import { define } from "../../../../utils.ts";
|
||||
|
||||
type CachedMovieCredits = {
|
||||
lastUpdated: number;
|
||||
@@ -16,37 +16,37 @@ const cache = createCache<CachedMovieCredits>("movie-credits", {
|
||||
|
||||
const log = createLogger("api/tmdb");
|
||||
|
||||
export const handler = async (
|
||||
_req: Request,
|
||||
_ctx: FreshContext,
|
||||
) => {
|
||||
const id = _ctx.params.id;
|
||||
export const handler = define.handlers({
|
||||
GET: async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
if (!id) {
|
||||
return new Response("Bad Request", {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
if (!id) {
|
||||
return new Response("Bad Request", {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
log.debug("getting movie credits");
|
||||
log.debug("getting movie credits");
|
||||
|
||||
const cacheId = `/movie/credits/${id}`;
|
||||
const cacheId = `/movie/credits/${id}`;
|
||||
|
||||
const cachedResponse = cache.get(cacheId);
|
||||
if (
|
||||
cachedResponse && Date.now() < (cachedResponse.lastUpdated + CACHE_INTERVAL)
|
||||
) {
|
||||
return json(cachedResponse.data);
|
||||
}
|
||||
const cachedResponse = cache.get(cacheId);
|
||||
if (
|
||||
cachedResponse &&
|
||||
Date.now() < (cachedResponse.lastUpdated + CACHE_INTERVAL)
|
||||
) {
|
||||
return json(cachedResponse.data);
|
||||
}
|
||||
|
||||
const res = await getMovieCredits(+id);
|
||||
cache.set(
|
||||
cacheId,
|
||||
JSON.stringify({
|
||||
lastUpdated: Date.now(),
|
||||
data: res,
|
||||
}),
|
||||
);
|
||||
const res = await getMovieCredits(+id);
|
||||
cache.set(
|
||||
cacheId,
|
||||
JSON.stringify({
|
||||
lastUpdated: Date.now(),
|
||||
data: res,
|
||||
}),
|
||||
);
|
||||
|
||||
return json(res);
|
||||
};
|
||||
return json(res);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user