feat: get author on series

This commit is contained in:
max_richter 2023-08-10 19:16:03 +02:00
parent 9058e192ba
commit d8f7ac38f1
6 changed files with 35 additions and 11 deletions

View File

@ -56,6 +56,8 @@ export function createDocument(
log.info("creating document", { name }); log.info("creating document", { name });
typesense.synchronize();
return fetch(SILVERBULLET_SERVER + "/" + name, { return fetch(SILVERBULLET_SERVER + "/" + name, {
body: content, body: content,
method: "PUT", method: "PUT",
@ -73,6 +75,8 @@ export async function getDocument(name: string): Promise<string> {
cache.setDocument(name, text); cache.setDocument(name, text);
typesense.synchronize();
return text; return text;
} }

View File

@ -100,3 +100,7 @@ const resourcePrefixes = Object.values(resources).map((v) => v.prefix).filter(
); );
export const isLocalImage = (src: string) => export const isLocalImage = (src: string) =>
resourcePrefixes.some((p) => src.startsWith(p)); resourcePrefixes.some((p) => src.startsWith(p));
export const isString = (input: string | undefined): input is string => {
return typeof input === "string";
};

View File

@ -3,7 +3,7 @@ import { createMovie, getMovie, Movie } from "@lib/resource/movies.ts";
import { json } from "@lib/helpers.ts"; import { json } from "@lib/helpers.ts";
import * as tmdb from "@lib/tmdb.ts"; import * as tmdb from "@lib/tmdb.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.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 { createDocument } from "@lib/documents.ts";
import { AccessDeniedError } from "@lib/errors.ts"; import { AccessDeniedError } from "@lib/errors.ts";
@ -52,12 +52,21 @@ export const handler: Handlers = {
metadata.author = director.name; metadata.author = director.name;
} }
const tags: string[] = [];
if (movieDetails.genres) {
tags.push(
...movieDetails.genres.map((g) => g.name?.toLowerCase()).filter(
isString,
),
);
}
const movie: Movie = { const movie: Movie = {
id: name, id: name,
name: name, name: name,
type: "movie", type: "movie",
description: "", description: "",
tags: [], tags,
meta: metadata, meta: metadata,
}; };

View File

@ -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 { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import { createMovie, getMovie } from "@lib/resource/movies.ts"; import { createMovie, getMovie } from "@lib/resource/movies.ts";
import * as tmdb from "@lib/tmdb.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 { json } from "@lib/helpers.ts";
import { import {
AccessDeniedError, AccessDeniedError,
@ -12,10 +12,6 @@ import {
} from "@lib/errors.ts"; } from "@lib/errors.ts";
import * as cache from "@lib/cache/cache.ts"; import * as cache from "@lib/cache/cache.ts";
const isString = (input: string | undefined): input is string => {
return typeof input === "string";
};
const POST = async ( const POST = async (
req: Request, req: Request,
ctx: HandlerContext, ctx: HandlerContext,

View File

@ -2,7 +2,7 @@ import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts"; import { json } from "@lib/helpers.ts";
import * as tmdb from "@lib/tmdb.ts"; import * as tmdb from "@lib/tmdb.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.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 { createDocument } from "@lib/documents.ts";
import { AccessDeniedError } from "@lib/errors.ts"; import { AccessDeniedError } from "@lib/errors.ts";
import { createSeries, getSeries, Series } from "@lib/resource/series.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 releaseDate = seriesDetails.first_air_date;
const posterPath = seriesDetails.poster_path; const posterPath = seriesDetails.poster_path;
const director = const director =
seriesCredits?.crew?.filter?.((person) => person.job === "Director")[0]; seriesCredits?.crew?.filter?.((person) => person.job === "Director")[0] ||
seriesDetails.created_by?.[0];
let finalPath = ""; let finalPath = "";
const name = seriesDetails.name || seriesDetails.original_name || const name = seriesDetails.name || seriesDetails.original_name ||
@ -52,12 +53,21 @@ export const handler: Handlers = {
metadata.author = director.name; metadata.author = director.name;
} }
const tags: string[] = [];
if (seriesDetails.genres) {
tags.push(
...seriesDetails.genres.map((g) => g.name?.toLowerCase()).filter(
isString,
),
);
}
const series: Series = { const series: Series = {
id: name, id: name,
name: name, name: name,
tags,
type: "series", type: "series",
description: "", description: "",
tags: [],
meta: metadata, meta: metadata,
}; };

View File

@ -52,7 +52,8 @@ const POST = async (
} }
const posterPath = seriesDetails.poster_path; const posterPath = seriesDetails.poster_path;
const director = seriesCredits && 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) { if (director && director.name && !series.meta.author) {
series.meta.author = director.name; series.meta.author = director.name;
} }