feat: move some stuff around
This commit is contained in:
9
routes/api/cache/index.ts
vendored
Normal file
9
routes/api/cache/index.ts
vendored
Normal 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");
|
||||
},
|
||||
};
|
@ -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,
|
||||
},
|
||||
|
@ -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,
|
||||
};
|
||||
|
0
routes/api/readable/index.ts
Normal file
0
routes/api/readable/index.ts
Normal file
Reference in New Issue
Block a user