feat: correctly cache images with redis
This commit is contained in:
@@ -2,6 +2,7 @@ import { unified } from "npm:unified";
|
||||
import remarkParse from "npm:remark-parse";
|
||||
import remarkFrontmatter from "https://esm.sh/remark-frontmatter@4";
|
||||
import { parse } from "https://deno.land/std@0.194.0/yaml/mod.ts";
|
||||
import * as cache from "@lib/cache/documents.ts";
|
||||
|
||||
const SILVERBULLET_SERVER = Deno.env.get("SILVERBULLET_SERVER");
|
||||
|
||||
@@ -18,6 +19,9 @@ export function parseFrontmatter(yaml: string) {
|
||||
}
|
||||
|
||||
export async function getDocuments(): Promise<Document[]> {
|
||||
const cachedDocuments = await cache.getDocuments();
|
||||
if (cachedDocuments) return cachedDocuments;
|
||||
|
||||
const headers = new Headers();
|
||||
headers.append("Accept", "application/json");
|
||||
|
||||
@@ -25,12 +29,22 @@ export async function getDocuments(): Promise<Document[]> {
|
||||
headers: headers,
|
||||
});
|
||||
|
||||
return response.json();
|
||||
const documents = await response.json();
|
||||
cache.setDocuments(documents);
|
||||
|
||||
return documents;
|
||||
}
|
||||
|
||||
export async function getDocument(name: string): Promise<string> {
|
||||
const cachedDocument = await cache.getDocument(name);
|
||||
if (cachedDocument) return cachedDocument;
|
||||
|
||||
const response = await fetch(SILVERBULLET_SERVER + "/" + name);
|
||||
return await response.text();
|
||||
const text = await response.text();
|
||||
|
||||
cache.setDocument(name, text);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
export function parseDocument(doc: string) {
|
||||
|
||||
Reference in New Issue
Block a user