feat: remove typesense

This commit is contained in:
2025-01-05 23:14:19 +01:00
parent d0d49b217d
commit 709fb2d7be
21 changed files with 128 additions and 381 deletions

View File

@ -1,15 +1,7 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { getAllMovies, Movie } from "@lib/resource/movies.ts";
import { Article, getAllArticles } from "@lib/resource/articles.ts";
import { getAllRecipes, Recipe } from "@lib/resource/recipes.ts";
import { AccessDeniedError } from "@lib/errors.ts";
const isResource = (
item: Movie | Article | Recipe | boolean,
): item is Movie | Article | Recipe => {
return !!item;
};
import { searchResource } from "@lib/search.ts";
export const handler: Handlers = {
async GET(req, ctx) {
@ -20,27 +12,16 @@ export const handler: Handlers = {
const url = new URL(req.url);
const types = url.searchParams.get("type")?.split(", ");
let resources = (await Promise.all([
(!types || types.includes("movie")) && getAllMovies(),
(!types || types.includes("article")) && getAllArticles(),
(!types || types.includes("recipe")) && getAllRecipes(),
])).flat().filter(isResource);
const types = url.searchParams.get("types")?.split(",");
const tags = url.searchParams?.get("tags")?.split(",");
if (tags?.length) {
resources = resources.filter((r) => {
return tags?.every((t) => r.tags.includes(t));
});
}
const authors = url.searchParams?.get("authors")?.split(",");
const authors = url.searchParams?.get("author")?.split(",");
if (authors?.length) {
resources = resources.filter((r) => {
return r?.meta?.author && authors.includes(r?.meta?.author);
});
}
const resources = await searchResource({
q: url.searchParams.get("q") || "",
types,
tags,
authors,
});
return json(resources);
},

View File

@ -1,16 +0,0 @@
import { AccessDeniedError } from "@lib/errors.ts";
import { Handlers } from "$fresh/server.ts";
import { synchronize } from "@lib/typesense.ts";
export const handler: Handlers = {
POST(_, ctx) {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
synchronize();
return new Response("OK");
},
};