feat: trying to add hashes to scripts

This commit is contained in:
Max Richter
2026-01-10 13:03:13 +01:00
parent e65938ecc2
commit e55f787a29
79 changed files with 4209 additions and 720 deletions

View File

@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { getMovie } from "@lib/tmdb.ts";
import { json } from "@lib/helpers.ts";
import { createCache } from "@lib/cache.ts";
import { define } from "../../../utils.ts";
type CachedMovieCredits = {
lastUpdated: number;
@@ -13,40 +13,36 @@ const cache = createCache<CachedMovieCredits>("movie-credits", {
expires: CACHE_INTERVAL,
});
const GET = 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,
});
}
const cacheId = `/movie/${id}`;
const cacheId = `/movie/${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 getMovie(+id);
const res = await getMovie(+id);
cache.set(
cacheId,
JSON.stringify({
lastUpdated: Date.now(),
data: res,
}),
);
cache.set(
cacheId,
JSON.stringify({
lastUpdated: Date.now(),
data: res,
}),
);
return json(res);
};
export const handler: Handlers = {
GET,
};
return json(res);
},
});

View File

@@ -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);
},
});

View File

@@ -1,33 +1,28 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { searchMovie, searchTVShow } from "@lib/tmdb.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { define } from "../../../utils.ts";
const GET = async (
req: Request,
ctx: FreshContext,
) => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
export const handler = define.handlers({
GET: async (ctx) => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const u = new URL(req.url);
const u = new URL(ctx.req.url);
const query = u.searchParams.get("q");
const query = u.searchParams.get("q");
if (!query) {
throw new BadRequestError();
}
if (!query) {
throw new BadRequestError();
}
const type = u.searchParams.get("type") || "movies";
const type = u.searchParams.get("type") || "movies";
const res = type === "movies"
? await searchMovie(query)
: await searchTVShow(query);
const res = type === "movies"
? await searchMovie(query)
: await searchTVShow(query);
return new Response(JSON.stringify(res.results));
};
export const handler: Handlers = {
GET,
};
return new Response(JSON.stringify(res.results));
},
});