From c17f8a15e8d8b89a488630b267efc86ab181d04a Mon Sep 17 00:00:00 2001 From: castdrian Date: Mon, 12 Jun 2023 21:25:24 +0200 Subject: [PATCH] more refactorings --- src/backend/metadata/getmeta.ts | 8 ++--- src/backend/metadata/justwatch.ts | 42 +++++-------------------- src/backend/metadata/search_old.ts | 9 ++---- src/backend/metadata/types.ts | 49 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/backend/metadata/getmeta.ts b/src/backend/metadata/getmeta.ts index 6b3b9a30..c4771451 100644 --- a/src/backend/metadata/getmeta.ts +++ b/src/backend/metadata/getmeta.ts @@ -1,13 +1,13 @@ import { FetchError } from "ofetch"; +import { formatJWMeta, mediaTypeToJW } from "./justwatch"; import { JWMediaResult, JWSeasonMetaResult, JW_API_BASE, - formatJWMeta, - mediaTypeToJW, -} from "./justwatch"; -import { MWMediaMeta, MWMediaType } from "./types"; + MWMediaMeta, + MWMediaType, +} from "./types"; import { makeUrl, proxiedFetch } from "../helpers/fetch"; type JWExternalIdType = diff --git a/src/backend/metadata/justwatch.ts b/src/backend/metadata/justwatch.ts index 5c79c1e3..27c5aa4c 100644 --- a/src/backend/metadata/justwatch.ts +++ b/src/backend/metadata/justwatch.ts @@ -1,38 +1,10 @@ -import { MWMediaMeta, MWMediaType, MWSeasonMeta } from "./types"; - -export const JW_API_BASE = "https://apis.justwatch.com"; -export const JW_IMAGE_BASE = "https://images.justwatch.com"; - -export type JWContentTypes = "movie" | "show"; - -export type JWSeasonShort = { - title: string; - id: number; - season_number: number; -}; - -export type JWEpisodeShort = { - title: string; - id: number; - episode_number: number; -}; - -export type JWMediaResult = { - title: string; - poster?: string; - id: number; - original_release_year?: number; - jw_entity_id: string; - object_type: JWContentTypes; - seasons?: JWSeasonShort[]; -}; - -export type JWSeasonMetaResult = { - title: string; - id: string; - season_number: number; - episodes: JWEpisodeShort[]; -}; +import { + JWContentTypes, + JWMediaResult, + JWSeasonMetaResult, + JW_IMAGE_BASE, +} 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 index 05be994d..f12f62d2 100644 --- a/src/backend/metadata/search_old.ts +++ b/src/backend/metadata/search_old.ts @@ -1,12 +1,7 @@ import { SimpleCache } from "@/utils/cache"; -import { - JWContentTypes, - JWMediaResult, - JW_API_BASE, - formatJWMeta, - mediaTypeToJW, -} from "./justwatch"; +import { formatJWMeta, mediaTypeToJW } from "./justwatch"; +import { JWContentTypes, JWMediaResult, JW_API_BASE } from "./types"; import { MWMediaMeta, MWQuery } from "./types_old"; import { proxiedFetch } from "../helpers/fetch"; diff --git a/src/backend/metadata/types.ts b/src/backend/metadata/types.ts index f954ff6a..9e87d49d 100644 --- a/src/backend/metadata/types.ts +++ b/src/backend/metadata/types.ts @@ -262,3 +262,52 @@ export interface TMDBMediaStatic { getMediaDetails(id: string, type: MWMediaType.MOVIE): TMDBMediaDetailsPromise; getMediaDetails(id: string, type: MWMediaType): TMDBMediaDetailsPromise; } + +export type JWContentTypes = "movie" | "show"; + +export type JWSearchQuery = { + content_types: JWContentTypes[]; + page: number; + page_size: number; + query: string; +}; + +export type JWPage = { + items: T[]; + page: number; + page_size: number; + total_pages: number; + total_results: number; +}; + +export const JW_API_BASE = "https://apis.justwatch.com"; +export const JW_IMAGE_BASE = "https://images.justwatch.com"; + +export type JWSeasonShort = { + title: string; + id: number; + season_number: number; +}; + +export type JWEpisodeShort = { + title: string; + id: number; + episode_number: number; +}; + +export type JWMediaResult = { + title: string; + poster?: string; + id: number; + original_release_year?: number; + jw_entity_id: string; + object_type: JWContentTypes; + seasons?: JWSeasonShort[]; +}; + +export type JWSeasonMetaResult = { + title: string; + id: string; + season_number: number; + episodes: JWEpisodeShort[]; +};