Added webhook for currencies and language updates

This commit is contained in:
DrMint 2024-03-09 12:11:11 +01:00
parent b06c624d41
commit a847b73363
2 changed files with 16 additions and 5 deletions

View File

@ -1,6 +1,6 @@
---
import { Collections } from "src/shared/payload/payload-sdk";
import { refreshWordings } from "src/utils/cachedPayload";
import { refreshCurrencies, refreshLocales, refreshWordings } from "src/utils/cachedPayload";
const auth = Astro.request.headers.get("Authorization");
@ -15,6 +15,14 @@ switch (collectionSlug) {
await refreshWordings();
break;
case Collections.Currencies:
await refreshCurrencies();
break;
case Collections.Languages:
await refreshLocales()
break;
default:
return new Response(null, { status: 400, statusText: "Bad Request" });
}

View File

@ -18,7 +18,10 @@ export const refreshWordings = async () => {
cache.wordings = await payload.getWordings();
};
setInterval(async () => {
console.log("Refreshing cached Payload data");
cache = await fetchNewData();
}, 1000_000);
export const refreshCurrencies = async () => {
cache.currencies = (await payload.getCurrencies()).map(({ id }) => id)
};
export const refreshLocales = async () => {
cache.locales = await payload.getLanguages();
};