fix: dont import node:path in clientside components
This commit is contained in:
35
lib/marka.ts
Normal file
35
lib/marka.ts
Normal 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();
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import { MARKA_API_KEY } from "./env.ts";
|
|
||||||
|
|
||||||
export const resources = {
|
export const resources = {
|
||||||
"home": {
|
"home": {
|
||||||
emoji: "House with Garden.png",
|
emoji: "House with Garden.png",
|
||||||
@@ -32,38 +30,3 @@ export const resources = {
|
|||||||
prefix: "Media/series/",
|
prefix: "Media/series/",
|
||||||
},
|
},
|
||||||
} as const;
|
} 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();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Movie } from "@lib/resource/movies.ts";
|
|||||||
import { Article } from "@lib/resource/articles.ts";
|
import { Article } from "@lib/resource/articles.ts";
|
||||||
import { Recipe } from "@lib/resource/recipes.ts";
|
import { Recipe } from "@lib/resource/recipes.ts";
|
||||||
import { Series } from "@lib/resource/series.ts";
|
import { Series } from "@lib/resource/series.ts";
|
||||||
import { fetchResource } from "./resources.ts";
|
import { fetchResource } from "./marka.ts";
|
||||||
|
|
||||||
type ResourceType = keyof typeof resources;
|
type ResourceType = keyof typeof resources;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
async GET(_, ctx) {
|
async GET(_, ctx) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
toUrlSafeString,
|
toUrlSafeString,
|
||||||
} from "@lib/string.ts";
|
} from "@lib/string.ts";
|
||||||
import { createLogger } from "@lib/log/index.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";
|
import { webScrape } from "@lib/webScraper.ts";
|
||||||
|
|
||||||
const log = createLogger("api/article");
|
const log = createLogger("api/article");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
async GET() {
|
async GET() {
|
||||||
|
|||||||
@@ -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 { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
||||||
import { isString, safeFileName } from "@lib/string.ts";
|
import { isString, safeFileName } from "@lib/string.ts";
|
||||||
import { AccessDeniedError } from "@lib/errors.ts";
|
import { AccessDeniedError } from "@lib/errors.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
async GET(_, ctx) {
|
async GET(_, ctx) {
|
||||||
@@ -38,8 +38,7 @@ export const handler: Handlers = {
|
|||||||
const poster = await tmdb.getMoviePoster(posterPath);
|
const poster = await tmdb.getMoviePoster(posterPath);
|
||||||
const extension = fileExtension(posterPath);
|
const extension = fileExtension(posterPath);
|
||||||
|
|
||||||
finalPath = `Media/movies/images/${
|
finalPath = `Media/movies/images/${safeFileName(name)
|
||||||
safeFileName(name)
|
|
||||||
}_cover.${extension}`;
|
}_cover.${extension}`;
|
||||||
await createDocument(finalPath, poster);
|
await createDocument(finalPath, poster);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
NotFoundError,
|
NotFoundError,
|
||||||
} from "@lib/errors.ts";
|
} from "@lib/errors.ts";
|
||||||
import { createRecommendationResource } from "@lib/recommendation.ts";
|
import { createRecommendationResource } from "@lib/recommendation.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
const POST = async (
|
const POST = async (
|
||||||
req: Request,
|
req: Request,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
async GET() {
|
async GET() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
async GET(_, ctx) {
|
async GET(_, ctx) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { json } from "@lib/helpers.ts";
|
import { json } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
async GET() {
|
async GET() {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
getRecommendation,
|
getRecommendation,
|
||||||
} from "@lib/recommendation.ts";
|
} from "@lib/recommendation.ts";
|
||||||
import { AccessDeniedError } from "@lib/errors.ts";
|
import { AccessDeniedError } from "@lib/errors.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
async function processUpdateRecommendations(
|
async function processUpdateRecommendations(
|
||||||
streamResponse: ReturnType<typeof createStreamResponse>,
|
streamResponse: ReturnType<typeof createStreamResponse>,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { isString, safeFileName } from "@lib/string.ts";
|
|||||||
import { createDocument } from "@lib/documents.ts";
|
import { createDocument } from "@lib/documents.ts";
|
||||||
import { AccessDeniedError } from "@lib/errors.ts";
|
import { AccessDeniedError } from "@lib/errors.ts";
|
||||||
import { Series } from "@lib/resource/series.ts";
|
import { Series } from "@lib/resource/series.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
async GET(_, ctx) {
|
async GET(_, ctx) {
|
||||||
@@ -37,8 +37,7 @@ export const handler: Handlers = {
|
|||||||
const poster = await tmdb.getMoviePoster(posterPath);
|
const poster = await tmdb.getMoviePoster(posterPath);
|
||||||
const extension = fileExtension(posterPath);
|
const extension = fileExtension(posterPath);
|
||||||
|
|
||||||
finalPath = `Media/series/images/${
|
finalPath = `Media/series/images/${safeFileName(name)
|
||||||
safeFileName(name)
|
|
||||||
}_cover.${extension}`;
|
}_cover.${extension}`;
|
||||||
await createDocument(finalPath, poster);
|
await createDocument(finalPath, poster);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { RedirectSearchHandler } from "@islands/Search.tsx";
|
|||||||
import PageHero from "@components/PageHero.tsx";
|
import PageHero from "@components/PageHero.tsx";
|
||||||
import { Star } from "@components/Stars.tsx";
|
import { Star } from "@components/Stars.tsx";
|
||||||
import { MetaTags } from "@components/MetaTags.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 }> = {
|
export const handler: Handlers<{ article: Article; session: unknown }> = {
|
||||||
async GET(_, ctx) {
|
async GET(_, ctx) {
|
||||||
@@ -27,7 +27,7 @@ export default function Greet(
|
|||||||
) {
|
) {
|
||||||
const { article, session } = props.data;
|
const { article, session } = props.data;
|
||||||
|
|
||||||
const { author = "", date = "", articleBody = "" } = (article?.content || {});
|
const { author = "", date = "", articleBody = "" } = article?.content || {};
|
||||||
|
|
||||||
const content = renderMarkdown(
|
const content = renderMarkdown(
|
||||||
removeImage(articleBody, article.content.image),
|
removeImage(articleBody, article.content.image),
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
|||||||
import { GenericResource } from "@lib/types.ts";
|
import { GenericResource } from "@lib/types.ts";
|
||||||
import { ResourceCard } from "@components/Card.tsx";
|
import { ResourceCard } from "@components/Card.tsx";
|
||||||
import { Link } from "@islands/Link.tsx";
|
import { Link } from "@islands/Link.tsx";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
|
|
||||||
export const handler: Handlers<
|
export const handler: Handlers<
|
||||||
{ articles: Article[] | null; searchResults?: GenericResource[] }
|
{ articles: Article[] | null; searchResults?: GenericResource[] }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import PageHero from "@components/PageHero.tsx";
|
|||||||
import { Star } from "@components/Stars.tsx";
|
import { Star } from "@components/Stars.tsx";
|
||||||
import { MetaTags } from "@components/MetaTags.tsx";
|
import { MetaTags } from "@components/MetaTags.tsx";
|
||||||
import { parseRating } from "@lib/helpers.ts";
|
import { parseRating } from "@lib/helpers.ts";
|
||||||
import { fetchResource } from "@lib/resources.ts";
|
import { fetchResource } from "@lib/marka.ts";
|
||||||
|
|
||||||
export default async function Greet(
|
export default async function Greet(
|
||||||
props: PageProps<{ movie: Movie; session: Record<string, string> }>,
|
props: PageProps<{ movie: Movie; session: Record<string, string> }>,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { KMenu } from "@islands/KMenu.tsx";
|
|||||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||||
import { GenericResource } from "@lib/types.ts";
|
import { GenericResource } from "@lib/types.ts";
|
||||||
import { PageProps } from "$fresh/server.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";
|
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||||
|
|
||||||
export default async function Greet(
|
export default async function Greet(
|
||||||
@@ -20,7 +20,10 @@ export default async function Greet(
|
|||||||
const searchResults = searchParams &&
|
const searchResults = searchParams &&
|
||||||
await searchResource({ ...searchParams, types: ["movie"] });
|
await searchResource({ ...searchParams, types: ["movie"] });
|
||||||
const movies = allMovies.sort((a, b) =>
|
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 (
|
return (
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { Star } from "@components/Stars.tsx";
|
|||||||
import { renderMarkdown } from "@lib/documents.ts";
|
import { renderMarkdown } from "@lib/documents.ts";
|
||||||
import { isValidRecipe } from "@lib/recipeSchema.ts";
|
import { isValidRecipe } from "@lib/recipeSchema.ts";
|
||||||
import { MetaTags } from "@components/MetaTags.tsx";
|
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> = {
|
export const handler: Handlers<{ recipe: Recipe; session: unknown } | null> = {
|
||||||
async GET(_, ctx) {
|
async GET(_, ctx) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { KMenu } from "@islands/KMenu.tsx";
|
|||||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||||
import { GenericResource } from "@lib/types.ts";
|
import { GenericResource } from "@lib/types.ts";
|
||||||
import { ResourceCard } from "@components/Card.tsx";
|
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";
|
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||||
|
|
||||||
export const handler: Handlers<
|
export const handler: Handlers<
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import PageHero from "@components/PageHero.tsx";
|
|||||||
import { Star } from "@components/Stars.tsx";
|
import { Star } from "@components/Stars.tsx";
|
||||||
import { MetaTags } from "@components/MetaTags.tsx";
|
import { MetaTags } from "@components/MetaTags.tsx";
|
||||||
import { parseRating } from "@lib/helpers.ts";
|
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 }> = {
|
export const handler: Handlers<{ serie: Series; session: unknown }> = {
|
||||||
async GET(_, ctx) {
|
async GET(_, ctx) {
|
||||||
@@ -27,7 +27,7 @@ export default function Greet(
|
|||||||
) {
|
) {
|
||||||
const { serie, session } = props.data;
|
const { serie, session } = props.data;
|
||||||
|
|
||||||
const { author = "", date = "" } = (serie?.content || {});
|
const { author = "", date = "" } = serie?.content || {};
|
||||||
|
|
||||||
const content = renderMarkdown(
|
const content = renderMarkdown(
|
||||||
removeImage(serie.description || "", serie.content?.image),
|
removeImage(serie.description || "", serie.content?.image),
|
||||||
@@ -43,7 +43,10 @@ export default function Greet(
|
|||||||
<KMenu type="main" context={serie} />
|
<KMenu type="main" context={serie} />
|
||||||
|
|
||||||
<MetaTags resource={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.Header>
|
||||||
<PageHero.BackLink href="/series" />
|
<PageHero.BackLink href="/series" />
|
||||||
{session && (
|
{session && (
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { RedirectSearchHandler } from "@islands/Search.tsx";
|
|||||||
import { KMenu } from "@islands/KMenu.tsx";
|
import { KMenu } from "@islands/KMenu.tsx";
|
||||||
import { ResourceCard } from "@components/Card.tsx";
|
import { ResourceCard } from "@components/Card.tsx";
|
||||||
import { GenericResource } from "@lib/types.ts";
|
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";
|
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||||
|
|
||||||
export const handler: Handlers<
|
export const handler: Handlers<
|
||||||
|
|||||||
Reference in New Issue
Block a user