Skip to content

Commit

Permalink
feat: change environments variables, badge image must be in base64
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine D committed Oct 3, 2024
1 parent 06025e5 commit 51a8c9a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
12 changes: 11 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ DISCORD_WEBHOOK_CONTACT=

# Some more random variables
API_RATE_LIMIT=12
API_CART_LIFESPAN=3600
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=
29 changes: 18 additions & 11 deletions src/utils/badge.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -31,6 +30,10 @@ const getBack = (permission: BadgePermission): string => {
return loadBackFullAccess();
}

case 'invite': {
return loadBackInvite();
}

default: {
return loadBackRestricted();
}
Expand All @@ -51,6 +54,10 @@ const getBadge = (permission: BadgePermission): string => {
return loadImageBadgeFullAccess();
}

case 'invite': {
return loadImageBadgeInvite();
}

default: {
return loadImageBadgeRestricted();
}
Expand Down
10 changes: 10 additions & 0 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 51a8c9a

Please sign in to comment.