feat: some shit

This commit is contained in:
max_richter 2023-08-08 11:03:20 +02:00
parent eb1d065f1f
commit dccb6a6ecf
9 changed files with 95 additions and 19 deletions

View File

@ -39,10 +39,11 @@ import * as $$1 from "./islands/IngredientsList.tsx";
import * as $$2 from "./islands/KMenu.tsx";
import * as $$3 from "./islands/KMenu/commands.ts";
import * as $$4 from "./islands/KMenu/commands/add_movie_infos.ts";
import * as $$5 from "./islands/KMenu/commands/create_article.ts";
import * as $$6 from "./islands/KMenu/commands/create_movie.ts";
import * as $$7 from "./islands/KMenu/types.ts";
import * as $$8 from "./islands/Search.tsx";
import * as $$5 from "./islands/KMenu/commands/add_series_infos.ts";
import * as $$6 from "./islands/KMenu/commands/create_article.ts";
import * as $$7 from "./islands/KMenu/commands/create_movie.ts";
import * as $$8 from "./islands/KMenu/types.ts";
import * as $$9 from "./islands/Search.tsx";
const manifest = {
routes: {
@ -85,10 +86,11 @@ const manifest = {
"./islands/KMenu.tsx": $$2,
"./islands/KMenu/commands.ts": $$3,
"./islands/KMenu/commands/add_movie_infos.ts": $$4,
"./islands/KMenu/commands/create_article.ts": $$5,
"./islands/KMenu/commands/create_movie.ts": $$6,
"./islands/KMenu/types.ts": $$7,
"./islands/Search.tsx": $$8,
"./islands/KMenu/commands/add_series_infos.ts": $$5,
"./islands/KMenu/commands/create_article.ts": $$6,
"./islands/KMenu/commands/create_movie.ts": $$7,
"./islands/KMenu/types.ts": $$8,
"./islands/Search.tsx": $$9,
},
baseUrl: import.meta.url,
};

View 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"));
},
};

View File

@ -14,14 +14,13 @@ import { isLocalImage } from "@lib/string.ts";
export const RedirectSearchHandler = () => {
useEventListener("keydown", (e: KeyboardEvent) => {
if (e?.target?.nodeName == "INPUT") return;
if (
e.key === "?" &&
window.location.search === ""
) {
window.location.href += "?q=";
}
});
}, document?.body);
return <></>;
};
@ -136,13 +135,14 @@ const SearchComponent = (
debouncedFetchData(q);
}, []);
console.log({ data, isLoading });
return (
<div class="mt-2">
<div
class="flex items-center gap-1 rounded-xl w-full shadow-2xl"
style={{ background: "#2B2930", color: "#818181" }}
>
{isLoading
{isLoading && searchQuery
? <IconLoader2 class="w-4 h-4 ml-4 mr-2 animate-spin" />
: <IconSearch class="w-4 h-4 ml-4 mr-2" />}
<input

View File

@ -3,7 +3,7 @@ import { useEffect, useRef } from "preact/hooks";
export function useEventListener<T extends Event>(
eventName: string,
handler: (event: T) => void,
element = window,
element: Window | HTMLElement = window,
) {
console.log("Add Eventlistener", { eventName, element, handler });
// Create a ref that stores handler

View File

@ -27,8 +27,8 @@ export interface GiteaOauthUser {
groups: any;
}
export type SearchResult = SearchResponse<{
id:string;
export type TypesenseDocument = {
id: string;
name: string;
type: keyof typeof resources;
date?: string;
@ -36,4 +36,6 @@ export type SearchResult = SearchResponse<{
tags: string[];
description?: string;
image?: string;
}>;
};
export type SearchResult = SearchResponse<TypesenseDocument>;

View File

@ -6,6 +6,7 @@ import { getAllArticles } from "@lib/resource/articles.ts";
import { createLogger } from "@lib/log.ts";
import { debounce } from "https://deno.land/std@0.193.0/async/mod.ts";
import { getAllSeries } from "@lib/resource/series.ts";
import { TypesenseDocument } from "@lib/types.ts";
const log = createLogger("typesense");
@ -94,6 +95,16 @@ async function 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() {
await init;
try {

View File

@ -12,7 +12,8 @@ export const handler: Handlers = {
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 = "";
const type = url.searchParams.get("type");

View File

@ -1,5 +1,5 @@
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 { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { json } from "@lib/helpers.ts";
@ -28,7 +28,9 @@ const GET = async (
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);
if (
@ -37,7 +39,9 @@ const GET = async (
return json(cachedResponse.data);
}
const res = await searchMovie(query);
const res = type === "movie"
? await searchMovie(query)
: await searchTVShow(query);
cache.set(
cacheId,

View File

@ -3,6 +3,8 @@ import { MainLayout } from "@components/layouts/main.tsx";
import { Card } from "@components/Card.tsx";
import { PageProps } from "$fresh/server.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) {
return (
@ -10,6 +12,8 @@ export default function Home(props: PageProps) {
<Head>
<title>app</title>
</Head>
<RedirectSearchHandler />
<KMenu type="main" context={false} />
<MainLayout url={props.url}>
<div class="flex flex-wrap items-center gap-4 px-4">
{Object.values(resources).map((m) => {