fix: dont import node:path in clientside components

This commit is contained in:
Max Richter
2025-10-31 15:41:46 +01:00
parent 7e60327940
commit 79d692c2c6
21 changed files with 68 additions and 67 deletions

35
lib/marka.ts Normal file
View File

@@ -0,0 +1,35 @@
import { MARKA_API_KEY } from "./env.ts";
const url = `https://marka.max-richter.dev/resources`;
//const url = "http://localhost:8080/resources";
export async function fetchResource(resource: string) {
try {
const response = await fetch(
`${url}/${resource}`,
);
return response.json();
} catch (_e) {
return [];
}
}
export async function createResource(
path: string,
content: string | object | ArrayBuffer,
) {
const isJson = typeof content === "object";
const fetchUrl = `${url}/${path}`;
console.log("Creating resource", { fetchUrl, content, isJson });
const response = await fetch(fetchUrl, {
method: "POST",
headers: {
"Content-Type": isJson ? "application/json" : "",
"Authentication": MARKA_API_KEY,
},
body: isJson ? JSON.stringify(content) : content,
});
if (!response.ok) {
throw new Error(`Failed to create resource: ${response.status}`);
}
return response.json();
}

View File

@@ -1,5 +1,3 @@
import { MARKA_API_KEY } from "./env.ts";
export const resources = {
"home": {
emoji: "House with Garden.png",
@@ -32,38 +30,3 @@ export const resources = {
prefix: "Media/series/",
},
} as const;
const url = `https://marka.max-richter.dev/resources`;
//const url = "http://localhost:8080/resources";
export async function fetchResource(resource: string) {
try {
const response = await fetch(
`${url}/${resource}`,
);
return response.json();
} catch (_e) {
return [];
}
}
export async function createResource(
path: string,
content: string | object | ArrayBuffer,
) {
const isJson = typeof content === "object";
const fetchUrl = `${url}/${path}`;
console.log("Creating resource", { fetchUrl, content, isJson });
const response = await fetch(fetchUrl, {
method: "POST",
headers: {
"Content-Type": isJson ? "application/json" : "",
"Authentication": MARKA_API_KEY,
},
body: isJson ? JSON.stringify(content) : content,
});
if (!response.ok) {
throw new Error(`Failed to create resource: ${response.status}`);
}
return response.json();
}

View File

@@ -6,7 +6,7 @@ import { Movie } from "@lib/resource/movies.ts";
import { Article } from "@lib/resource/articles.ts";
import { Recipe } from "@lib/resource/recipes.ts";
import { Series } from "@lib/resource/series.ts";
import { fetchResource } from "./resources.ts";
import { fetchResource } from "./marka.ts";
type ResourceType = keyof typeof resources;

View File

@@ -1,6 +1,6 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers = {
async GET(_, ctx) {

View File

@@ -12,7 +12,7 @@ import {
toUrlSafeString,
} from "@lib/string.ts";
import { createLogger } from "@lib/log/index.ts";
import { createResource } from "@lib/resources.ts";
import { createResource } from "@lib/marka.ts";
import { webScrape } from "@lib/webScraper.ts";
const log = createLogger("api/article");

View File

@@ -1,6 +1,6 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers = {
async GET() {

View File

@@ -5,7 +5,7 @@ import * as tmdb from "@lib/tmdb.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import { isString, safeFileName } from "@lib/string.ts";
import { AccessDeniedError } from "@lib/errors.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers = {
async GET(_, ctx) {
@@ -38,8 +38,7 @@ export const handler: Handlers = {
const poster = await tmdb.getMoviePoster(posterPath);
const extension = fileExtension(posterPath);
finalPath = `Media/movies/images/${
safeFileName(name)
finalPath = `Media/movies/images/${safeFileName(name)
}_cover.${extension}`;
await createDocument(finalPath, poster);
}

View File

@@ -9,7 +9,7 @@ import {
NotFoundError,
} from "@lib/errors.ts";
import { createRecommendationResource } from "@lib/recommendation.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
const POST = async (
req: Request,

View File

@@ -1,6 +1,6 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers = {
async GET() {

View File

@@ -1,6 +1,6 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers = {
async GET(_, ctx) {

View File

@@ -1,6 +1,6 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers = {
async GET() {

View File

@@ -7,7 +7,7 @@ import {
getRecommendation,
} from "@lib/recommendation.ts";
import { AccessDeniedError } from "@lib/errors.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
async function processUpdateRecommendations(
streamResponse: ReturnType<typeof createStreamResponse>,

View File

@@ -6,7 +6,7 @@ import { isString, safeFileName } from "@lib/string.ts";
import { createDocument } from "@lib/documents.ts";
import { AccessDeniedError } from "@lib/errors.ts";
import { Series } from "@lib/resource/series.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers = {
async GET(_, ctx) {
@@ -37,8 +37,7 @@ export const handler: Handlers = {
const poster = await tmdb.getMoviePoster(posterPath);
const extension = fileExtension(posterPath);
finalPath = `Media/series/images/${
safeFileName(name)
finalPath = `Media/series/images/${safeFileName(name)
}_cover.${extension}`;
await createDocument(finalPath, poster);
}

View File

@@ -10,7 +10,7 @@ import { RedirectSearchHandler } from "@islands/Search.tsx";
import PageHero from "@components/PageHero.tsx";
import { Star } from "@components/Stars.tsx";
import { MetaTags } from "@components/MetaTags.tsx";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers<{ article: Article; session: unknown }> = {
async GET(_, ctx) {
@@ -27,7 +27,7 @@ export default function Greet(
) {
const { article, session } = props.data;
const { author = "", date = "", articleBody = "" } = (article?.content || {});
const { author = "", date = "", articleBody = "" } = article?.content || {};
const content = renderMarkdown(
removeImage(articleBody, article.content.image),

View File

@@ -9,8 +9,7 @@ import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { GenericResource } from "@lib/types.ts";
import { ResourceCard } from "@components/Card.tsx";
import { Link } from "@islands/Link.tsx";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers<
{ articles: Article[] | null; searchResults?: GenericResource[] }

View File

@@ -9,7 +9,7 @@ import PageHero from "@components/PageHero.tsx";
import { Star } from "@components/Stars.tsx";
import { MetaTags } from "@components/MetaTags.tsx";
import { parseRating } from "@lib/helpers.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export default async function Greet(
props: PageProps<{ movie: Movie; session: Record<string, string> }>,

View File

@@ -7,7 +7,7 @@ import { KMenu } from "@islands/KMenu.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { GenericResource } from "@lib/types.ts";
import { PageProps } from "$fresh/server.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
export default async function Greet(
@@ -20,7 +20,10 @@ export default async function Greet(
const searchResults = searchParams &&
await searchResource({ ...searchParams, types: ["movie"] });
const movies = allMovies.sort((a, b) =>
a?.content?.reviewRating?.ratingValue > b?.content?.reviewRating?.ratingValue ? -1 : 1
a?.content?.reviewRating?.ratingValue >
b?.content?.reviewRating?.ratingValue
? -1
: 1
);
return (

View File

@@ -11,7 +11,7 @@ import { Star } from "@components/Stars.tsx";
import { renderMarkdown } from "@lib/documents.ts";
import { isValidRecipe } from "@lib/recipeSchema.ts";
import { MetaTags } from "@components/MetaTags.tsx";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers<{ recipe: Recipe; session: unknown } | null> = {
async GET(_, ctx) {

View File

@@ -7,7 +7,7 @@ import { KMenu } from "@islands/KMenu.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { GenericResource } from "@lib/types.ts";
import { ResourceCard } from "@components/Card.tsx";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
export const handler: Handlers<

View File

@@ -9,7 +9,7 @@ import PageHero from "@components/PageHero.tsx";
import { Star } from "@components/Stars.tsx";
import { MetaTags } from "@components/MetaTags.tsx";
import { parseRating } from "@lib/helpers.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
export const handler: Handlers<{ serie: Series; session: unknown }> = {
async GET(_, ctx) {
@@ -27,7 +27,7 @@ export default function Greet(
) {
const { serie, session } = props.data;
const { author = "", date = "" } = (serie?.content || {});
const { author = "", date = "" } = serie?.content || {};
const content = renderMarkdown(
removeImage(serie.description || "", serie.content?.image),
@@ -43,7 +43,10 @@ export default function Greet(
<KMenu type="main" context={serie} />
<MetaTags resource={serie} />
<PageHero image={serie.content?.image} thumbnail={serie.content?.thumbnail}>
<PageHero
image={serie.content?.image}
thumbnail={serie.content?.thumbnail}
>
<PageHero.Header>
<PageHero.BackLink href="/series" />
{session && (

View File

@@ -7,7 +7,7 @@ import { RedirectSearchHandler } from "@islands/Search.tsx";
import { KMenu } from "@islands/KMenu.tsx";
import { ResourceCard } from "@components/Card.tsx";
import { GenericResource } from "@lib/types.ts";
import { fetchResource } from "@lib/resources.ts";
import { fetchResource } from "@lib/marka.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
export const handler: Handlers<