From b22e3ff8c14e4eb78e52dcdeb7a61814a37c6a75 Mon Sep 17 00:00:00 2001 From: castdrian Date: Tue, 13 Jun 2023 14:25:31 +0200 Subject: [PATCH] cleanup --- src/backend/metadata/justwatch.ts | 4 ++- src/backend/metadata/search_old.ts | 54 ------------------------------ src/backend/metadata/types_old.ts | 47 -------------------------- 3 files changed, 3 insertions(+), 102 deletions(-) delete mode 100644 src/backend/metadata/search_old.ts delete mode 100644 src/backend/metadata/types_old.ts diff --git a/src/backend/metadata/justwatch.ts b/src/backend/metadata/justwatch.ts index 27c5aa4c..857ff006 100644 --- a/src/backend/metadata/justwatch.ts +++ b/src/backend/metadata/justwatch.ts @@ -3,8 +3,10 @@ import { JWMediaResult, JWSeasonMetaResult, JW_IMAGE_BASE, + MWMediaMeta, + MWMediaType, + MWSeasonMeta, } from "./types"; -import { MWMediaMeta, MWMediaType, MWSeasonMeta } from "./types_old"; export function mediaTypeToJW(type: MWMediaType): JWContentTypes { if (type === MWMediaType.MOVIE) return "movie"; diff --git a/src/backend/metadata/search_old.ts b/src/backend/metadata/search_old.ts deleted file mode 100644 index f12f62d2..00000000 --- a/src/backend/metadata/search_old.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { SimpleCache } from "@/utils/cache"; - -import { formatJWMeta, mediaTypeToJW } from "./justwatch"; -import { JWContentTypes, JWMediaResult, JW_API_BASE } from "./types"; -import { MWMediaMeta, MWQuery } from "./types_old"; -import { proxiedFetch } from "../helpers/fetch"; - -const cache = new SimpleCache(); -cache.setCompare((a, b) => { - return a.type === b.type && a.searchQuery.trim() === b.searchQuery.trim(); -}); -cache.initialize(); - -type JWSearchQuery = { - content_types: JWContentTypes[]; - page: number; - page_size: number; - query: string; -}; - -type JWPage = { - items: T[]; - page: number; - page_size: number; - total_pages: number; - total_results: number; -}; - -export async function searchForMedia(query: MWQuery): Promise { - if (cache.has(query)) return cache.get(query) as MWMediaMeta[]; - const { searchQuery, type } = query; - - const contentType = mediaTypeToJW(type); - const body: JWSearchQuery = { - content_types: [contentType], - page: 1, - query: searchQuery, - page_size: 40, - }; - - const data = await proxiedFetch>( - "/content/titles/en_US/popular", - { - baseURL: JW_API_BASE, - params: { - body: JSON.stringify(body), - }, - } - ); - - const returnData = data.items.map((v) => formatJWMeta(v)); - cache.set(query, returnData, 3600); // cache for an hour - return returnData; -} diff --git a/src/backend/metadata/types_old.ts b/src/backend/metadata/types_old.ts deleted file mode 100644 index 2723fbe7..00000000 --- a/src/backend/metadata/types_old.ts +++ /dev/null @@ -1,47 +0,0 @@ -export enum MWMediaType { - MOVIE = "movie", - SERIES = "series", - ANIME = "anime", -} - -export type MWSeasonMeta = { - id: string; - number: number; - title: string; -}; - -export type MWSeasonWithEpisodeMeta = { - id: string; - number: number; - title: string; - episodes: { - id: string; - number: number; - title: string; - }[]; -}; - -type MWMediaMetaBase = { - title: string; - id: string; - year?: string; - poster?: string; -}; - -type MWMediaMetaSpecific = - | { - type: MWMediaType.MOVIE | MWMediaType.ANIME; - seasons: undefined; - } - | { - type: MWMediaType.SERIES; - seasons: MWSeasonMeta[]; - seasonData: MWSeasonWithEpisodeMeta; - }; - -export type MWMediaMeta = MWMediaMetaBase & MWMediaMetaSpecific; - -export interface MWQuery { - searchQuery: string; - type: MWMediaType; -}