diff --git a/.env.example b/.env.example index 75757ba6..30f2a1dd 100644 --- a/.env.example +++ b/.env.example @@ -70,4 +70,14 @@ DISCORD_WEBHOOK_CONTACT= # Some more random variables API_RATE_LIMIT=12 -API_CART_LIFESPAN=3600 \ No newline at end of file +API_CART_LIFESPAN=3600 + +# Base 64 encoded image for the badge template +BADGE_RESTRICTED= +BADGE_RESTRICTED_BACK= +BADGE_FULLACCESS= +BADGE_FULLACCESS_BACK= +BADGE_ORGAPRICE= +BADGE_ORGAPRICE_BACK= +BADGE_INVITE= +BADGE_INVITE_BACK= \ No newline at end of file diff --git a/src/utils/badge.ts b/src/utils/badge.ts index f12adaae..d5cfea90 100644 --- a/src/utils/badge.ts +++ b/src/utils/badge.ts @@ -1,21 +1,20 @@ import axios, { AxiosResponse } from 'axios'; -import { readFileSync } from 'fs'; import PDFkit from 'pdfkit'; import sharp from 'sharp'; import { Badge } from '../types'; +import env from './env'; -const loadImageBadgeRestricted = () => - `data:image/png;base64,${readFileSync(`assets/badges/badge-restricted.png`, 'base64')}`; -const loadImageBadgeOrgaPrice = () => - `data:image/png;base64,${readFileSync(`assets/badges/badge-orgaprice.png`, 'base64')}`; -const loadImageBadgeFullAccess = () => - `data:image/png;base64,${readFileSync(`assets/badges/badge-fullaccess.png`, 'base64')}`; +const loadImageBadgeRestricted = () => `data:image/png;base64,${env.badge.badge_restricted}`; +const loadImageBadgeOrgaPrice = () => `data:image/png;base64,${env.badge.badge_orgaprice}`; +const loadImageBadgeFullAccess = () => `data:image/png;base64,${env.badge.badge_fullaccess}`; +const loadImageBadgeInvite = () => `data:image/png;base64,${env.badge.badge_invite}`; -const loadBackRestricted = () => `data:image/png;base64,${readFileSync(`assets/badges/back-restricted.png`, 'base64')}`; -const loadBackOrgaPrice = () => `data:image/png;base64,${readFileSync(`assets/badges/back-orgaprice.png`, 'base64')}`; -const loadBackFullAccess = () => `data:image/png;base64,${readFileSync(`assets/badges/back-fullaccess.png`, 'base64')}`; +const loadBackRestricted = () => `data:image/png;base64,${env.badge.badge_restricted_back}`; +const loadBackOrgaPrice = () => `data:image/png;base64,${env.badge.badge_orgaprice_back}`; +const loadBackFullAccess = () => `data:image/png;base64,${env.badge.badge_fullaccess_back}`; +const loadBackInvite = () => `data:image/png;base64,${env.badge.badge_invite_back}`; -type BadgePermission = 'restricted' | 'orgaprice' | 'fullaccess'; +type BadgePermission = 'restricted' | 'orgaprice' | 'fullaccess' | 'invite'; const getBack = (permission: BadgePermission): string => { switch (permission) { @@ -31,6 +30,10 @@ const getBack = (permission: BadgePermission): string => { return loadBackFullAccess(); } + case 'invite': { + return loadBackInvite(); + } + default: { return loadBackRestricted(); } @@ -51,6 +54,10 @@ const getBadge = (permission: BadgePermission): string => { return loadImageBadgeFullAccess(); } + case 'invite': { + return loadImageBadgeInvite(); + } + default: { return loadImageBadgeRestricted(); } diff --git a/src/utils/env.ts b/src/utils/env.ts index 65911060..4f0333f1 100755 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -130,6 +130,16 @@ const env = { enabledInTest: loadEnv('LOG_IN_TEST') === 'true', sentryDsn: loadEnv('LOG_SENTRY_DSN'), }, + badge: { + badge_restricted: loadEnv('BADGE_RESTRICTED'), + badge_orgaprice: loadEnv('BADGE_ORGAPRICE'), + badge_fullaccess: loadEnv('BADGE_FULLACCESS'), + badge_invite: loadEnv('BADGE_INVITE'), + badge_restricted_back: loadEnv('BADGE_RESTRICTED_BACK'), + badge_orgaprice_back: loadEnv('BADGE_ORGAPRICE_BACK'), + badge_fullaccess_back: loadEnv('BADGE_FULLACCESS_BACK'), + badge_invite_back: loadEnv('BADGE_INVITE_BACK'), + }, }; // Create a warn log array to use it after winsotn initialization