feat: fallback to unsplash cover when article contains no image

This commit is contained in:
Max Richter
2025-11-09 23:52:53 +01:00
parent 6c6b69a46a
commit 655fc648e6
27 changed files with 687 additions and 224 deletions

View File

@@ -8,39 +8,53 @@ export const addMovieInfos: MenuEntry = {
meta: "",
icon: "IconReportSearch",
cb: async (state, context) => {
state.activeState.value = "loading";
const movie = context as ReviewResource;
try {
state.activeState.value = "loading";
const movie = context as ReviewResource;
const query = movie.name;
const query = movie.name;
const response = await fetch(
`/api/tmdb/query?q=${encodeURIComponent(query)}`,
);
const response = await fetch(
`/api/tmdb/query?q=${encodeURIComponent(query)}`,
);
const json = await response.json() as TMDBMovie[];
if (!response.ok) {
throw new Error(await response.text());
}
const menuID = `result/${movie.name}`;
const json = await response.json() as TMDBMovie[];
state.menus[menuID] = {
title: "Select",
entries: json.map((m) => ({
title: `${m.title} released ${m.release_date}`,
cb: async () => {
state.activeState.value = "loading";
await fetch(`/api/movies/enhance/${movie.name}/`, {
method: "POST",
body: JSON.stringify({ tmdbId: m.id }),
});
state.visible.value = false;
state.activeState.value = "normal";
globalThis.location.reload();
},
})),
};
const menuID = `result/${movie.name}`;
state.activeMenu.value = menuID;
state.commandInput.value = "";
state.activeState.value = "normal";
state.menus[menuID] = {
title: "Select",
entries: json.map((m) => ({
title: `${m.title} released ${m.release_date}`,
cb: async () => {
try {
state.activeState.value = "loading";
await fetch(`/api/movies/enhance/${movie.name}/`, {
method: "POST",
body: JSON.stringify({ tmdbId: m.id }),
});
state.visible.value = false;
state.activeState.value = "normal";
globalThis.location.reload();
} catch (e) {
state.activeState.value = "error";
state.loadingText.value = e.message;
}
},
})),
};
state.activeMenu.value = menuID;
state.commandInput.value = "";
state.activeState.value = "normal";
} catch (e) {
state.activeState.value = "error";
state.loadingText.value = e.message;
}
},
visible: () => {
const loc = globalThis["location"];