diff --git a/.env.example b/.env.example index aa808a3..35ea40d 100644 --- a/.env.example +++ b/.env.example @@ -13,8 +13,11 @@ SEEDING_ADMIN_USERNAME=admin_name SEEDING_ADMIN_EMAIL=email@domain.com SEEDING_ADMIN_PASSWORD=somepassword -WEB_HOOK_TOKEN=webhooktoken5e6ea45ef4e66eaa151612bdcb599df -WEB_HOOK_URI=https://accords-library.com/some/path +WEB_SERVER_HOOK_TOKEN=webhooktoken5e6ea45ef4e66eaa151612bdcb599df +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_USERNAME=someuser diff --git a/src/hooks/afterOperationWebhook.ts b/src/hooks/afterOperationWebhook.ts index 449b63d..ab10d8d 100644 --- a/src/hooks/afterOperationWebhook.ts +++ b/src/hooks/afterOperationWebhook.ts @@ -68,14 +68,21 @@ export const afterDeleteWebhook: AfterDeleteHook = async ({ collection, doc }) = }; const sendWebhookMessage = async (message: AfterOperationWebHookMessage) => { - await fetch(`${process.env.WEB_HOOK_URI}/collection-operation`, { - headers: { - Authorization: `Bearer ${process.env.WEB_HOOK_TOKEN}`, - "Content-Type": "application/json", - }, - body: JSON.stringify(message), - method: "POST", - }).catch((e) => { + try { + await Promise.all( + [process.env.WEB_SERVER_HOOK_URL, process.env.MEILISEARCH_HOOK_URL].flatMap((url) => { + if (!url) return; + return fetch(url, { + headers: { + Authorization: `Bearer ${process.env.WEB_SERVER_HOOK_TOKEN}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(message), + method: "POST", + }); + }) + ); + } catch (e) { console.warn("Error while sending webhook", e); - }); + } }; diff --git a/src/shared b/src/shared index 47c9900..824f708 160000 --- a/src/shared +++ b/src/shared @@ -1 +1 @@ -Subproject commit 47c990080173a2330f0c7a9837dac34dba4e0811 +Subproject commit 824f7085f9e0787f97ef9afd11cb5320a2cd6208 diff --git a/src/utils/string.ts b/src/utils/string.ts index 76088c1..642ab8c 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -6,7 +6,7 @@ export const shortenEllipsis = (text: string, length: number): string => text.length - 3 > length ? `${text.substring(0, length)}...` : text; 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 => { const [firstLetter, ...otherLetters] = string;