feat: trying to add hashes to scripts

This commit is contained in:
Max Richter
2026-01-10 13:03:13 +01:00
parent e65938ecc2
commit e55f787a29
79 changed files with 4209 additions and 720 deletions

View File

@@ -1,6 +1,5 @@
// deno-lint-ignore-file react-no-danger
import { PageProps } from "$fresh/server.ts";
import { Partial } from "$fresh/runtime.ts";
import { PageProps } from "fresh";
import { Partial } from "fresh/runtime";
export default function App({ Component }: PageProps) {
const globalCss = Deno.readTextFileSync("./static/global.css");

View File

@@ -1,7 +1,18 @@
import { Head } from "$fresh/runtime.ts";
import { Head } from "fresh/runtime";
import { MainLayout } from "@components/layouts/main.tsx";
import { HttpError, PageProps } from "fresh";
export default function ErrorPage(props: PageProps) {
const error = props.error; // Contains the thrown Error or HTTPError
if (error instanceof HttpError) {
const status = error.status; // HTTP status code
// Render a 404 not found page
if (status === 404) {
return <h1>404 - Page not found</h1>;
}
}
export default function Error404() {
return (
<>
<Head>

View File

@@ -1,8 +1,8 @@
import { PageProps } from "$fresh/server.ts";
import { resources } from "@lib/resources.ts";
import { Link } from "@islands/Link.tsx";
import { Emoji } from "@components/Emoji.tsx";
import KMenuButton from "@islands/KMenuButton.tsx";
import { PageProps } from "fresh";
export default function MyLayout({ Component }: PageProps) {
return (

View File

@@ -1,27 +1,39 @@
//routes/middleware-error-handler/_middleware.ts
import { FreshContext } from "$fresh/server.ts";
import { DomainError } from "@lib/errors.ts";
import { getCookies } from "@std/http/cookie";
import { verify } from "https://deno.land/x/djwt@v2.2/mod.ts";
import { verify } from "@zaubrik/djwt";
import * as perf from "@lib/performance.ts";
import { JWT_SECRET } from "@lib/env.ts";
import { define } from "../utils.ts";
export async function handler(
req: Request,
ctx: FreshContext,
function importKey(secret: string) {
return crypto.subtle.importKey(
"raw",
new TextEncoder().encode(secret),
{ name: "HMAC", hash: "SHA-512" },
false,
["sign", "verify"],
);
}
const authMiddleware = define.middleware(async function (
ctx,
) {
const req = ctx.req;
try {
performance.mark("a");
const allCookies = getCookies(req.headers);
const sessionCookie = allCookies["session_cookie"];
if (!ctx.state.session && sessionCookie && JWT_SECRET) {
try {
const payload = await verify(sessionCookie, JWT_SECRET, "HS512");
const payload = await verify<typeof ctx.state.session>(
sessionCookie,
await importKey(JWT_SECRET),
);
if (payload) {
ctx.state.session = payload;
}
} catch (_err) {
//
console.log({ _err });
}
}
@@ -44,4 +56,6 @@ export async function handler(
status: 500,
});
}
}
});
export default [authMiddleware];

View File

@@ -1,14 +1,13 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { Handlers, PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { getCacheInfo } from "@lib/cache.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers<
{ cacheInfo: ReturnType<typeof getCacheInfo> }
> = {
GET(_, ctx) {
return ctx.render({ cacheInfo: getCacheInfo() });
export const handler = define.handlers({
GET() {
return { data: { cacheInfo: getCacheInfo() } };
},
};
});
export default function Greet(
props: PageProps<

View File

@@ -1,31 +1,34 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { Handlers, PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { AccessDeniedError } from "@lib/errors.ts";
import { getLogs, Log } from "@lib/log/index.ts";
import { formatDate } from "@lib/string.ts";
import { renderMarkdown } from "@lib/markdown.ts";
import { define } from "../../../utils.ts";
const renderLog = (t: unknown) =>
renderMarkdown(`\`\`\`js
${typeof t === "string" ? t : JSON.stringify(t, null, 2).trim()}
\`\`\``);
export const handler: Handlers = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const logs = await getLogs();
if (!("session" in ctx.state)) {
throw new AccessDeniedError();
}
return ctx.render({
logs: logs.map((l) => {
return {
...l,
html: l.args.map(renderLog).join("<br/>"),
};
}),
});
return {
data: {
logs: logs.map((l) => {
return {
...l,
html: l.args.map(renderLog).join("<br/>"),
};
}),
},
};
},
};
});
function LogLine(
{ log }: {

View File

@@ -1,18 +1,19 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { Handlers, PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { getPerformances, PerformanceRes } from "@lib/performance.ts";
import { AccessDeniedError } from "@lib/errors.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const performances = await getPerformances();
if (!("session" in ctx.state)) {
throw new AccessDeniedError();
}
return ctx.render({ performances });
return { data: { performances } };
},
};
});
function PerformanceLine(
{ maximum, data: [amount, min, average, max], url }: {

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/marka/index.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const article = await fetchResource(`articles/${ctx.params.name}`);
return json(article);
},
};
});

View File

@@ -1,5 +1,3 @@
import { Handlers } from "$fresh/server.ts";
import { Defuddle } from "defuddle/node";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { createStreamResponse, isValidUrl } from "@lib/helpers.ts";
import * as openai from "@lib/openai.ts";
@@ -7,6 +5,7 @@ import * as unsplash from "@lib/unsplash.ts";
import { getYoutubeVideoDetails } from "@lib/youtube.ts";
import {
extractYoutubeId,
fileExtension,
formatDate,
isYoutubeLink,
safeFileName,
@@ -16,7 +15,7 @@ import { createLogger } from "@lib/log/index.ts";
import { createResource } from "@lib/marka/index.ts";
import { webScrape } from "@lib/webScraper.ts";
import { ArticleResource } from "@lib/marka/schema.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import { define } from "../../../../utils.ts";
const log = createLogger("api/article");
@@ -201,8 +200,9 @@ async function processCreateYoutubeVideo(
streamResponse.send({ type: "finished", url: filename });
}
export const handler: Handlers = {
GET(req, ctx) {
export const handler = define.handlers({
GET(ctx) {
const req = ctx.req;
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
@@ -239,4 +239,4 @@ export const handler: Handlers = {
return streamResponse.response;
},
};
});

View File

@@ -1,6 +1,4 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import { formatDate, safeFileName } from "@lib/string.ts";
import { fileExtension, formatDate, safeFileName } from "@lib/string.ts";
import { createStreamResponse } from "@lib/helpers.ts";
import {
AccessDeniedError,
@@ -13,6 +11,7 @@ import { webScrape } from "@lib/webScraper.ts";
import * as openai from "@lib/openai.ts";
import * as unsplash from "@lib/unsplash.ts";
import { createLogger } from "@lib/log/index.ts";
import { define } from "../../../../utils.ts";
function ext(str: string) {
try {
@@ -163,29 +162,24 @@ async function processEnhanceArticle(
streamResponse.send({ type: "finished", url: name.replace(/$\.md/, "") });
}
const POST = (
_req: Request,
ctx: FreshContext,
): Response => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
export const handler = define.handlers({
POST: (ctx) => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const streamResponse = createStreamResponse();
const streamResponse = createStreamResponse();
processEnhanceArticle(ctx.params.name, streamResponse)
.catch((err) => {
log.error(err);
streamResponse.error(err.message);
})
.finally(() => {
streamResponse.cancel();
});
processEnhanceArticle(ctx.params.name, streamResponse)
.catch((err) => {
log.error(err);
streamResponse.error(err.message);
})
.finally(() => {
streamResponse.cancel();
});
return streamResponse.response;
};
export const handler: Handlers = {
POST,
};
return streamResponse.response;
},
});

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/marka/index.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
export const handler = define.handlers({
async GET() {
const articles = await fetchResource("articles");
return json(articles?.content);
},
};
});

View File

@@ -1,5 +1,4 @@
import { Handlers } from "$fresh/server.ts";
import { create, getNumericDate } from "https://deno.land/x/djwt@v2.2/mod.ts";
import { create, getNumericDate } from "@zaubrik/djwt";
import { oauth2Client } from "@lib/auth.ts";
import { getCookies, setCookie } from "@std/http/cookie";
import { codeChallengeMap } from "./login.ts";
@@ -9,15 +8,16 @@ import { BadRequestError } from "@lib/errors.ts";
import { db } from "@lib/db/sqlite.ts";
import { userTable } from "@lib/db/schema.ts";
import { eq } from "drizzle-orm";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
async GET(request) {
export const handler = define.handlers({
async GET(ctx) {
if (!JWT_SECRET) {
throw new BadRequestError();
}
// Exchange the authorization code for an access token
const cookies = getCookies(request.headers);
const cookies = getCookies(ctx.req.headers);
const stored = codeChallengeMap.get(cookies["code_challenge"]);
if (!stored) {
@@ -26,7 +26,7 @@ export const handler: Handlers = {
const { codeVerifier, redirect } = stored;
const tokens = await oauth2Client.code.getToken(request.url, {
const tokens = await oauth2Client.code.getToken(ctx.req.url, {
codeVerifier,
});
@@ -53,11 +53,23 @@ export const handler: Handlers = {
user = res[0];
}
if (!JWT_SECRET) {
throw new BadRequestError();
}
const key = await crypto.subtle.importKey(
"raw",
new TextEncoder().encode(JWT_SECRET),
{ name: "HMAC", hash: "SHA-512" },
false,
["sign", "verify"],
);
const jwt = await create({ alg: "HS512", type: "JWT" }, {
id: user.id,
name: user.name,
exp: getNumericDate(SESSION_DURATION),
}, JWT_SECRET);
}, key);
const headers = new Headers({
location: redirect || "/",
@@ -78,4 +90,4 @@ export const handler: Handlers = {
status: 302,
});
},
};
});

View File

@@ -1,14 +1,15 @@
import { Handlers } from "$fresh/server.ts";
import { oauth2Client } from "@lib/auth.ts";
import { setCookie } from "@std/http/cookie";
import { define } from "../../../utils.ts";
export const codeChallengeMap = new Map<
string,
{ codeVerifier: string; redirect?: string }
>();
export const handler: Handlers = {
async GET(req) {
export const handler = define.handlers({
async GET(ctx) {
const req = ctx.req;
const url = new URL(req.url);
const { codeVerifier, uri } = await oauth2Client.code.getAuthorizationUri();
@@ -33,4 +34,4 @@ export const handler: Handlers = {
status: 302,
});
},
};
});

View File

@@ -1,8 +1,9 @@
import { deleteCookie } from "@std/http/cookie";
import { Handlers } from "$fresh/server.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
GET(req) {
export const handler = define.handlers({
GET(ctx) {
const req = ctx.req;
const url = new URL(req.url);
const redirect = decodeURIComponent(url.searchParams.get("redirect") || "");
@@ -19,4 +20,4 @@ export const handler: Handlers = {
status: 302,
});
},
};
});

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { documentTable } from "@lib/db/schema.ts";
import { db } from "@lib/db/sqlite.ts";
import { json } from "@lib/helpers.ts";
import { caches } from "@lib/cache.ts";
import { define } from "../../utils.ts";
export const handler: Handlers = {
export const handler = define.handlers({
async DELETE() {
for (const cache of caches.values()) {
cache.clear();
@@ -12,4 +12,4 @@ export const handler: Handlers = {
await db.delete(documentTable).run();
return json({ status: "ok" });
},
};
});

View File

@@ -1,6 +1,6 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { getImageContent } from "@lib/image.ts";
import { createLogger } from "@lib/log/index.ts";
import { Context } from "fresh";
const log = createLogger("api/image");
@@ -69,9 +69,9 @@ async function generateETag(content: Uint8Array<ArrayBuffer>): Promise<string> {
}"`;
}
async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
async function GET(ctx: Context<unknown>): Promise<Response> {
try {
const url = new URL(req.url);
const url = new URL(ctx.req.url);
const params = parseParams(url);
if (typeof params === "string") {
@@ -106,6 +106,6 @@ async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
}
}
export const handler: Handlers = {
export const handler = {
GET,
};

View File

@@ -1,8 +1,8 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { define } from "../../utils.ts";
export const handler: Handlers = {
export const handler = define.handlers({
GET() {
return json([]);
},
};
});

View File

@@ -1,9 +1,9 @@
import { Handlers } from "$fresh/server.ts";
import { createStreamResponse } from "@lib/helpers.ts";
import { define } from "../../utils.ts";
const activeResponses: ReturnType<typeof createStreamResponse>[] = [];
export const handler: Handlers = {
export const handler = define.handlers({
GET() {
const r = createStreamResponse();
@@ -11,4 +11,4 @@ export const handler: Handlers = {
return r.response;
},
};
});

View File

@@ -1,8 +1,7 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import * as tmdb from "@lib/tmdb.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import {
fileExtension,
formatDate,
isString,
safeFileName,
@@ -11,13 +10,14 @@ import {
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { createResource, fetchResource } from "@lib/marka/index.ts";
import { ReviewResource } from "@lib/marka/schema.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const movie = await fetchResource(`movies/${ctx.params.name}`);
return json(movie?.content);
},
async POST(_, ctx) {
async POST(ctx) {
const session = ctx.state.session;
if (!session) throw new AccessDeniedError();
@@ -70,4 +70,4 @@ export const handler: Handlers = {
return json({ name: fileName });
},
};
});

View File

@@ -1,7 +1,6 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import * as tmdb from "@lib/tmdb.ts";
import {
fileExtension,
formatDate,
isString,
safeFileName,
@@ -16,80 +15,76 @@ import {
import { createRecommendationResource } from "@lib/recommendation.ts";
import { createResource, fetchResource } from "@lib/marka/index.ts";
import { ReviewResource } from "@lib/marka/schema.ts";
import { define } from "../../../../utils.ts";
const POST = async (
req: Request,
ctx: FreshContext,
): Promise<Response> => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
export const handler = define.handlers({
POST: async function (ctx) {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const movie = await fetchResource<ReviewResource>(
`movies/${ctx.params.name}`,
);
if (!movie) {
throw new NotFoundError();
}
const movie = await fetchResource<ReviewResource>(
`movies/${ctx.params.name}`,
);
if (!movie) {
throw new NotFoundError();
}
const body = await req.json();
const name = ctx.params.name;
const { tmdbId } = body;
if (!name || !tmdbId) {
throw new BadRequestError();
}
const body = await ctx.req.json();
const name = ctx.params.name;
const { tmdbId } = body;
if (!name || !tmdbId) {
throw new BadRequestError();
}
const movieDetails = await tmdb.getMovie(tmdbId);
const movieCredits = !movie.content?.author &&
await tmdb.getMovieCredits(tmdbId);
const movieDetails = await tmdb.getMovie(tmdbId);
const movieCredits = !movie.content?.author &&
await tmdb.getMovieCredits(tmdbId);
const director = movieCredits &&
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
const director = movieCredits &&
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
movie.content ??= {
_type: "Review",
};
movie.content.datePublished ??= formatDate(movieDetails.release_date);
if (director && !movie.content?.author) {
movie.content.author = {
_type: "Person",
name: director.name,
movie.content ??= {
_type: "Review",
};
}
if (movieDetails.genres) {
movie.content.keywords = [
...new Set([
...(movie.content.keywords?.map((g) => g.toLowerCase()) || []),
...movieDetails.genres.map((g) =>
g.name?.toLowerCase().replaceAll(" ", "-")
),
].filter(isString)),
];
}
movie.content.datePublished ??= formatDate(movieDetails.release_date);
movie.content.tmdbId ??= tmdbId;
if (director && !movie.content?.author) {
movie.content.author = {
_type: "Person",
name: director.name,
};
}
let finalPath = "";
const posterPath = movieDetails.poster_path;
if (posterPath && !movie.content.image) {
const poster = await tmdb.getMoviePoster(posterPath);
const extension = fileExtension(posterPath);
finalPath = `movies/images/${safeFileName(name)}_cover.${extension}`;
await createResource(finalPath, poster);
movie.content.image = finalPath;
}
if (movieDetails.genres) {
movie.content.keywords = [
...new Set([
...(movie.content.keywords?.map((g) => g.toLowerCase()) || []),
...movieDetails.genres.map((g) =>
g.name?.toLowerCase().replaceAll(" ", "-")
),
].filter(isString)),
];
}
await createResource(`movies/${toUrlSafeString(movie.name)}.md`, movie);
movie.content.tmdbId ??= tmdbId;
createRecommendationResource(movie, movieDetails.overview);
let finalPath = "";
const posterPath = movieDetails.poster_path;
if (posterPath && !movie.content.image) {
const poster = await tmdb.getMoviePoster(posterPath);
const extension = fileExtension(posterPath);
finalPath = `movies/images/${safeFileName(name)}_cover.${extension}`;
await createResource(finalPath, poster);
movie.content.image = finalPath;
}
return json(movie);
};
await createResource(`movies/${toUrlSafeString(movie.name)}.md`, movie);
export const handler: Handlers = {
POST,
};
createRecommendationResource(movie, movieDetails.overview);
return json(movie);
},
});

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/marka/index.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
export const handler = define.handlers({
async GET() {
const movies = await fetchResource("movies");
return json(movies);
},
};
});

View File

@@ -1,10 +1,11 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
async GET(req, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const req = ctx.req;
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
@@ -20,4 +21,4 @@ export const handler: Handlers = {
return json(resources);
},
};
});

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/marka/index.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const recipe = await fetchResource(`recipes/${ctx.params.name}`);
return json(recipe);
},
};
});

View File

@@ -1,16 +1,15 @@
import { Handlers } from "$fresh/server.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { createStreamResponse, isValidUrl } from "@lib/helpers.ts";
import * as openai from "@lib/openai.ts";
import { createLogger } from "@lib/log/index.ts";
import recipeSchema from "@lib/recipeSchema.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import { safeFileName, toUrlSafeString } from "@lib/string.ts";
import { fileExtension, safeFileName, toUrlSafeString } from "@lib/string.ts";
import { parseJsonLdToRecipeSchema } from "./parseJsonLd.ts";
import z from "zod";
import { createResource } from "@lib/marka/index.ts";
import { webScrape } from "@lib/webScraper.ts";
import { RecipeResource } from "@lib/marka/schema.ts";
import { define } from "../../../../utils.ts";
const log = createLogger("api/article");
@@ -93,8 +92,9 @@ async function processCreateRecipeFromUrl(
streamResponse.send({ type: "finished", url: id });
}
export const handler: Handlers = {
GET(req, ctx) {
export const handler = define.handlers({
GET(ctx) {
const req = ctx.req;
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
@@ -120,4 +120,4 @@ export const handler: Handlers = {
return streamResponse.response;
},
};
});

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/marka/index.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
export const handler = define.handlers({
async GET() {
const recipes = await fetchResource("recipes");
return json(recipes);
},
};
});

View File

@@ -1,4 +1,3 @@
import { Handlers } from "$fresh/server.ts";
import { createStreamResponse } from "@lib/helpers.ts";
import * as tmdb from "@lib/tmdb.ts";
import {
@@ -8,6 +7,7 @@ import {
import { AccessDeniedError } from "@lib/errors.ts";
import { listResources } from "@lib/marka/index.ts";
import { ReviewResource } from "@lib/marka/schema.ts";
import { define } from "../../../utils.ts";
async function processUpdateRecommendations(
streamResponse: ReturnType<typeof createStreamResponse>,
@@ -53,8 +53,8 @@ async function processUpdateRecommendations(
streamResponse.info("100% Finished");
}
export const handler: Handlers = {
GET(_, ctx) {
export const handler = define.handlers({
GET(ctx) {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
@@ -65,4 +65,4 @@ export const handler: Handlers = {
return streamResponse.response;
},
};
});

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { AccessDeniedError } from "@lib/errors.ts";
import { getAllRecommendations } from "@lib/recommendation.ts";
import { json } from "@lib/helpers.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
@@ -34,4 +34,4 @@ export const handler: Handlers = {
keywords,
});
},
};
});

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { getAllRecommendations } from "@lib/recommendation.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
export const handler = define.handlers({
async GET() {
const recommendations = await getAllRecommendations();
return json(recommendations);
},
};
});

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { AccessDeniedError } from "@lib/errors.ts";
import { getSimilarMovies } from "@lib/recommendation.ts";
import { json } from "@lib/helpers.ts";
import { define } from "../../../../utils.ts";
export const handler: Handlers = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
@@ -14,4 +14,4 @@ export const handler: Handlers = {
return json(recommendations);
},
};
});

View File

@@ -1,12 +1,16 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import * as tmdb from "@lib/tmdb.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import { formatDate, isString, safeFileName } from "@lib/string.ts";
import {
fileExtension,
formatDate,
isString,
safeFileName,
} from "@lib/string.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { createResource, fetchResource } from "@lib/marka/index.ts";
import { ReviewResource } from "@lib/marka/schema.ts";
import { toUrlSafeString } from "@lib/string.ts";
import { define } from "../../../utils.ts";
function pickDirector(
credits: Awaited<ReturnType<typeof tmdb.getSeriesCredits>>,
@@ -16,12 +20,12 @@ function pickDirector(
return crewDirector?.name ?? createdBy?.[0]?.name;
}
export const handler: Handlers = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const series = await fetchResource(`series/${ctx.params.name}`);
return json(series);
},
async POST(_, ctx) {
async POST(ctx) {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
@@ -78,4 +82,4 @@ export const handler: Handlers = {
return json({ name: fileName });
},
};
});

View File

@@ -1,7 +1,5 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import * as tmdb from "@lib/tmdb.ts";
import { safeFileName } from "@lib/string.ts";
import { fileExtension, safeFileName } from "@lib/string.ts";
import { json } from "@lib/helpers.ts";
import {
AccessDeniedError,
@@ -9,74 +7,72 @@ import {
NotFoundError,
} from "@lib/errors.ts";
import { createResource, fetchResource } from "@lib/marka/index.ts";
import { define } from "../../../../utils.ts";
const isString = (input: string | undefined): input is string => {
return typeof input === "string";
};
const POST = async (
req: Request,
ctx: FreshContext,
): Promise<Response> => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
export const handler = define.handlers({
POST: async (ctx) => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const body = await req.json();
const name = ctx.params.name;
const { tmdbId } = body;
if (!name || !tmdbId) {
throw new BadRequestError();
}
const body = await ctx.req.json();
const name = ctx.params.name;
const { tmdbId } = body;
if (!name || !tmdbId) {
throw new BadRequestError();
}
const series = await fetchResource(`series/${ctx.params.name}`);
if (!series) {
throw new NotFoundError();
}
const series = await fetchResource(`series/${ctx.params.name}`);
if (!series) {
throw new NotFoundError();
}
const seriesDetails = await tmdb.getSeries(tmdbId);
const seriesCredits = !series?.content?.author &&
await tmdb.getSeriesCredits(tmdbId);
const seriesDetails = await tmdb.getSeries(tmdbId);
const seriesCredits = !series?.content?.author &&
await tmdb.getSeriesCredits(tmdbId);
const releaseDate = seriesDetails.first_air_date;
if (releaseDate && series.content?.datePublished) {
series.content.datePublished = new Date(releaseDate).toISOString();
}
const posterPath = seriesDetails.poster_path;
const director = seriesCredits &&
seriesCredits.crew?.filter?.((person) => person.job === "Director")[0] ||
seriesDetails?.created_by?.[0];
if (director && director.name && !series.content?.author) {
series.content.author = series.content.author || {
_type: "Person",
name: director.name,
};
}
const releaseDate = seriesDetails.first_air_date;
if (releaseDate && series.content?.datePublished) {
series.content.datePublished = new Date(releaseDate).toISOString();
}
const posterPath = seriesDetails.poster_path;
const director = seriesCredits &&
seriesCredits.crew?.filter?.((person) =>
person.job === "Director"
)[0] ||
seriesDetails?.created_by?.[0];
if (director && director.name && !series.content?.author) {
series.content.author = series.content.author || {
_type: "Person",
name: director.name,
};
}
if (seriesDetails.genres) {
series.content.keywords = [
...new Set([
...(series.content.keywords?.map((t) => t.toLowerCase()) || []),
...seriesDetails.genres.map((g) => g.name?.toLowerCase()),
].filter(isString)),
];
}
if (seriesDetails.genres) {
series.content.keywords = [
...new Set([
...(series.content.keywords?.map((t) => t.toLowerCase()) || []),
...seriesDetails.genres.map((g) => g.name?.toLowerCase()),
].filter(isString)),
];
}
let finalPath = "";
if (posterPath && !series.content?.image) {
const poster = await tmdb.getMoviePoster(posterPath);
const extension = fileExtension(posterPath);
let finalPath = "";
if (posterPath && !series.content?.image) {
const poster = await tmdb.getMoviePoster(posterPath);
const extension = fileExtension(posterPath);
finalPath = `series/images/${safeFileName(name)}_cover.${extension}`;
await createResource(finalPath, poster);
series.content.image = finalPath;
}
await createResource(`series/${safeFileName(series.name)}.md`, series);
finalPath = `series/images/${safeFileName(name)}_cover.${extension}`;
await createResource(finalPath, poster);
series.content.image = finalPath;
}
await createResource(`series/${safeFileName(series.name)}.md`, series);
return json(series);
};
export const handler: Handlers = {
POST,
};
return json(series);
},
});

View File

@@ -1,10 +1,10 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/marka/index.ts";
import { define } from "../../../utils.ts";
export const handler: Handlers = {
export const handler = define.handlers({
async GET() {
const series = await fetchResource("series");
return json(series);
},
};
});

View File

@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { getMovie } from "@lib/tmdb.ts";
import { json } from "@lib/helpers.ts";
import { createCache } from "@lib/cache.ts";
import { define } from "../../../utils.ts";
type CachedMovieCredits = {
lastUpdated: number;
@@ -13,40 +13,36 @@ const cache = createCache<CachedMovieCredits>("movie-credits", {
expires: CACHE_INTERVAL,
});
const GET = async (
_req: Request,
_ctx: FreshContext,
) => {
const id = _ctx.params.id;
export const handler = define.handlers({
GET: async (ctx) => {
const id = ctx.params.id;
if (!id) {
return new Response("Bad Request", {
status: 400,
});
}
if (!id) {
return new Response("Bad Request", {
status: 400,
});
}
const cacheId = `/movie/${id}`;
const cacheId = `/movie/${id}`;
const cachedResponse = cache.get(cacheId);
if (
cachedResponse && Date.now() < (cachedResponse.lastUpdated + CACHE_INTERVAL)
) {
return json(cachedResponse.data);
}
const cachedResponse = cache.get(cacheId);
if (
cachedResponse &&
Date.now() < (cachedResponse.lastUpdated + CACHE_INTERVAL)
) {
return json(cachedResponse.data);
}
const res = await getMovie(+id);
const res = await getMovie(+id);
cache.set(
cacheId,
JSON.stringify({
lastUpdated: Date.now(),
data: res,
}),
);
cache.set(
cacheId,
JSON.stringify({
lastUpdated: Date.now(),
data: res,
}),
);
return json(res);
};
export const handler: Handlers = {
GET,
};
return json(res);
},
});

View File

@@ -1,8 +1,8 @@
import { FreshContext } from "$fresh/server.ts";
import { getMovieCredits } from "@lib/tmdb.ts";
import { json } from "@lib/helpers.ts";
import { createLogger } from "@lib/log/index.ts";
import { createCache } from "@lib/cache.ts";
import { define } from "../../../../utils.ts";
type CachedMovieCredits = {
lastUpdated: number;
@@ -16,37 +16,37 @@ const cache = createCache<CachedMovieCredits>("movie-credits", {
const log = createLogger("api/tmdb");
export const handler = async (
_req: Request,
_ctx: FreshContext,
) => {
const id = _ctx.params.id;
export const handler = define.handlers({
GET: async (ctx) => {
const id = ctx.params.id;
if (!id) {
return new Response("Bad Request", {
status: 400,
});
}
if (!id) {
return new Response("Bad Request", {
status: 400,
});
}
log.debug("getting movie credits");
log.debug("getting movie credits");
const cacheId = `/movie/credits/${id}`;
const cacheId = `/movie/credits/${id}`;
const cachedResponse = cache.get(cacheId);
if (
cachedResponse && Date.now() < (cachedResponse.lastUpdated + CACHE_INTERVAL)
) {
return json(cachedResponse.data);
}
const cachedResponse = cache.get(cacheId);
if (
cachedResponse &&
Date.now() < (cachedResponse.lastUpdated + CACHE_INTERVAL)
) {
return json(cachedResponse.data);
}
const res = await getMovieCredits(+id);
cache.set(
cacheId,
JSON.stringify({
lastUpdated: Date.now(),
data: res,
}),
);
const res = await getMovieCredits(+id);
cache.set(
cacheId,
JSON.stringify({
lastUpdated: Date.now(),
data: res,
}),
);
return json(res);
};
return json(res);
},
});

View File

@@ -1,33 +1,28 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { searchMovie, searchTVShow } from "@lib/tmdb.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { define } from "../../../utils.ts";
const GET = async (
req: Request,
ctx: FreshContext,
) => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
export const handler = define.handlers({
GET: async (ctx) => {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const u = new URL(req.url);
const u = new URL(ctx.req.url);
const query = u.searchParams.get("q");
const query = u.searchParams.get("q");
if (!query) {
throw new BadRequestError();
}
if (!query) {
throw new BadRequestError();
}
const type = u.searchParams.get("type") || "movies";
const type = u.searchParams.get("type") || "movies";
const res = type === "movies"
? await searchMovie(query)
: await searchTVShow(query);
const res = type === "movies"
? await searchMovie(query)
: await searchTVShow(query);
return new Response(JSON.stringify(res.results));
};
export const handler: Handlers = {
GET,
};
return new Response(JSON.stringify(res.results));
},
});

View File

@@ -1,4 +1,4 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { MainLayout } from "@components/layouts/main.tsx";
import { KMenu } from "@islands/KMenu.tsx";
import { YoutubePlayer } from "@components/Youtube.tsx";
@@ -12,19 +12,20 @@ import { MetaTags } from "@components/MetaTags.tsx";
import { fetchResource } from "@lib/marka/index.ts";
import { ArticleResource } from "@lib/marka/schema.ts";
import { parseRating } from "@lib/helpers.ts";
import { HttpError } from "fresh";
import { define } from "../../utils.ts";
export const handler: Handlers<{ article: ArticleResource; session: unknown }> =
{
async GET(_, ctx) {
const article = await fetchResource<ArticleResource>(
`articles/${ctx.params.name}.md`,
);
if (!article) {
return ctx.renderNotFound();
}
return ctx.render({ article, session: ctx.state.session });
},
};
export const handler = define.handlers({
async GET(ctx) {
const article = await fetchResource<ArticleResource>(
`articles/${ctx.params.name}.md`,
);
if (!article) {
throw new HttpError(404);
}
return { data: { article, session: ctx.state.session } };
},
});
export default function Greet(
props: PageProps<

View File

@@ -1,28 +1,28 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { MainLayout } from "@components/layouts/main.tsx";
import { type ArticleResource, GenericResource } from "@lib/marka/schema.ts";
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 { ResourceCard } from "@components/Card.tsx";
import { Link } from "@islands/Link.tsx";
import { listResources } from "@lib/marka/index.ts";
import { define } from "../../utils.ts";
import { TbArrowLeft } from "@preact-icons/tb";
export const handler: Handlers<
{ articles: ArticleResource[] | null; searchResults?: GenericResource[] }
> = {
async GET(req, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const req = ctx.req;
const articles = await listResources<ArticleResource>("articles");
const searchParams = parseResourceUrl(req.url);
const searchResults = searchParams &&
await searchResource({ ...searchParams, types: ["articles"] });
return ctx.render({ articles, searchResults });
return { data: { articles, searchResults } };
},
};
});
export default function Greet(
export default define.page(function Greet(
props: PageProps<
{ articles: ArticleResource[] | null; searchResults: GenericResource[] }
>,
@@ -40,7 +40,7 @@ export default function Greet(
class="px-4 ml-4 py-2 bg-gray-300 text-gray-800 rounded-lg flex items-center gap-1"
href="/"
>
<IconArrowLeft class="w-5 h-5" />
<TbArrowLeft class="w-5 h-5" />
Back
</Link>
@@ -59,4 +59,4 @@ export default function Greet(
</Grid>
</MainLayout>
);
}
});

View File

@@ -1,6 +1,6 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { Card } from "@components/Card.tsx";
import { PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { resources } from "@lib/resources.ts";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { KMenu } from "@islands/KMenu.tsx";
@@ -16,7 +16,6 @@ export default function Home(props: PageProps) {
{Object.values(resources).filter((v) => v.link !== "/").map((m) => {
return (
<Card
splotch
key={m.link}
title={`${m.name}`}
backgroundSize={80}

View File

@@ -1,4 +1,3 @@
import { PageProps, RouteContext } from "$fresh/server.ts";
import { MainLayout } from "@components/layouts/main.tsx";
import { ReviewResource } from "@lib/marka/schema.ts";
import { removeImage, renderMarkdown } from "@lib/markdown.ts";
@@ -10,18 +9,18 @@ import { Star } from "@components/Stars.tsx";
import { MetaTags } from "@components/MetaTags.tsx";
import { parseRating } from "@lib/helpers.ts";
import { fetchResource } from "@lib/marka/index.ts";
import { HttpError } from "fresh";
import { define } from "../../utils.ts";
export default async function Greet(
props: PageProps<{ movie: ReviewResource; session: Record<string, string> }>,
ctx: RouteContext,
) {
export default define.page(async function (ctx) {
const props = ctx.req;
const movie = await fetchResource<ReviewResource>(
`movies/${ctx.params.name}.md`,
);
const session = ctx.state.session;
if (!movie) {
return ctx.renderNotFound();
throw new HttpError(404);
}
const { author, datePublished, reviewBody = "", reviewRating } =
@@ -87,4 +86,4 @@ export default async function Greet(
</div>
</MainLayout>
);
}
});

View File

@@ -2,13 +2,13 @@ import { MainLayout } from "@components/layouts/main.tsx";
import { GenericResource, ReviewResource } from "@lib/marka/schema.ts";
import { ResourceCard } from "@components/Card.tsx";
import { Grid } from "@components/Grid.tsx";
import { IconArrowLeft } from "@components/icons.tsx";
import { KMenu } from "@islands/KMenu.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { listResources } from "@lib/marka/index.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { parseRating } from "@lib/helpers.ts";
import { TbArrowLeft } from "@preact-icons/tb";
function sortOptional(a: number | string = 0, b: number | string = 0) {
return (parseRating(a) > parseRating(b)) ? 1 : -1;
@@ -44,7 +44,7 @@ export default async function MovieIndex(
class="px-4 ml-4 py-2 bg-gray-300 text-gray-800 rounded-lg flex items-center gap-1"
href="/"
>
<IconArrowLeft class="w-5 h-5" />
{TbArrowLeft({ class: "w-5 h-5" })}
Back
</a>

View File

@@ -1,4 +1,4 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { IngredientsList } from "@islands/IngredientsList.tsx";
import { MainLayout } from "@components/layouts/main.tsx";
import Counter from "@islands/Counter.tsx";
@@ -14,24 +14,24 @@ import { fetchResource } from "@lib/marka/index.ts";
import { RecipeResource } from "@lib/marka/schema.ts";
import { parseIngredients } from "@lib/parseIngredient.ts";
import { parseRating } from "@lib/helpers.ts";
import { HttpError } from "fresh";
import { define } from "../../utils.ts";
export const handler: Handlers<
{ recipe: RecipeResource; session: unknown } | null
> = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
try {
const recipe = await fetchResource<RecipeResource>(
`recipes/${ctx.params.name}.md`,
);
if (!recipe) {
return ctx.renderNotFound();
throw new HttpError(404);
}
return ctx.render({ recipe, session: ctx.state.session });
return { data: { recipe, session: ctx.state.session } };
} catch (_e) {
return ctx.renderNotFound();
throw new HttpError(404);
}
},
};
});
function ValidRecipe({
recipe,
@@ -48,11 +48,13 @@ function ValidRecipe({
<h3 class="text-3xl my-5">Ingredients</h3>
{portion && <Counter count={amount} />}
</div>
<IngredientsList
ingredients={ingredients}
amount={amount}
portion={portion}
/>
{
<IngredientsList
ingredients={ingredients}
amount={amount}
portion={portion}
/>
}
<h3 class="text-3xl my-5">Preparation</h3>
<div class="pl-2">
<ol class="list-decimal grid gap-4">
@@ -135,7 +137,7 @@ export default function Page(
)
: (
<div class="whitespace-break-spaces markdown-body">
{JSON.stringify(recipe)}
{recipe}
</div>
)}
</div>

View File

@@ -1,7 +1,7 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { Context, PageProps } from "fresh";
import { MainLayout } from "@components/layouts/main.tsx";
import { Grid } from "@components/Grid.tsx";
import { IconArrowLeft } from "@components/icons.tsx";
import { TbArrowLeft } from "@preact-icons/tb";
import { KMenu } from "@islands/KMenu.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { ResourceCard } from "@components/Card.tsx";
@@ -9,27 +9,27 @@ import { listResources } from "@lib/marka/index.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { GenericResource, RecipeResource } from "@lib/marka/schema.ts";
export const handler: Handlers<
{ recipes: RecipeResource[] | null; searchResults?: GenericResource[] }
> = {
async GET(req, ctx) {
export const handler = {
async GET(ctx: Context<{ test: number }>) {
const req = ctx.req;
const recipes = await listResources<RecipeResource>("recipes");
const searchParams = parseResourceUrl(req.url);
const searchResults = searchParams &&
await searchResource({ ...searchParams, types: ["recipes"] });
return ctx.render({ recipes, searchResults });
return { data: { recipes, searchResults } };
},
};
export default function Greet(
props: PageProps<
{ recipes: RecipeResource[] | null; searchResults: GenericResource[] }
>,
export default function Page(
{ data, url }: PageProps<{
recipes: RecipeResource[] | null;
searchResults: GenericResource[];
}>,
) {
const { recipes, searchResults } = props.data;
const { recipes, searchResults } = data;
return (
<MainLayout
url={props.url}
url={url}
title="Recipes"
searchResults={searchResults}
context={{ type: "recipes" }}
@@ -41,7 +41,7 @@ export default function Greet(
class="px-4 lg:ml-4 py-2 bg-gray-300 text-gray-800 rounded-lg flex items-center gap-1"
href="/"
>
<IconArrowLeft class="w-5 h-5" />
<TbArrowLeft class="w-5 h-5" />
Back
</a>

View File

@@ -1,4 +1,4 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { MainLayout } from "@components/layouts/main.tsx";
import { HashTags } from "@components/HashTags.tsx";
import { removeImage, renderMarkdown } from "@lib/markdown.ts";
@@ -9,20 +9,22 @@ import { Star } from "@components/Stars.tsx";
import { MetaTags } from "@components/MetaTags.tsx";
import { parseRating } from "@lib/helpers.ts";
import { fetchResource } from "@lib/marka/index.ts";
import { getNameOfResource, ReviewResource } from "@lib/marka/schema.ts";
import { ReviewResource } from "@lib/marka/schema.ts";
import { HttpError } from "fresh";
import { define } from "../../utils.ts";
export const handler: Handlers<{ serie: ReviewResource; session: unknown }> = {
async GET(_, ctx) {
export const handler = define.handlers({
async GET(ctx) {
const serie = await fetchResource<ReviewResource>(
`series/${ctx.params.name}.md`,
);
if (!serie) {
return ctx.renderNotFound();
throw new HttpError(404);
}
return ctx.render({ serie, session: ctx.state.session });
return { data: { serie, session: ctx.state.session } };
},
};
});
export default function Greet(
props: PageProps<{ serie: ReviewResource; session: Record<string, string> }>,

View File

@@ -1,25 +1,28 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { PageProps } from "fresh";
import { MainLayout } from "@components/layouts/main.tsx";
import { Grid } from "@components/Grid.tsx";
import { IconArrowLeft } from "@components/icons.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { KMenu } from "@islands/KMenu.tsx";
import { ResourceCard } from "@components/Card.tsx";
import { listResources } from "@lib/marka/index.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { GenericResource, ReviewResource } from "@lib/marka/schema.ts";
import { define } from "../../utils.ts";
import { TbArrowLeft } from "@preact-icons/tb";
export const handler: Handlers<
{ series: ReviewResource[] | null; searchResults?: GenericResource[] }
> = {
async GET(req, ctx) {
// : <
// { series: ReviewResource[] | null; searchResults?: GenericResource[] }
// >
export const handler = define.handlers({
async GET(ctx) {
const req = ctx.req;
const series = await listResources<ReviewResource>("series");
const searchParams = parseResourceUrl(req.url);
const searchResults = searchParams &&
await searchResource({ ...searchParams, types: ["series"] });
return ctx.render({ series, searchResults });
return { data: { series, searchResults } };
},
};
});
export default function Greet(
props: PageProps<
@@ -42,7 +45,7 @@ export default function Greet(
class="px-4 ml-4 py-2 bg-gray-300 text-gray-800 rounded-lg flex items-center gap-1"
href="/"
>
<IconArrowLeft class="w-5 h-5" />
<TbArrowLeft class="w-5 h-5" />
Back
</a>