Now sending webhooks to both the webserver and meili

This commit is contained in:
DrMint 2024-07-14 09:13:28 +02:00
parent dfbf3c9840
commit e2cd4a9388
4 changed files with 23 additions and 13 deletions

View File

@ -13,8 +13,11 @@ SEEDING_ADMIN_USERNAME=admin_name
SEEDING_ADMIN_EMAIL=email@domain.com SEEDING_ADMIN_EMAIL=email@domain.com
SEEDING_ADMIN_PASSWORD=somepassword SEEDING_ADMIN_PASSWORD=somepassword
WEB_HOOK_TOKEN=webhooktoken5e6ea45ef4e66eaa151612bdcb599df WEB_SERVER_HOOK_TOKEN=webhooktoken5e6ea45ef4e66eaa151612bdcb599df
WEB_HOOK_URI=https://accords-library.com/some/path WEB_SERVER_HOOK_URL=https://accords-library.com/some/path
MEILISEARCH_HOOK_TOKEN=webhooktoken5e6ea45ef4e66eaa151612bdcb599df
MEILISEARCH_HOOK_URL=https://meili.domain.com
SFTP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nxxxxxxxxxx..." SFTP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nxxxxxxxxxx..."
SFTP_USERNAME=someuser SFTP_USERNAME=someuser

View File

@ -68,14 +68,21 @@ export const afterDeleteWebhook: AfterDeleteHook = async ({ collection, doc }) =
}; };
const sendWebhookMessage = async (message: AfterOperationWebHookMessage) => { const sendWebhookMessage = async (message: AfterOperationWebHookMessage) => {
await fetch(`${process.env.WEB_HOOK_URI}/collection-operation`, { try {
await Promise.all(
[process.env.WEB_SERVER_HOOK_URL, process.env.MEILISEARCH_HOOK_URL].flatMap((url) => {
if (!url) return;
return fetch(url, {
headers: { headers: {
Authorization: `Bearer ${process.env.WEB_HOOK_TOKEN}`, Authorization: `Bearer ${process.env.WEB_SERVER_HOOK_TOKEN}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify(message), body: JSON.stringify(message),
method: "POST", method: "POST",
}).catch((e) => {
console.warn("Error while sending webhook", e);
}); });
})
);
} catch (e) {
console.warn("Error while sending webhook", e);
}
}; };

@ -1 +1 @@
Subproject commit 47c990080173a2330f0c7a9837dac34dba4e0811 Subproject commit 824f7085f9e0787f97ef9afd11cb5320a2cd6208

View File

@ -6,7 +6,7 @@ export const shortenEllipsis = (text: string, length: number): string =>
text.length - 3 > length ? `${text.substring(0, length)}...` : text; text.length - 3 > length ? `${text.substring(0, length)}...` : text;
export const formatLanguageCode = (code: string): string => export const formatLanguageCode = (code: string): string =>
tags(code).valid() ? tags(code).language()?.descriptions()[0] ?? code : code; tags(code).valid() ? (tags(code).language()?.descriptions()[0] ?? code) : code;
export const capitalize = (string: string): string => { export const capitalize = (string: string): string => {
const [firstLetter, ...otherLetters] = string; const [firstLetter, ...otherLetters] = string;