diff --git a/src/api.ts b/src/api.ts index e18ebc2..456b139 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,5 +1,9 @@ /* eslint-disable n/no-unsupported-features/node-builtins */ import { IList, IMediaCredits, IPersonCredits } from "./interfaces/IList"; +import type { + IRequestStatusResponse, + IRequestSubmitResponse +} from "./interfaces/IRequestResponse"; const API_HOSTNAME = import.meta.env.VITE_SEASONED_API; const ELASTIC_URL = import.meta.env.VITE_ELASTIC_URL; @@ -261,7 +265,7 @@ const addMagnet = (magnet: string, name: string, tmdbId: number | null) => { * @param {string} type Movie or show type * @returns {object} Success/Failure response */ -const request = (id, type) => { +const request = (id, type): Promise => { const url = new URL("/api/v2/request", API_HOSTNAME); const options = { @@ -284,18 +288,13 @@ const request = (id, type) => { * @param {string} type * @returns {object} Success/Failure response */ -const getRequestStatus = (id, type = undefined) => { +const getRequestStatus = (id, type = null): Promise => { const url = new URL("/api/v2/request", API_HOSTNAME); url.pathname = `${url.pathname}/${id.toString()}`; url.searchParams.append("type", type); return fetch(url.href) - .then(resp => { - const { status } = resp; - if (status === 200) return true; - - return false; - }) + .then(resp => resp.json()) .catch(err => Promise.reject(err)); }; @@ -437,9 +436,13 @@ const unlinkPlexAccount = () => { // - - - User graphs - - - -const fetchGraphData = (urlPath, days, chartType) => { +const fetchGraphData = async ( + urlPath: string, + days: number, + chartType: string +) => { const url = new URL(`/api/v1/user/${urlPath}`, API_HOSTNAME); - url.searchParams.append("days", days); + url.searchParams.append("days", String(days)); url.searchParams.append("y_axis", chartType); return fetch(url.href).then(resp => { @@ -454,7 +457,7 @@ const fetchGraphData = (urlPath, days, chartType) => { // - - - Random emoji - - - -const getEmoji = () => { +const getEmoji = async () => { const url = new URL("/api/v1/emoji", API_HOSTNAME); return fetch(url.href) @@ -475,28 +478,51 @@ const getEmoji = () => { * @param {string} query * @returns {object} List of movies and shows matching query */ + const elasticSearchMoviesAndShows = (query, count = 22) => { const url = new URL(`${ELASTIC_URL}/_search`); const body = { sort: [{ popularity: { order: "desc" } }, "_score"], + size: count, query: { - bool: { - should: [ - { - match_phrase_prefix: { - original_name: query - } - }, - { - match_phrase_prefix: { - original_title: query - } - } - ] + multi_match: { + query, + fields: ["name", "original_title", "original_name"], + type: "phrase_prefix", + tie_breaker: 0.3 } }, - size: count + suggest: { + text: query, + "person-suggest": { + prefix: query, + completion: { + field: "name.completion", + fuzzy: { + fuzziness: "AUTO" + } + } + }, + "movie-suggest": { + prefix: query, + completion: { + field: "original_title.completion", + fuzzy: { + fuzziness: "AUTO" + } + } + }, + "show-suggest": { + prefix: query, + completion: { + field: "original_name.completion", + fuzzy: { + fuzziness: "AUTO" + } + } + } + } }; const options = { diff --git a/src/components/CastListItem.vue b/src/components/CastListItem.vue index 177f682..53f4754 100644 --- a/src/components/CastListItem.vue +++ b/src/components/CastListItem.vue @@ -9,7 +9,7 @@ diff --git a/src/components/torrent/TorrentTable.vue b/src/components/torrent/TorrentTable.vue index 0b1dadb..94b6b8f 100644 --- a/src/components/torrent/TorrentTable.vue +++ b/src/components/torrent/TorrentTable.vue @@ -52,7 +52,7 @@