feat: move some stuff around

This commit is contained in:
2023-08-01 18:35:35 +02:00
parent c5cf629482
commit e51667bbac
9 changed files with 97 additions and 63 deletions

9
routes/api/cache/index.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import { Handlers } from "$fresh/server.ts";
import * as cache from "@lib/cache/cache.ts";
export const handler: Handlers = {
async DELETE() {
await cache.clearAll();
return new Response("OK");
},
};

View File

@ -126,14 +126,20 @@ const GET = async (
console.log("[api/image] resized image", { imageUrl });
cache.setImage(modifiedImage, {
await cache.setImage(modifiedImage, {
url: imageUrl,
width: params.width,
height: params.height,
mediaType: remoteImage.mediaType,
});
return new Response(modifiedImage, {
const cachedImage = await cache.getImage({
url: imageUrl,
width: params.width,
height: params.height,
});
return new Response(cachedImage.data || modifiedImage, {
headers: {
"Content-Type": remoteImage.mediaType,
},

View File

@ -18,40 +18,37 @@ async function updateMovieMetadata(
) {
const docId = `Media/movies/${name}.md`;
const currentDoc = await getDocument(docId);
let currentDoc = await getDocument(docId);
if (!currentDoc) return;
if (!currentDoc.startsWith("---\n---\n")) {
currentDoc = `---\n---\n\n${currentDoc}`;
}
const newDoc = transformDocument(currentDoc, (root) => {
const frontmatterNode = root.children.find((c) => c.type === "yaml");
const frontmatter = frontmatterNode?.value as string;
if (frontmatter) {
const value = parse(frontmatter) as Movie["meta"];
const value = parse(frontmatter) as Movie["meta"];
if (metadata.author && !value.author) {
value.author = metadata.author;
}
const newValue = {
...metadata,
date: formatDate(metadata.date),
...value,
};
if (metadata.image && !value.image) {
value.image = metadata.image;
}
if (metadata.date && !value.date) {
value.date = formatDate(metadata.date);
}
frontmatterNode.value = stringify(value);
}
frontmatterNode.value = stringify(newValue);
return root;
});
const response = await createDocument(docId, newDoc);
console.log({ newDoc });
return response;
return createDocument(docId, newDoc);
}
const GET = async (
const POST = async (
_req: Request,
_ctx: HandlerContext,
): Promise<Response> => {
@ -99,5 +96,5 @@ const GET = async (
};
export const handler: Handlers = {
GET,
POST,
};

View File