feat: remove typesense
This commit is contained in:
@ -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);
|
||||
},
|
||||
|
@ -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");
|
||||
},
|
||||
};
|
@ -1,21 +0,0 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
||||
import { getTypeSenseClient } from "@lib/typesense.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(req, ctx) {
|
||||
const session = ctx.state.session;
|
||||
if (!session) {
|
||||
throw new AccessDeniedError();
|
||||
}
|
||||
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
|
||||
// Perform the Typesense search
|
||||
const searchResults = await searchResource(searchParams);
|
||||
|
||||
return json(searchResults);
|
||||
},
|
||||
};
|
@ -1,29 +1,30 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { Article, getAllArticles } from "@lib/resource/articles.ts";
|
||||
import { Card } from "@components/Card.tsx";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { Grid } from "@components/Grid.tsx";
|
||||
import { IconArrowLeft } from "@components/icons.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { SearchResult } from "@lib/types.ts";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { ResourceCard } from "@components/Card.tsx";
|
||||
|
||||
export const handler: Handlers<
|
||||
{ articles: Article[] | null; searchResults?: SearchResult }
|
||||
{ articles: Article[] | null; searchResults?: GenericResource[] }
|
||||
> = {
|
||||
async GET(req, ctx) {
|
||||
const articles = await getAllArticles();
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, type: "article" });
|
||||
await searchResource({ ...searchParams, types: ["article"] });
|
||||
return ctx.render({ articles, searchResults });
|
||||
},
|
||||
};
|
||||
|
||||
export default function Greet(
|
||||
props: PageProps<{ articles: Article[] | null; searchResults: SearchResult }>,
|
||||
props: PageProps<
|
||||
{ articles: Article[] | null; searchResults: GenericResource[] }
|
||||
>,
|
||||
) {
|
||||
const { articles, searchResults } = props.data;
|
||||
return (
|
||||
|
@ -6,16 +6,18 @@ import { IconArrowLeft } from "@components/icons.tsx";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { SearchResult } from "@lib/types.ts";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { PageProps } from "$fresh/server.ts";
|
||||
|
||||
export default async function Greet(
|
||||
props: PageProps<{ movies: Movie[] | null; searchResults: SearchResult }>,
|
||||
props: PageProps<
|
||||
{ movies: Movie[] | null; searchResults: GenericResource[] }
|
||||
>,
|
||||
) {
|
||||
const allMovies = await getAllMovies();
|
||||
const searchParams = parseResourceUrl(props.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, type: "movie" });
|
||||
await searchResource({ ...searchParams, types: ["movie"] });
|
||||
const movies = allMovies.sort((a, b) =>
|
||||
a?.meta?.rating > b?.meta?.rating ? -1 : 1
|
||||
);
|
||||
|
@ -6,23 +6,25 @@ import { IconArrowLeft } from "@components/icons.tsx";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { SearchResult } from "@lib/types.ts";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { ResourceCard } from "@components/Card.tsx";
|
||||
|
||||
export const handler: Handlers<
|
||||
{ recipes: Recipe[] | null; searchResults?: SearchResult }
|
||||
{ recipes: Recipe[] | null; searchResults?: GenericResource[] }
|
||||
> = {
|
||||
async GET(req, ctx) {
|
||||
const recipes = await getAllRecipes();
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, type: "recipe" });
|
||||
await searchResource({ ...searchParams, types: ["recipe"] });
|
||||
return ctx.render({ recipes, searchResults });
|
||||
},
|
||||
};
|
||||
|
||||
export default function Greet(
|
||||
props: PageProps<{ recipes: Recipe[] | null; searchResults: SearchResult }>,
|
||||
props: PageProps<
|
||||
{ recipes: Recipe[] | null; searchResults: GenericResource[] }
|
||||
>,
|
||||
) {
|
||||
const { recipes, searchResults } = props.data;
|
||||
return (
|
||||
|
@ -7,22 +7,24 @@ import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { ResourceCard } from "@components/Card.tsx";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { SearchResult } from "@lib/types.ts";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
|
||||
export const handler: Handlers<
|
||||
{ series: Series[] | null; searchResults?: SearchResult }
|
||||
{ series: Series[] | null; searchResults?: GenericResource[] }
|
||||
> = {
|
||||
async GET(req, ctx) {
|
||||
const series = await getAllSeries();
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, type: "series" });
|
||||
await searchResource({ ...searchParams, types: ["series"] });
|
||||
return ctx.render({ series, searchResults });
|
||||
},
|
||||
};
|
||||
|
||||
export default function Greet(
|
||||
props: PageProps<{ series: Series[] | null; searchResults: SearchResult }>,
|
||||
props: PageProps<
|
||||
{ series: Series[] | null; searchResults: GenericResource[] }
|
||||
>,
|
||||
) {
|
||||
const { series, searchResults } = props.data;
|
||||
|
||||
|
Reference in New Issue
Block a user