cache public meilisearch key

This commit is contained in:
Christian Beutel
2025-09-12 16:45:50 +02:00
parent 3b7f30908c
commit 9c628c6511
2 changed files with 143 additions and 66 deletions

View File

@@ -48,6 +48,7 @@ function isFormContentType(request: Request) {
);
}
let publicMeilisearchKey: string | undefined = undefined;
const auth: Handle = async ({ event, resolve }) => {
const pb = new PocketBase(envPub.PUBLIC_POCKETBASE_URL)
@@ -84,8 +85,12 @@ const auth: Handle = async ({ event, resolve }) => {
settings = await pb.collection('settings').getFirstListItem<Settings>(`user="${pb.authStore.record.id}"`, { requestKey: null })
actor = await pb.collection("activitypub_actors").getFirstListItem(`user='${pb.authStore.record.id}'`)
} else {
const response = await pb.send("/public/search/token", { method: "GET", fetch: event.fetch });
meiliApiKey = response.token;
if (!publicMeilisearchKey) {
const response = await pb.send("/public/search/token", { method: "GET", fetch: event.fetch });
publicMeilisearchKey = response.token;
}
meiliApiKey = publicMeilisearchKey!;
}
const ms = new MeiliSearch({ host: env.MEILI_URL, apiKey: meiliApiKey });