refactor(backend): split log files into separate file

This commit is contained in:
2025-01-19 16:43:00 +01:00
parent e9cc56d7ee
commit f106460502
24 changed files with 155 additions and 113 deletions

View File

@@ -5,9 +5,11 @@ export default function App({ Component }: PageProps) {
const globalCss = Deno
.readTextFileSync("./static/global.css")
.replaceAll("\n", "");
return (
<>
<Head>
<link rel="stylesheet" href="/prism-material-dark.css" />
<link rel="stylesheet" href="/styles.css" />
<link
rel="icon"

View File

@@ -1,13 +1,13 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { Handlers, PageProps } from "$fresh/server.ts";
import { AccessDeniedError } from "@lib/errors.ts";
import { getLogs, Log } from "@lib/logs.ts";
import { getLogs, Log } from "@lib/log/index.ts";
import { formatDate } from "@lib/string.ts";
import { renderMarkdown } from "@lib/documents.ts";
const renderLog = (t: unknown) =>
renderMarkdown(`\`\`\`js
${typeof t === "string" ? t : JSON.stringify(t).trim()}
${typeof t === "string" ? t : JSON.stringify(t, null, 2).trim()}
\`\`\``);
export const handler: Handlers = {
@@ -16,11 +16,12 @@ export const handler: Handlers = {
if (!("session" in ctx.state)) {
throw new AccessDeniedError();
}
console.log({ logs });
return ctx.render({
logs: logs.map((l) => {
return {
...l,
html: l.args.map(renderLog).join("\n"),
html: l.args.map(renderLog).join("<br/>"),
};
}),
});
@@ -34,7 +35,7 @@ function LogLine(
) {
return (
<div
class="mt-4 flex flex-col gap-2 bg-gray-900 px-4 py-2 rounded-2xl"
class="mt-4 flex flex-col gap-2 bg-gray-900 px-4 py-2 rounded-2xl max-w-3xl"
style={{ background: "var(--light)" }}
>
<div class="flex gap-2">
@@ -51,13 +52,9 @@ function LogLine(
</span>
</div>
<div
class="flex gap-1 text-white"
class="text-white"
dangerouslySetInnerHTML={{ __html: log.html }}
>
<pre>
{log.html}
</pre>
</div>
/>
</div>
);
}
@@ -67,7 +64,7 @@ export default function Greet(
) {
return (
<MainLayout url={url}>
<h1 class="text-white text-4xl ">Performance</h1>
<h1 class="text-white text-4xl">Logs</h1>
{logs.map((r) => {
return (

View File

@@ -9,7 +9,7 @@ import tds from "https://cdn.skypack.dev/turndown@7.2.0";
import { Article, createArticle } from "@lib/resource/articles.ts";
import { getYoutubeVideoDetails } from "@lib/youtube.ts";
import { extractYoutubeId, isYoutubeLink } from "@lib/string.ts";
import { createLogger } from "@lib/log.ts";
import { createLogger } from "@lib/log/index.ts";
const parser = new DOMParser();

View File

@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { getImageContent } from "@lib/image.ts";
import { SILVERBULLET_SERVER } from "@lib/env.ts";
import { createLogger } from "@lib/log.ts";
import { createLogger } from "@lib/log/index.ts";
import { isLocalImage } from "@lib/string.ts";
const log = createLogger("api/image");

View File

@@ -5,7 +5,7 @@ import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { createStreamResponse, isValidUrl } from "@lib/helpers.ts";
import * as openai from "@lib/openai.ts";
import tds from "https://cdn.skypack.dev/turndown@7.2.0";
import { createLogger } from "@lib/log.ts";
import { createLogger } from "@lib/log/index.ts";
import { createRecipe, Recipe } from "@lib/resource/recipes.ts";
import recipeSchema from "@lib/recipeSchema.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
@@ -136,8 +136,8 @@ async function processCreateRecipeFromUrl(
const jsonLds = Array.from(
document?.querySelectorAll(
"script[type='application/ld+json']",
) as HTMLScriptElement[],
);
),
) as unknown as HTMLScriptElement[];
let recipe: z.infer<typeof recipeSchema> | undefined = undefined;
if (jsonLds.length > 0) {

View File

@@ -9,7 +9,9 @@ type CachedMovieCredits = {
};
const CACHE_INTERVAL = 1000 * 60 * 24 * 30;
const cache = createCache<CachedMovieCredits>({ expires: CACHE_INTERVAL });
const cache = createCache<CachedMovieCredits>("movie-credits", {
expires: CACHE_INTERVAL,
});
const GET = async (
_req: Request,

View File

@@ -1,7 +1,7 @@
import { FreshContext } from "$fresh/server.ts";
import { getMovieCredits } from "@lib/tmdb.ts";
import { json } from "@lib/helpers.ts";
import { createLogger } from "@lib/log.ts";
import { createLogger } from "@lib/log/index.ts";
import { createCache } from "@lib/cache.ts";
type CachedMovieCredits = {
@@ -10,7 +10,9 @@ type CachedMovieCredits = {
};
const CACHE_INTERVAL = 1000 * 60 * 24 * 30;
const cache = createCache<CachedMovieCredits>({ expires: CACHE_INTERVAL });
const cache = createCache<CachedMovieCredits>("movie-credits", {
expires: CACHE_INTERVAL,
});
const log = createLogger("api/tmdb");