feat: trying to add hashes to scripts
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import * as tmdb from "@lib/tmdb.ts";
|
||||
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
||||
import {
|
||||
fileExtension,
|
||||
formatDate,
|
||||
isString,
|
||||
safeFileName,
|
||||
@@ -11,13 +10,14 @@ import {
|
||||
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
||||
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
import { define } from "../../../utils.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(_, ctx) {
|
||||
export const handler = define.handlers({
|
||||
async GET(ctx) {
|
||||
const movie = await fetchResource(`movies/${ctx.params.name}`);
|
||||
return json(movie?.content);
|
||||
},
|
||||
async POST(_, ctx) {
|
||||
async POST(ctx) {
|
||||
const session = ctx.state.session;
|
||||
if (!session) throw new AccessDeniedError();
|
||||
|
||||
@@ -70,4 +70,4 @@ export const handler: Handlers = {
|
||||
|
||||
return json({ name: fileName });
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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 {
|
||||
fileExtension,
|
||||
formatDate,
|
||||
isString,
|
||||
safeFileName,
|
||||
@@ -16,80 +15,76 @@ import {
|
||||
import { createRecommendationResource } from "@lib/recommendation.ts";
|
||||
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
import { define } from "../../../../utils.ts";
|
||||
|
||||
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 function (ctx) {
|
||||
const session = ctx.state.session;
|
||||
if (!session) {
|
||||
throw new AccessDeniedError();
|
||||
}
|
||||
|
||||
const movie = await fetchResource<ReviewResource>(
|
||||
`movies/${ctx.params.name}`,
|
||||
);
|
||||
if (!movie) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
const movie = await fetchResource<ReviewResource>(
|
||||
`movies/${ctx.params.name}`,
|
||||
);
|
||||
if (!movie) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
|
||||
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 movieDetails = await tmdb.getMovie(tmdbId);
|
||||
const movieCredits = !movie.content?.author &&
|
||||
await tmdb.getMovieCredits(tmdbId);
|
||||
const movieDetails = await tmdb.getMovie(tmdbId);
|
||||
const movieCredits = !movie.content?.author &&
|
||||
await tmdb.getMovieCredits(tmdbId);
|
||||
|
||||
const director = movieCredits &&
|
||||
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
|
||||
const director = movieCredits &&
|
||||
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
|
||||
|
||||
movie.content ??= {
|
||||
_type: "Review",
|
||||
};
|
||||
|
||||
movie.content.datePublished ??= formatDate(movieDetails.release_date);
|
||||
|
||||
if (director && !movie.content?.author) {
|
||||
movie.content.author = {
|
||||
_type: "Person",
|
||||
name: director.name,
|
||||
movie.content ??= {
|
||||
_type: "Review",
|
||||
};
|
||||
}
|
||||
|
||||
if (movieDetails.genres) {
|
||||
movie.content.keywords = [
|
||||
...new Set([
|
||||
...(movie.content.keywords?.map((g) => g.toLowerCase()) || []),
|
||||
...movieDetails.genres.map((g) =>
|
||||
g.name?.toLowerCase().replaceAll(" ", "-")
|
||||
),
|
||||
].filter(isString)),
|
||||
];
|
||||
}
|
||||
movie.content.datePublished ??= formatDate(movieDetails.release_date);
|
||||
|
||||
movie.content.tmdbId ??= tmdbId;
|
||||
if (director && !movie.content?.author) {
|
||||
movie.content.author = {
|
||||
_type: "Person",
|
||||
name: director.name,
|
||||
};
|
||||
}
|
||||
|
||||
let finalPath = "";
|
||||
const posterPath = movieDetails.poster_path;
|
||||
if (posterPath && !movie.content.image) {
|
||||
const poster = await tmdb.getMoviePoster(posterPath);
|
||||
const extension = fileExtension(posterPath);
|
||||
finalPath = `movies/images/${safeFileName(name)}_cover.${extension}`;
|
||||
await createResource(finalPath, poster);
|
||||
movie.content.image = finalPath;
|
||||
}
|
||||
if (movieDetails.genres) {
|
||||
movie.content.keywords = [
|
||||
...new Set([
|
||||
...(movie.content.keywords?.map((g) => g.toLowerCase()) || []),
|
||||
...movieDetails.genres.map((g) =>
|
||||
g.name?.toLowerCase().replaceAll(" ", "-")
|
||||
),
|
||||
].filter(isString)),
|
||||
];
|
||||
}
|
||||
|
||||
await createResource(`movies/${toUrlSafeString(movie.name)}.md`, movie);
|
||||
movie.content.tmdbId ??= tmdbId;
|
||||
|
||||
createRecommendationResource(movie, movieDetails.overview);
|
||||
let finalPath = "";
|
||||
const posterPath = movieDetails.poster_path;
|
||||
if (posterPath && !movie.content.image) {
|
||||
const poster = await tmdb.getMoviePoster(posterPath);
|
||||
const extension = fileExtension(posterPath);
|
||||
finalPath = `movies/images/${safeFileName(name)}_cover.${extension}`;
|
||||
await createResource(finalPath, poster);
|
||||
movie.content.image = finalPath;
|
||||
}
|
||||
|
||||
return json(movie);
|
||||
};
|
||||
await createResource(`movies/${toUrlSafeString(movie.name)}.md`, movie);
|
||||
|
||||
export const handler: Handlers = {
|
||||
POST,
|
||||
};
|
||||
createRecommendationResource(movie, movieDetails.overview);
|
||||
|
||||
return json(movie);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { fetchResource } from "@lib/marka/index.ts";
|
||||
import { define } from "../../../utils.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
export const handler = define.handlers({
|
||||
async GET() {
|
||||
const movies = await fetchResource("movies");
|
||||
return json(movies);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user