fix: soo many lint errors
This commit is contained in:
@@ -46,7 +46,7 @@ async function processCreateArticle(
|
||||
const title = result?.title || aiMeta?.headline || "";
|
||||
const id = toUrlSafeString(title);
|
||||
|
||||
const newArticle: Article = {
|
||||
const newArticle: ArticleResource["content"] = {
|
||||
_type: "Article",
|
||||
headline: title,
|
||||
articleBody: result.content,
|
||||
|
||||
@@ -60,7 +60,7 @@ function parseParams(reqUrl: URL): ImageParams | string {
|
||||
}
|
||||
}
|
||||
// Helper function to generate ETag
|
||||
async function generateETag(content: ArrayBuffer): Promise<string> {
|
||||
async function generateETag(content: Uint8Array<ArrayBuffer>): Promise<string> {
|
||||
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
|
||||
return `"${
|
||||
Array.from(new Uint8Array(hashBuffer))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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 { isString, safeFileName } from "@lib/string.ts";
|
||||
import { formatDate, isString, safeFileName } from "@lib/string.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import {
|
||||
AccessDeniedError,
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from "@lib/errors.ts";
|
||||
import { createRecommendationResource } from "@lib/recommendation.ts";
|
||||
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
|
||||
const POST = async (
|
||||
req: Request,
|
||||
@@ -20,7 +21,9 @@ const POST = async (
|
||||
throw new AccessDeniedError();
|
||||
}
|
||||
|
||||
const movie = await fetchResource(`movies/${ctx.params.name}`);
|
||||
const movie = await fetchResource<ReviewResource>(
|
||||
`movies/${ctx.params.name}`,
|
||||
);
|
||||
if (!movie) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
@@ -33,27 +36,28 @@ const POST = async (
|
||||
}
|
||||
|
||||
const movieDetails = await tmdb.getMovie(tmdbId);
|
||||
const movieCredits = !movie.meta?.author &&
|
||||
const movieCredits = !movie.content?.author &&
|
||||
await tmdb.getMovieCredits(tmdbId);
|
||||
|
||||
const releaseDate = movieDetails.release_date;
|
||||
if (releaseDate && !movie.meta?.date) {
|
||||
movie.meta = movie.meta || {};
|
||||
movie.meta.date = new Date(releaseDate);
|
||||
if (releaseDate && !movie.content?.datePublished) {
|
||||
movie.content = movie.content || {};
|
||||
movie.content.datePublished = formatDate(new Date(releaseDate));
|
||||
}
|
||||
|
||||
const director = movieCredits?.crew?.filter?.((person) =>
|
||||
person.job === "Director"
|
||||
)[0];
|
||||
if (director && !movie.meta?.author) {
|
||||
movie.meta = movie.meta || {};
|
||||
movie.meta.author = director.name;
|
||||
const director = movieCredits &&
|
||||
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
|
||||
if (director && !movie.content?.author) {
|
||||
movie.content = movie.content || {};
|
||||
movie.content.author = {
|
||||
_type: "Person",
|
||||
name: director.name,
|
||||
};
|
||||
}
|
||||
|
||||
if (movieDetails.genres) {
|
||||
movie.tags = [
|
||||
movie.content.keywords = [
|
||||
...new Set([
|
||||
...(movie.tags?.map((g) => g.toLowerCase()) || []),
|
||||
...(movie.content.keywords?.map((g) => g.toLowerCase()) || []),
|
||||
...movieDetails.genres.map((g) =>
|
||||
g.name?.toLowerCase().replaceAll(" ", "-")
|
||||
),
|
||||
@@ -61,22 +65,22 @@ const POST = async (
|
||||
];
|
||||
}
|
||||
|
||||
if (!movie.id) {
|
||||
movie.id = tmdbId;
|
||||
if (!movie.name) {
|
||||
movie.name = tmdbId;
|
||||
}
|
||||
|
||||
let finalPath = "";
|
||||
const posterPath = movieDetails.poster_path;
|
||||
if (posterPath && !movie.meta?.image) {
|
||||
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.meta = movie.meta || {};
|
||||
movie.meta.image = finalPath;
|
||||
movie.content = movie.content || {};
|
||||
movie.content.image = finalPath;
|
||||
}
|
||||
|
||||
await createResource(`movies/${safeFileName(movie.id)}.md`, movie);
|
||||
await createResource(`movies/${safeFileName(movie.name)}.md`, movie);
|
||||
|
||||
createRecommendationResource(movie, movieDetails.overview);
|
||||
|
||||
|
||||
@@ -48,7 +48,14 @@ async function processCreateRecipeFromUrl(
|
||||
}
|
||||
|
||||
if (!recipe) {
|
||||
recipe = await openai.extractRecipe(result.content);
|
||||
const res = await openai.extractRecipe(result.content);
|
||||
if (!res || "errorMessages" in res) {
|
||||
const errorMessage = res?.errorMessages?.[0] ||
|
||||
"could not extract recipe";
|
||||
streamResponse.enqueue(`failed to extract recipe: ${errorMessage}`);
|
||||
return;
|
||||
}
|
||||
recipe = res;
|
||||
}
|
||||
|
||||
const id = safeFileName(recipe?.name || "");
|
||||
|
||||
@@ -25,11 +25,14 @@ export function parseJsonLdToRecipeSchema(jsonLdContent: string) {
|
||||
);
|
||||
|
||||
const instructions = Array.isArray(data.recipeInstructions)
|
||||
? data.recipeInstructions.map((instr) => {
|
||||
? data.recipeInstructions.map((instr: unknown) => {
|
||||
if (!instr) return "";
|
||||
if (typeof instr === "string") return instr;
|
||||
if (typeof instr === "object" && instr.text) return instr.text;
|
||||
if (typeof instr === "object" && "text" in instr && instr.text) {
|
||||
return instr.text;
|
||||
}
|
||||
return "";
|
||||
}).filter((instr) => instr.trim() !== "")
|
||||
}).filter((instr: string) => instr.trim() !== "")
|
||||
: [];
|
||||
|
||||
// Parse servings
|
||||
@@ -53,7 +56,7 @@ export function parseJsonLdToRecipeSchema(jsonLdContent: string) {
|
||||
title: data.name || "Unnamed Recipe",
|
||||
image: pickImage(image || data.image || ""),
|
||||
author: Array.isArray(data.author)
|
||||
? data.author.map((a: any) => a.name).join(", ")
|
||||
? data.author.map((a: { name: string }) => a.name).join(", ")
|
||||
: data.author?.name || "",
|
||||
description: data.description || "",
|
||||
ingredients,
|
||||
@@ -81,7 +84,7 @@ function pickImage(images: string | string[]): string {
|
||||
return images;
|
||||
}
|
||||
|
||||
function parseServings(servingsData: any): number {
|
||||
function parseServings(servingsData: unknown): number {
|
||||
if (typeof servingsData === "string") {
|
||||
const match = servingsData.match(/\d+/);
|
||||
return match ? parseInt(match[0], 10) : 1;
|
||||
|
||||
@@ -11,7 +11,6 @@ export const handler: Handlers = {
|
||||
}
|
||||
|
||||
const recommendations = await getSimilarMovies(ctx.params.id);
|
||||
console.log({ recommendations });
|
||||
|
||||
return json(recommendations);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
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";
|
||||
@@ -37,42 +36,43 @@ const POST = async (
|
||||
}
|
||||
|
||||
const seriesDetails = await tmdb.getSeries(tmdbId);
|
||||
const seriesCredits = !series.meta?.author &&
|
||||
const seriesCredits = !series?.content?.author &&
|
||||
await tmdb.getSeriesCredits(tmdbId);
|
||||
|
||||
const releaseDate = seriesDetails.first_air_date;
|
||||
if (releaseDate && series.meta?.date) {
|
||||
series.meta.date = new Date(releaseDate);
|
||||
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.meta?.author) {
|
||||
series.author = series.author || {};
|
||||
series.author["_type"] = "Person";
|
||||
series.author.name = director.name;
|
||||
if (director && director.name && !series.content?.author) {
|
||||
series.content.author = series.content.author || {
|
||||
_type: "Person",
|
||||
name: director.name,
|
||||
};
|
||||
}
|
||||
|
||||
if (seriesDetails.genres) {
|
||||
series.keywords = [
|
||||
series.content.keywords = [
|
||||
...new Set([
|
||||
...(series.tags?.map((t) => t.toLowerCase()) || []),
|
||||
...(series.content.keywords?.map((t) => t.toLowerCase()) || []),
|
||||
...seriesDetails.genres.map((g) => g.name?.toLowerCase()),
|
||||
].filter(isString)),
|
||||
];
|
||||
}
|
||||
|
||||
let finalPath = "";
|
||||
if (posterPath && !series.meta?.image) {
|
||||
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.image = finalPath;
|
||||
series.content.image = finalPath;
|
||||
}
|
||||
await createResource(`series/${safeFileName(series.id)}.md`, series);
|
||||
await createResource(`series/${safeFileName(series.name)}.md`, series);
|
||||
|
||||
return json(series);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user