From d8f7ac38f16a7477f895b4e43733b126a83b7772 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Thu, 10 Aug 2023 19:16:03 +0200 Subject: [PATCH] feat: get author on series --- lib/documents.ts | 4 ++++ lib/string.ts | 4 ++++ routes/api/movies/[name].ts | 13 +++++++++++-- routes/api/movies/enhance/[name].ts | 6 +----- routes/api/series/[name].ts | 16 +++++++++++++--- routes/api/series/enhance/[name].ts | 3 ++- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/lib/documents.ts b/lib/documents.ts index 3387651..a4b0619 100644 --- a/lib/documents.ts +++ b/lib/documents.ts @@ -56,6 +56,8 @@ export function createDocument( log.info("creating document", { name }); + typesense.synchronize(); + return fetch(SILVERBULLET_SERVER + "/" + name, { body: content, method: "PUT", @@ -73,6 +75,8 @@ export async function getDocument(name: string): Promise { cache.setDocument(name, text); + typesense.synchronize(); + return text; } diff --git a/lib/string.ts b/lib/string.ts index b7bc057..51d6269 100644 --- a/lib/string.ts +++ b/lib/string.ts @@ -100,3 +100,7 @@ const resourcePrefixes = Object.values(resources).map((v) => v.prefix).filter( ); export const isLocalImage = (src: string) => resourcePrefixes.some((p) => src.startsWith(p)); + +export const isString = (input: string | undefined): input is string => { + return typeof input === "string"; +}; diff --git a/routes/api/movies/[name].ts b/routes/api/movies/[name].ts index 39767d4..5c9a0b8 100644 --- a/routes/api/movies/[name].ts +++ b/routes/api/movies/[name].ts @@ -3,7 +3,7 @@ import { createMovie, getMovie, Movie } from "@lib/resource/movies.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 { safeFileName } from "@lib/string.ts"; +import { isString, safeFileName } from "@lib/string.ts"; import { createDocument } from "@lib/documents.ts"; import { AccessDeniedError } from "@lib/errors.ts"; @@ -52,12 +52,21 @@ export const handler: Handlers = { metadata.author = director.name; } + const tags: string[] = []; + if (movieDetails.genres) { + tags.push( + ...movieDetails.genres.map((g) => g.name?.toLowerCase()).filter( + isString, + ), + ); + } + const movie: Movie = { id: name, name: name, type: "movie", description: "", - tags: [], + tags, meta: metadata, }; diff --git a/routes/api/movies/enhance/[name].ts b/routes/api/movies/enhance/[name].ts index 535541f..6611773 100644 --- a/routes/api/movies/enhance/[name].ts +++ b/routes/api/movies/enhance/[name].ts @@ -3,7 +3,7 @@ import { createDocument } from "@lib/documents.ts"; import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts"; import { createMovie, getMovie } from "@lib/resource/movies.ts"; import * as tmdb from "@lib/tmdb.ts"; -import { safeFileName } from "@lib/string.ts"; +import { isString, safeFileName } from "@lib/string.ts"; import { json } from "@lib/helpers.ts"; import { AccessDeniedError, @@ -12,10 +12,6 @@ import { } from "@lib/errors.ts"; import * as cache from "@lib/cache/cache.ts"; -const isString = (input: string | undefined): input is string => { - return typeof input === "string"; -}; - const POST = async ( req: Request, ctx: HandlerContext, diff --git a/routes/api/series/[name].ts b/routes/api/series/[name].ts index 0c781c2..fe252f1 100644 --- a/routes/api/series/[name].ts +++ b/routes/api/series/[name].ts @@ -2,7 +2,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 { safeFileName } from "@lib/string.ts"; +import { isString, safeFileName } from "@lib/string.ts"; import { createDocument } from "@lib/documents.ts"; import { AccessDeniedError } from "@lib/errors.ts"; import { createSeries, getSeries, Series } from "@lib/resource/series.ts"; @@ -26,7 +26,8 @@ export const handler: Handlers = { const releaseDate = seriesDetails.first_air_date; const posterPath = seriesDetails.poster_path; const director = - seriesCredits?.crew?.filter?.((person) => person.job === "Director")[0]; + seriesCredits?.crew?.filter?.((person) => person.job === "Director")[0] || + seriesDetails.created_by?.[0]; let finalPath = ""; const name = seriesDetails.name || seriesDetails.original_name || @@ -52,12 +53,21 @@ export const handler: Handlers = { metadata.author = director.name; } + const tags: string[] = []; + if (seriesDetails.genres) { + tags.push( + ...seriesDetails.genres.map((g) => g.name?.toLowerCase()).filter( + isString, + ), + ); + } + const series: Series = { id: name, name: name, + tags, type: "series", description: "", - tags: [], meta: metadata, }; diff --git a/routes/api/series/enhance/[name].ts b/routes/api/series/enhance/[name].ts index ed22ec8..8ea3998 100644 --- a/routes/api/series/enhance/[name].ts +++ b/routes/api/series/enhance/[name].ts @@ -52,7 +52,8 @@ const POST = async ( } const posterPath = seriesDetails.poster_path; const director = seriesCredits && - seriesCredits.crew?.filter?.((person) => person.job === "Director")[0]; + seriesCredits.crew?.filter?.((person) => person.job === "Director")[0] || + seriesDetails?.created_by?.[0]; if (director && director.name && !series.meta.author) { series.meta.author = director.name; }