This commit is contained in:
DevOFVictory
2025-10-08 17:26:35 +02:00
parent a01ffcd2bb
commit 21d2cb158e
3 changed files with 222 additions and 90 deletions

29
apis/searchApi.ts Normal file
View File

@@ -0,0 +1,29 @@
export type SearchItemType = "SHOW" | "PERSON" | "SEASON" | string;
export type SearchResultItem = {
type: SearchItemType;
data: any;
};
const DISCOVER_BASE = "http://45.157.177.99:8080/discover/search";
export async function getSearchResults(
tags: string[] | string,
limit = 10,
signal?: AbortSignal
): Promise<SearchResultItem[]> {
const tagList = Array.isArray(tags) ? tags : [tags];
const filteredTags = tagList.map((t) => t.trim()).filter(Boolean);
if (!filteredTags.length) return [];
const url = `${DISCOVER_BASE}?tags=${encodeURIComponent(
filteredTags.join(",")
)}&limit=${limit}`;
const res = await fetch(url, { signal });
if (!res.ok) throw new Error("AutoComplete failed " + res.status);
const data: unknown = await res.json();
if (!Array.isArray(data)) return [];
return data as SearchResultItem[];
}