feat: some shit
This commit is contained in:
parent
eb1d065f1f
commit
dccb6a6ecf
18
fresh.gen.ts
18
fresh.gen.ts
@ -39,10 +39,11 @@ import * as $$1 from "./islands/IngredientsList.tsx";
|
|||||||
import * as $$2 from "./islands/KMenu.tsx";
|
import * as $$2 from "./islands/KMenu.tsx";
|
||||||
import * as $$3 from "./islands/KMenu/commands.ts";
|
import * as $$3 from "./islands/KMenu/commands.ts";
|
||||||
import * as $$4 from "./islands/KMenu/commands/add_movie_infos.ts";
|
import * as $$4 from "./islands/KMenu/commands/add_movie_infos.ts";
|
||||||
import * as $$5 from "./islands/KMenu/commands/create_article.ts";
|
import * as $$5 from "./islands/KMenu/commands/add_series_infos.ts";
|
||||||
import * as $$6 from "./islands/KMenu/commands/create_movie.ts";
|
import * as $$6 from "./islands/KMenu/commands/create_article.ts";
|
||||||
import * as $$7 from "./islands/KMenu/types.ts";
|
import * as $$7 from "./islands/KMenu/commands/create_movie.ts";
|
||||||
import * as $$8 from "./islands/Search.tsx";
|
import * as $$8 from "./islands/KMenu/types.ts";
|
||||||
|
import * as $$9 from "./islands/Search.tsx";
|
||||||
|
|
||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
@ -85,10 +86,11 @@ const manifest = {
|
|||||||
"./islands/KMenu.tsx": $$2,
|
"./islands/KMenu.tsx": $$2,
|
||||||
"./islands/KMenu/commands.ts": $$3,
|
"./islands/KMenu/commands.ts": $$3,
|
||||||
"./islands/KMenu/commands/add_movie_infos.ts": $$4,
|
"./islands/KMenu/commands/add_movie_infos.ts": $$4,
|
||||||
"./islands/KMenu/commands/create_article.ts": $$5,
|
"./islands/KMenu/commands/add_series_infos.ts": $$5,
|
||||||
"./islands/KMenu/commands/create_movie.ts": $$6,
|
"./islands/KMenu/commands/create_article.ts": $$6,
|
||||||
"./islands/KMenu/types.ts": $$7,
|
"./islands/KMenu/commands/create_movie.ts": $$7,
|
||||||
"./islands/Search.tsx": $$8,
|
"./islands/KMenu/types.ts": $$8,
|
||||||
|
"./islands/Search.tsx": $$9,
|
||||||
},
|
},
|
||||||
baseUrl: import.meta.url,
|
baseUrl: import.meta.url,
|
||||||
};
|
};
|
||||||
|
52
islands/KMenu/commands/add_series_infos.ts
Normal file
52
islands/KMenu/commands/add_series_infos.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import { MenuEntry } from "@islands/KMenu/types.ts";
|
||||||
|
import { TMDBMovie } from "@lib/types.ts";
|
||||||
|
import { getCookie } from "@lib/string.ts";
|
||||||
|
import { Series } from "@lib/resource/series.ts";
|
||||||
|
|
||||||
|
export const addMovieInfos: MenuEntry = {
|
||||||
|
title: "Add Movie infos",
|
||||||
|
meta: "",
|
||||||
|
icon: "IconReportSearch",
|
||||||
|
cb: async (state, context) => {
|
||||||
|
state.activeState.value = "loading";
|
||||||
|
const movie = context as Series;
|
||||||
|
|
||||||
|
const query = movie.name;
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
`/api/tmdb/query?q=${encodeURIComponent(query)}&type=serie`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const json = await response.json() as TMDBMovie[];
|
||||||
|
|
||||||
|
const menuID = `result/${movie.name}`;
|
||||||
|
|
||||||
|
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";
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
state.activeMenu.value = menuID;
|
||||||
|
|
||||||
|
state.activeState.value = "normal";
|
||||||
|
},
|
||||||
|
visible: () => {
|
||||||
|
const loc = globalThis["location"];
|
||||||
|
if (!getCookie("session_cookie")) return false;
|
||||||
|
return (loc?.pathname?.includes("movie") &&
|
||||||
|
!loc.pathname.endsWith("movies")) ||
|
||||||
|
(loc?.pathname?.includes("series") && !loc.pathname.endsWith("series"));
|
||||||
|
},
|
||||||
|
};
|
@ -14,14 +14,13 @@ import { isLocalImage } from "@lib/string.ts";
|
|||||||
export const RedirectSearchHandler = () => {
|
export const RedirectSearchHandler = () => {
|
||||||
useEventListener("keydown", (e: KeyboardEvent) => {
|
useEventListener("keydown", (e: KeyboardEvent) => {
|
||||||
if (e?.target?.nodeName == "INPUT") return;
|
if (e?.target?.nodeName == "INPUT") return;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
e.key === "?" &&
|
e.key === "?" &&
|
||||||
window.location.search === ""
|
window.location.search === ""
|
||||||
) {
|
) {
|
||||||
window.location.href += "?q=";
|
window.location.href += "?q=";
|
||||||
}
|
}
|
||||||
});
|
}, document?.body);
|
||||||
|
|
||||||
return <></>;
|
return <></>;
|
||||||
};
|
};
|
||||||
@ -136,13 +135,14 @@ const SearchComponent = (
|
|||||||
debouncedFetchData(q);
|
debouncedFetchData(q);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
console.log({ data, isLoading });
|
||||||
return (
|
return (
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<div
|
<div
|
||||||
class="flex items-center gap-1 rounded-xl w-full shadow-2xl"
|
class="flex items-center gap-1 rounded-xl w-full shadow-2xl"
|
||||||
style={{ background: "#2B2930", color: "#818181" }}
|
style={{ background: "#2B2930", color: "#818181" }}
|
||||||
>
|
>
|
||||||
{isLoading
|
{isLoading && searchQuery
|
||||||
? <IconLoader2 class="w-4 h-4 ml-4 mr-2 animate-spin" />
|
? <IconLoader2 class="w-4 h-4 ml-4 mr-2 animate-spin" />
|
||||||
: <IconSearch class="w-4 h-4 ml-4 mr-2" />}
|
: <IconSearch class="w-4 h-4 ml-4 mr-2" />}
|
||||||
<input
|
<input
|
||||||
|
@ -3,7 +3,7 @@ import { useEffect, useRef } from "preact/hooks";
|
|||||||
export function useEventListener<T extends Event>(
|
export function useEventListener<T extends Event>(
|
||||||
eventName: string,
|
eventName: string,
|
||||||
handler: (event: T) => void,
|
handler: (event: T) => void,
|
||||||
element = window,
|
element: Window | HTMLElement = window,
|
||||||
) {
|
) {
|
||||||
console.log("Add Eventlistener", { eventName, element, handler });
|
console.log("Add Eventlistener", { eventName, element, handler });
|
||||||
// Create a ref that stores handler
|
// Create a ref that stores handler
|
||||||
|
@ -27,8 +27,8 @@ export interface GiteaOauthUser {
|
|||||||
groups: any;
|
groups: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SearchResult = SearchResponse<{
|
export type TypesenseDocument = {
|
||||||
id:string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
type: keyof typeof resources;
|
type: keyof typeof resources;
|
||||||
date?: string;
|
date?: string;
|
||||||
@ -36,4 +36,6 @@ export type SearchResult = SearchResponse<{
|
|||||||
tags: string[];
|
tags: string[];
|
||||||
description?: string;
|
description?: string;
|
||||||
image?: string;
|
image?: string;
|
||||||
}>;
|
};
|
||||||
|
|
||||||
|
export type SearchResult = SearchResponse<TypesenseDocument>;
|
||||||
|
@ -6,6 +6,7 @@ import { getAllArticles } from "@lib/resource/articles.ts";
|
|||||||
import { createLogger } from "@lib/log.ts";
|
import { createLogger } from "@lib/log.ts";
|
||||||
import { debounce } from "https://deno.land/std@0.193.0/async/mod.ts";
|
import { debounce } from "https://deno.land/std@0.193.0/async/mod.ts";
|
||||||
import { getAllSeries } from "@lib/resource/series.ts";
|
import { getAllSeries } from "@lib/resource/series.ts";
|
||||||
|
import { TypesenseDocument } from "@lib/types.ts";
|
||||||
|
|
||||||
const log = createLogger("typesense");
|
const log = createLogger("typesense");
|
||||||
|
|
||||||
@ -94,6 +95,16 @@ async function initializeTypesense() {
|
|||||||
|
|
||||||
const init = initializeTypesense();
|
const init = initializeTypesense();
|
||||||
|
|
||||||
|
export async function createTypesenseDocument(doc: TypesenseDocument) {
|
||||||
|
const client = await getTypeSenseClient();
|
||||||
|
if (!client) return;
|
||||||
|
|
||||||
|
await client.collections("resources").documents().create(
|
||||||
|
doc,
|
||||||
|
{ action: "upsert" },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function synchronizeWithTypesense() {
|
async function synchronizeWithTypesense() {
|
||||||
await init;
|
await init;
|
||||||
try {
|
try {
|
||||||
|
@ -12,7 +12,8 @@ export const handler: Handlers = {
|
|||||||
throw new BadRequestError('Query parameter "q" is required.');
|
throw new BadRequestError('Query parameter "q" is required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const query_by = url.searchParams.get("query_by") || "name,description";
|
const query_by = url.searchParams.get("query_by") ||
|
||||||
|
"name,description,author,tags";
|
||||||
|
|
||||||
let filter_by = "";
|
let filter_by = "";
|
||||||
const type = url.searchParams.get("type");
|
const type = url.searchParams.get("type");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { HandlerContext, Handlers } from "$fresh/server.ts";
|
import { HandlerContext, Handlers } from "$fresh/server.ts";
|
||||||
import { searchMovie } from "@lib/tmdb.ts";
|
import { searchMovie, searchTVShow } from "@lib/tmdb.ts";
|
||||||
import * as cache from "@lib/cache/cache.ts";
|
import * as cache from "@lib/cache/cache.ts";
|
||||||
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
@ -28,7 +28,9 @@ const GET = async (
|
|||||||
throw new BadRequestError();
|
throw new BadRequestError();
|
||||||
}
|
}
|
||||||
|
|
||||||
const cacheId = `/movie/query/${query}`;
|
const type = u.searchParams.get("type") || "movie";
|
||||||
|
|
||||||
|
const cacheId = `/${type}/query/${query}`;
|
||||||
|
|
||||||
const cachedResponse = await cache.get<CachedMovieQuery>(cacheId);
|
const cachedResponse = await cache.get<CachedMovieQuery>(cacheId);
|
||||||
if (
|
if (
|
||||||
@ -37,7 +39,9 @@ const GET = async (
|
|||||||
return json(cachedResponse.data);
|
return json(cachedResponse.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await searchMovie(query);
|
const res = type === "movie"
|
||||||
|
? await searchMovie(query)
|
||||||
|
: await searchTVShow(query);
|
||||||
|
|
||||||
cache.set(
|
cache.set(
|
||||||
cacheId,
|
cacheId,
|
||||||
|
@ -3,6 +3,8 @@ import { MainLayout } from "@components/layouts/main.tsx";
|
|||||||
import { Card } from "@components/Card.tsx";
|
import { Card } from "@components/Card.tsx";
|
||||||
import { PageProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
import { resources } from "@lib/resources.ts";
|
import { resources } from "@lib/resources.ts";
|
||||||
|
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||||
|
import { KMenu } from "@islands/KMenu.tsx";
|
||||||
|
|
||||||
export default function Home(props: PageProps) {
|
export default function Home(props: PageProps) {
|
||||||
return (
|
return (
|
||||||
@ -10,6 +12,8 @@ export default function Home(props: PageProps) {
|
|||||||
<Head>
|
<Head>
|
||||||
<title>app</title>
|
<title>app</title>
|
||||||
</Head>
|
</Head>
|
||||||
|
<RedirectSearchHandler />
|
||||||
|
<KMenu type="main" context={false} />
|
||||||
<MainLayout url={props.url}>
|
<MainLayout url={props.url}>
|
||||||
<div class="flex flex-wrap items-center gap-4 px-4">
|
<div class="flex flex-wrap items-center gap-4 px-4">
|
||||||
{Object.values(resources).map((m) => {
|
{Object.values(resources).map((m) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user