feat: fallback to unsplash cover when article contains no image
This commit is contained in:
@@ -31,42 +31,55 @@ export const createNewSeries: MenuEntry = {
|
||||
|
||||
let currentQuery: string;
|
||||
const search = debounce(async function search(query: string) {
|
||||
currentQuery = query;
|
||||
if (query.length < 2) {
|
||||
return;
|
||||
try {
|
||||
currentQuery = query;
|
||||
if (query.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
"/api/tmdb/query?q=" + query + "&type=series",
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
|
||||
const series = await response.json() as TMDBSeries[];
|
||||
|
||||
if (query !== currentQuery) return;
|
||||
|
||||
state.menus["input_link"] = {
|
||||
title: "Search",
|
||||
entries: series.map((r) => {
|
||||
return {
|
||||
title: `${r.name} - ${r.first_air_date}`,
|
||||
cb: async () => {
|
||||
try {
|
||||
state.activeState.value = "loading";
|
||||
const response = await fetch("/api/series/" + r.id, {
|
||||
method: "POST",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
const series = await response.json() as ReviewResource;
|
||||
unsub();
|
||||
globalThis.location.href = "/series/" + series.name;
|
||||
} catch (e) {
|
||||
state.activeState.value = "error";
|
||||
state.loadingText.value = e.message;
|
||||
}
|
||||
},
|
||||
};
|
||||
}),
|
||||
};
|
||||
state.commandInput.value = "";
|
||||
state.activeMenu.value = "input_link";
|
||||
} catch (e) {
|
||||
state.activeState.value = "error";
|
||||
state.loadingText.value = e.message;
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
"/api/tmdb/query?q=" + query + "&type=series",
|
||||
);
|
||||
|
||||
const series = await response.json() as TMDBSeries[];
|
||||
|
||||
if (query !== currentQuery) return;
|
||||
|
||||
state.menus["input_link"] = {
|
||||
title: "Search",
|
||||
entries: series.map((r) => {
|
||||
return {
|
||||
title: `${r.name} - ${r.first_air_date}`,
|
||||
cb: async () => {
|
||||
try {
|
||||
state.activeState.value = "loading";
|
||||
const response = await fetch("/api/series/" + r.id, {
|
||||
method: "POST",
|
||||
});
|
||||
const series = await response.json() as ReviewResource;
|
||||
unsub();
|
||||
globalThis.location.href = "/series/" + series.name;
|
||||
} catch (_e) {
|
||||
state.activeState.value = "normal";
|
||||
}
|
||||
},
|
||||
};
|
||||
}),
|
||||
};
|
||||
state.commandInput.value = "";
|
||||
state.activeMenu.value = "input_link";
|
||||
}, 500);
|
||||
|
||||
const unsub = state.commandInput.subscribe((value) => {
|
||||
|
||||
Reference in New Issue
Block a user