feat: add update all recommendations command

This commit is contained in:
2023-09-08 15:15:36 +02:00
parent 297dab97cd
commit 6d5a3a1a0c
8 changed files with 177 additions and 50 deletions

View File

@ -5,6 +5,7 @@ import { createNewArticle } from "@islands/KMenu/commands/create_article.ts";
import { getCookie } from "@lib/string.ts";
import { addSeriesInfo } from "@islands/KMenu/commands/add_series_infos.ts";
import { createNewSeries } from "@islands/KMenu/commands/create_series.ts";
import { updateAllRecommendations } from "@islands/KMenu/commands/create_recommendations.ts";
export const menus: Record<string, Menu> = {
main: {
@ -85,6 +86,7 @@ export const menus: Record<string, Menu> = {
createNewMovie,
createNewSeries,
addMovieInfos,
updateAllRecommendations,
],
},
};

View File

@ -0,0 +1,29 @@
import { MenuEntry } from "@islands/KMenu/types.ts";
import { fetchStream } from "@lib/helpers.ts";
import { getCookie } from "@lib/string.ts";
export const updateAllRecommendations: MenuEntry = {
title: "Update all recommendations",
meta: "",
icon: "IconSquareRoundedPlus",
cb: (state) => {
state.activeState.value = "loading";
fetchStream("/api/recommendation/all", (chunk) => {
if (chunk.toLowerCase().includes("finish")) {
setTimeout(() => {
window.location.reload();
}, 500);
} else {
state.loadingText.value = chunk;
}
});
},
visible: () => {
if (!getCookie("session_cookie")) return false;
if (
!globalThis?.location?.pathname?.includes("movies")
) return false;
return true;
},
};