-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from madfish-solutions/development
Release latest changes to production
- Loading branch information
Showing
34 changed files
with
428 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import '../../src/configure'; | ||
|
||
import { Redis } from 'ioredis'; | ||
import { EnvVars } from '../../src/config'; | ||
import { addExistingNotificationsToDb } from './utils/add-existing-notifications-to-db'; | ||
import logger from '../../src/utils/logger'; | ||
|
||
const redisClient = new Redis(EnvVars.REDIS_URL); | ||
|
||
redisClient.on('error', err => logger.error(err)); | ||
|
||
(async () => { | ||
await addExistingNotificationsToDb(redisClient); | ||
logger.info('Notifications successfully added to Redis database.'); | ||
process.exit(0); | ||
})(); |
14 changes: 14 additions & 0 deletions
14
migrations/notifications/utils/add-existing-notifications-to-db.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Redis } from 'ioredis'; | ||
|
||
import { DEFAULT_NOTIFICATIONS_LIST, MANDATORY_NOTIFICATIONS_LIST } from '../data/notifications.data'; | ||
|
||
export const addExistingNotificationsToDb = async (client: Redis) => { | ||
const data = await client.lrange('notifications', 0, -1); | ||
const existingNotifications = [...DEFAULT_NOTIFICATIONS_LIST, ...MANDATORY_NOTIFICATIONS_LIST]; | ||
|
||
if (data.length === 0) { | ||
for (let i = 0; i < existingNotifications.length; i++) { | ||
await client.rpush('notifications', JSON.stringify(existingNotifications[i])); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
|
||
import { EnvVars } from '../config'; | ||
import { isDefined } from '../utils/helpers'; | ||
|
||
export const basicAuth = (req: Request, res: Response, next: NextFunction) => { | ||
const base64EncodedCredentials = req.get('Authorization'); | ||
|
||
if (isDefined(base64EncodedCredentials)) { | ||
const [username, password] = Buffer.from(base64EncodedCredentials.split(' ')[1], 'base64').toString().split(':'); | ||
|
||
if (!(username === EnvVars.ADD_NOTIFICATION_USERNAME && password === EnvVars.ADD_NOTIFICATION_PASSWORD)) { | ||
handleNotAuthenticated(res, next); | ||
} | ||
next(); | ||
} else { | ||
handleNotAuthenticated(res, next); | ||
} | ||
}; | ||
|
||
const handleNotAuthenticated = (res: Response, next: NextFunction) => { | ||
const err = new Error('Not Authenticated!'); | ||
res.status(401).set('WWW-Authenticate', 'Basic'); | ||
next(err); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const IMAGES_BUCKET_URL = 'https://generic-objects.fra1.digitaloceanspaces.com/notification-icons'; | ||
|
||
export const DEFAULT_IMAGE_URLS = { | ||
extension: { | ||
news: `${IMAGES_BUCKET_URL}/extension/news.svg`, | ||
platformUpdate: `${IMAGES_BUCKET_URL}/extension/platform-update.svg`, | ||
securityNote: `${IMAGES_BUCKET_URL}/extension/security-note.svg`, | ||
winNft: `${IMAGES_BUCKET_URL}/extension/extension-win-nft.svg` | ||
}, | ||
mobile: { | ||
news: `${IMAGES_BUCKET_URL}/mobile/news.svg`, | ||
platformUpdate: `${IMAGES_BUCKET_URL}/mobile/platform-update.svg`, | ||
securityNote: `${IMAGES_BUCKET_URL}/mobile/security-note.svg`, | ||
winNft: `${IMAGES_BUCKET_URL}/mobile/mobile-win-nft.svg` | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { DEFAULT_IMAGE_URLS } from '../default-image-fallbacks'; | ||
import { NotificationType, PlatformType } from '../notification.interface'; | ||
|
||
export const getImageFallback = (platform: PlatformType, notificationType: NotificationType) => { | ||
if (platform === PlatformType.Mobile) { | ||
switch (notificationType) { | ||
case NotificationType.PlatformUpdate: | ||
return DEFAULT_IMAGE_URLS.mobile.platformUpdate; | ||
case NotificationType.SecurityNote: | ||
return DEFAULT_IMAGE_URLS.mobile.securityNote; | ||
default: | ||
return DEFAULT_IMAGE_URLS.mobile.news; | ||
} | ||
} else { | ||
switch (notificationType) { | ||
case NotificationType.PlatformUpdate: | ||
return DEFAULT_IMAGE_URLS.extension.platformUpdate; | ||
case NotificationType.SecurityNote: | ||
return DEFAULT_IMAGE_URLS.extension.securityNote; | ||
default: | ||
return DEFAULT_IMAGE_URLS.extension.news; | ||
} | ||
} | ||
}; |
Oops, something went wrong.