feat: initial refactor to use marka as backend
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { getArticle } from "@lib/resource/articles.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { fetchResource } from "@lib/resources.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(_, ctx) {
|
||||
const article = await getArticle(ctx.params.name);
|
||||
const article = await fetchResource(`articles/${ctx.params.name}`);
|
||||
return json(article);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ 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 { Article, createArticle } from "@lib/resource/articles.ts";
|
||||
import { Article } from "@lib/resource/articles.ts";
|
||||
import { getYoutubeVideoDetails } from "@lib/youtube.ts";
|
||||
import {
|
||||
extractYoutubeId,
|
||||
@@ -170,7 +170,7 @@ async function processCreateArticle(
|
||||
|
||||
streamResponse.enqueue("writing to disk");
|
||||
|
||||
await createArticle(newArticle.id, newArticle);
|
||||
// await createArticle(newArticle.id, newArticle);
|
||||
|
||||
streamResponse.enqueue("id: " + newArticle.id);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ async function processCreateYoutubeVideo(
|
||||
|
||||
streamResponse.enqueue("creating article");
|
||||
|
||||
await createArticle(newArticle.id, newArticle);
|
||||
// await createArticle(newArticle.id, newArticle);
|
||||
|
||||
streamResponse.enqueue("finished");
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { getAllArticles } from "@lib/resource/articles.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { fetchResource } from "@lib/resources.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET() {
|
||||
const movies = await getAllArticles();
|
||||
return json(movies);
|
||||
const articles = await fetchResource("articles");
|
||||
return json(articles?.content);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
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/index.ts";
|
||||
import { isLocalImage } from "@lib/string.ts";
|
||||
|
||||
const log = createLogger("api/image");
|
||||
|
||||
@@ -64,11 +62,10 @@ function parseParams(reqUrl: URL): ImageParams | string {
|
||||
// Helper function to generate ETag
|
||||
async function generateETag(content: ArrayBuffer): Promise<string> {
|
||||
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
|
||||
return `"${
|
||||
Array.from(new Uint8Array(hashBuffer))
|
||||
.map((b) => b.toString(16).padStart(2, "0"))
|
||||
.join("")
|
||||
}"`;
|
||||
return `"${Array.from(new Uint8Array(hashBuffer))
|
||||
.map((b) => b.toString(16).padStart(2, "0"))
|
||||
.join("")
|
||||
}"`;
|
||||
}
|
||||
|
||||
async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
|
||||
@@ -83,8 +80,8 @@ async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
|
||||
});
|
||||
}
|
||||
|
||||
const imageUrl = isLocalImage(params.image)
|
||||
? `${SILVERBULLET_SERVER}/${params.image.replace(/^\//, "")}`
|
||||
const imageUrl = params.image.startsWith("resources")
|
||||
? `https://marka.max-richter.dev/${params.image.replace(/^\//, "")}`
|
||||
: params.image;
|
||||
|
||||
log.debug("Processing image request:", { imageUrl, params });
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { getDocuments } from "@lib/documents.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET() {
|
||||
const documents = await getDocuments();
|
||||
return json(documents);
|
||||
return json([]);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { createMovie, getMovie, Movie } from "@lib/resource/movies.ts";
|
||||
import { Movie } from "@lib/resource/movies.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 { isString, safeFileName } from "@lib/string.ts";
|
||||
import { createDocument } from "@lib/documents.ts";
|
||||
import { AccessDeniedError } from "@lib/errors.ts";
|
||||
import { fetchResource } from "@lib/resources.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(_, ctx) {
|
||||
const movie = await getMovie(ctx.params.name);
|
||||
return json(movie);
|
||||
const movie = await fetchResource(`movies/${ctx.params.name}`);
|
||||
return json(movie?.content);
|
||||
},
|
||||
async POST(_, ctx) {
|
||||
const session = ctx.state.session;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
import { createDocument } from "@lib/documents.ts";
|
||||
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
||||
import { createMovie, getMovie } from "@lib/resource/movies.ts";
|
||||
import * as tmdb from "@lib/tmdb.ts";
|
||||
import { isString, safeFileName } from "@lib/string.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
@@ -11,6 +9,7 @@ import {
|
||||
NotFoundError,
|
||||
} from "@lib/errors.ts";
|
||||
import { createRecommendationResource } from "@lib/recommendation.ts";
|
||||
import { fetchResource } from "@lib/resources.ts";
|
||||
|
||||
const POST = async (
|
||||
req: Request,
|
||||
@@ -21,7 +20,7 @@ const POST = async (
|
||||
throw new AccessDeniedError();
|
||||
}
|
||||
|
||||
const movie = await getMovie(ctx.params.name);
|
||||
const movie = await fetchResource(`movies/${ctx.params.name}`);
|
||||
if (!movie) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
@@ -72,12 +71,12 @@ const POST = async (
|
||||
const poster = await tmdb.getMoviePoster(posterPath);
|
||||
const extension = fileExtension(posterPath);
|
||||
finalPath = `Media/movies/images/${safeFileName(name)}_cover.${extension}`;
|
||||
await createDocument(finalPath, poster);
|
||||
// await createDocument(finalPath, poster);
|
||||
movie.meta = movie.meta || {};
|
||||
movie.meta.image = finalPath;
|
||||
}
|
||||
|
||||
await createMovie(movie.id, movie);
|
||||
// await createMovie(movie.id, movie);
|
||||
|
||||
createRecommendationResource(movie, movieDetails.overview);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { getAllMovies } from "@lib/resource/movies.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { fetchResource } from "@lib/resources.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET() {
|
||||
const movies = await getAllMovies();
|
||||
const movies = await fetchResource("movies");
|
||||
return json(movies);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { getRecipe } from "@lib/resource/recipes.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { fetchResource } from "@lib/resources.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(_, ctx) {
|
||||
const recipe = await getRecipe(ctx.params.name);
|
||||
const recipe = await fetchResource(`recipes/${ctx.params.name}`);
|
||||
return json(recipe);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@ 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/index.ts";
|
||||
import { createRecipe, Recipe } from "@lib/resource/recipes.ts";
|
||||
import recipeSchema, { isValidRecipe } from "@lib/recipeSchema.ts";
|
||||
import { 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";
|
||||
import { safeFileName } from "@lib/string.ts";
|
||||
import { createDocument } from "@lib/documents.ts";
|
||||
@@ -205,10 +205,10 @@ async function processCreateRecipeFromUrl(
|
||||
streamResponse.enqueue("downloading image");
|
||||
try {
|
||||
streamResponse.enqueue("downloading image");
|
||||
const res = await fetch(src);
|
||||
// const res = await fetch(src);
|
||||
streamResponse.enqueue("saving image");
|
||||
const buffer = await res.arrayBuffer();
|
||||
await createDocument(finalPath, buffer);
|
||||
// const buffer = await res.arrayBuffer();
|
||||
// await createDocument(finalPath, buffer);
|
||||
newRecipe.meta.image = finalPath;
|
||||
} catch (err) {
|
||||
console.log("Failed to save image", err);
|
||||
@@ -218,7 +218,7 @@ async function processCreateRecipeFromUrl(
|
||||
|
||||
streamResponse.enqueue("finished processing, creating file");
|
||||
|
||||
await createRecipe(newRecipe.id, newRecipe);
|
||||
// await createRecipe(newRecipe.id, newRecipe);
|
||||
|
||||
streamResponse.enqueue("id: " + newRecipe.id);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { getAllRecipes } from "@lib/resource/recipes.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { fetchResource } from "@lib/resources.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET() {
|
||||
const recipes = await getAllRecipes();
|
||||
const recipes = await fetchResource("recipes");
|
||||
return json(recipes);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { createStreamResponse } from "@lib/helpers.ts";
|
||||
import { getAllMovies, Movie } from "@lib/resource/movies.ts";
|
||||
import { Movie } from "@lib/resource/movies.ts";
|
||||
import * as tmdb from "@lib/tmdb.ts";
|
||||
import {
|
||||
createRecommendationResource,
|
||||
getRecommendation,
|
||||
} from "@lib/recommendation.ts";
|
||||
import { AccessDeniedError } from "@lib/errors.ts";
|
||||
import { fetchResource } from "@lib/resources.ts";
|
||||
|
||||
async function processUpdateRecommendations(
|
||||
streamResponse: ReturnType<typeof createStreamResponse>,
|
||||
) {
|
||||
const allMovies = await getAllMovies();
|
||||
const allMovies = await fetchResource("movies");
|
||||
|
||||
const movies = allMovies.filter((m) => {
|
||||
if (!m?.meta) return false;
|
||||
if (!m.meta.rating) return false;
|
||||
if (!m.meta.tmdbId) return false;
|
||||
const movies = allMovies?.content.filter((m) => {
|
||||
if (!m?.content) return false;
|
||||
if (!m.content.reviewRating) return false;
|
||||
if (!m.content.tmdbId) return false;
|
||||
return true;
|
||||
}) as Movie[];
|
||||
|
||||
|
||||
@@ -5,11 +5,12 @@ import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts"
|
||||
import { isString, safeFileName } from "@lib/string.ts";
|
||||
import { createDocument } from "@lib/documents.ts";
|
||||
import { AccessDeniedError } from "@lib/errors.ts";
|
||||
import { createSeries, getSeries, Series } from "@lib/resource/series.ts";
|
||||
import { Series } from "@lib/resource/series.ts";
|
||||
import { fetchResource } from "@lib/resources.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(_, ctx) {
|
||||
const series = await getSeries(ctx.params.name);
|
||||
const series = await fetchResource(`series/${ctx.params.name}`);
|
||||
return json(series);
|
||||
},
|
||||
async POST(_, ctx) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
BadRequestError,
|
||||
NotFoundError,
|
||||
} from "@lib/errors.ts";
|
||||
import { createSeries, getSeries } from "@lib/resource/series.ts";
|
||||
|
||||
const isString = (input: string | undefined): input is string => {
|
||||
return typeof input === "string";
|
||||
@@ -64,15 +63,15 @@ const POST = async (
|
||||
|
||||
let finalPath = "";
|
||||
if (posterPath && !series.meta?.image) {
|
||||
const poster = await tmdb.getMoviePoster(posterPath);
|
||||
// const poster = await tmdb.getMoviePoster(posterPath);
|
||||
const extension = fileExtension(posterPath);
|
||||
|
||||
finalPath = `Media/series/images/${safeFileName(name)}_cover.${extension}`;
|
||||
await createDocument(finalPath, poster);
|
||||
// await createDocument(finalPath, poster);
|
||||
series.meta = series.meta || {};
|
||||
series.meta.image = finalPath;
|
||||
}
|
||||
await createSeries(series.id, series);
|
||||
// await createSeries(series.id, series);
|
||||
|
||||
return json(series);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user