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,5 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import * as tmdb from "@lib/tmdb.ts";
import { safeFileName } from "@lib/string.ts";
import { fileExtension, safeFileName } from "@lib/string.ts";
import { json } from "@lib/helpers.ts";
import {
AccessDeniedError,
@@ -9,74 +7,72 @@ import {
NotFoundError,
} from "@lib/errors.ts";
import { createResource, fetchResource } from "@lib/marka/index.ts";
import { define } from "../../../../utils.ts";
const isString = (input: string | undefined): input is string => {
return typeof input === "string";
};
const POST = async (
req: Request,
ctx: FreshContext,
): Promise<Response> => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
export const handler = define.handlers({
POST: async (ctx) => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const body = await req.json();
const name = ctx.params.name;
const { tmdbId } = body;
if (!name || !tmdbId) {
throw new BadRequestError();
}
const body = await ctx.req.json();
const name = ctx.params.name;
const { tmdbId } = body;
if (!name || !tmdbId) {
throw new BadRequestError();
}
const series = await fetchResource(`series/${ctx.params.name}`);
if (!series) {
throw new NotFoundError();
}
const series = await fetchResource(`series/${ctx.params.name}`);
if (!series) {
throw new NotFoundError();
}
const seriesDetails = await tmdb.getSeries(tmdbId);
const seriesCredits = !series?.content?.author &&
await tmdb.getSeriesCredits(tmdbId);
const seriesDetails = await tmdb.getSeries(tmdbId);
const seriesCredits = !series?.content?.author &&
await tmdb.getSeriesCredits(tmdbId);
const releaseDate = seriesDetails.first_air_date;
if (releaseDate && series.content?.datePublished) {
series.content.datePublished = new Date(releaseDate).toISOString();
}
const posterPath = seriesDetails.poster_path;
const director = seriesCredits &&
seriesCredits.crew?.filter?.((person) => person.job === "Director")[0] ||
seriesDetails?.created_by?.[0];
if (director && director.name && !series.content?.author) {
series.content.author = series.content.author || {
_type: "Person",
name: director.name,
};
}
const releaseDate = seriesDetails.first_air_date;
if (releaseDate && series.content?.datePublished) {
series.content.datePublished = new Date(releaseDate).toISOString();
}
const posterPath = seriesDetails.poster_path;
const director = seriesCredits &&
seriesCredits.crew?.filter?.((person) =>
person.job === "Director"
)[0] ||
seriesDetails?.created_by?.[0];
if (director && director.name && !series.content?.author) {
series.content.author = series.content.author || {
_type: "Person",
name: director.name,
};
}
if (seriesDetails.genres) {
series.content.keywords = [
...new Set([
...(series.content.keywords?.map((t) => t.toLowerCase()) || []),
...seriesDetails.genres.map((g) => g.name?.toLowerCase()),
].filter(isString)),
];
}
if (seriesDetails.genres) {
series.content.keywords = [
...new Set([
...(series.content.keywords?.map((t) => t.toLowerCase()) || []),
...seriesDetails.genres.map((g) => g.name?.toLowerCase()),
].filter(isString)),
];
}
let finalPath = "";
if (posterPath && !series.content?.image) {
const poster = await tmdb.getMoviePoster(posterPath);
const extension = fileExtension(posterPath);
let finalPath = "";
if (posterPath && !series.content?.image) {
const poster = await tmdb.getMoviePoster(posterPath);
const extension = fileExtension(posterPath);
finalPath = `series/images/${safeFileName(name)}_cover.${extension}`;
await createResource(finalPath, poster);
series.content.image = finalPath;
}
await createResource(`series/${safeFileName(series.name)}.md`, series);
finalPath = `series/images/${safeFileName(name)}_cover.${extension}`;
await createResource(finalPath, poster);
series.content.image = finalPath;
}
await createResource(`series/${safeFileName(series.name)}.md`, series);
return json(series);
};
export const handler: Handlers = {
POST,
};
return json(series);
},
});