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 = {
|
||||
"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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user