feat: notifications for media_available and media_approved

This commit is contained in:
sct
2020-11-23 10:34:53 +00:00
parent d8e542e5fe
commit a6c5e65bbf
8 changed files with 234 additions and 29 deletions

View File

@@ -1,10 +1,12 @@
import { Notification } from '..';
import { User } from '../../../entity/User';
export interface NotificationPayload {
subject: string;
username?: string;
notifyUser: User;
image?: string;
message?: string;
extra?: { name: string; value: string }[];
}
export interface NotificationAgent {

View File

@@ -81,10 +81,21 @@ class DiscordAgent implements NotificationAgent {
payload: NotificationPayload
): DiscordRichEmbed {
let color = EmbedColors.DEFAULT;
let status = 'Unknown';
switch (type) {
case Notification.MEDIA_ADDED:
case Notification.MEDIA_PENDING:
color = EmbedColors.ORANGE;
status = 'Pending Approval';
break;
case Notification.MEDIA_APPROVED:
color = EmbedColors.PURPLE;
status = 'Processing Request';
break;
case Notification.MEDIA_AVAILABLE:
color = EmbedColors.GREEN;
status = 'Available';
break;
}
return {
@@ -96,14 +107,19 @@ class DiscordAgent implements NotificationAgent {
fields: [
{
name: 'Requested By',
value: payload.username ?? '',
value: payload.notifyUser.username ?? '',
inline: true,
},
{
name: 'Status',
value: 'Pending Approval',
value: status,
inline: true,
},
// If we have extra data, map it to fields for discord notifications
...(payload.extra ?? []).map((extra) => ({
name: extra.name,
value: extra.value,
})),
],
thumbnail: {
url: payload.image,
@@ -131,8 +147,8 @@ class DiscordAgent implements NotificationAgent {
const settings = getSettings();
logger.debug('Sending discord notification', { label: 'Notifications' });
try {
const webhookUrl = settings.notifications.agents.discord?.options
?.webhookUrl as string;
const webhookUrl =
settings.notifications.agents.discord?.options?.webhookUrl;
if (!webhookUrl) {
return false;

View File

@@ -2,7 +2,9 @@ import logger from '../../logger';
import type { NotificationAgent, NotificationPayload } from './agents/agent';
export enum Notification {
MEDIA_ADDED = 2,
MEDIA_PENDING = 2,
MEDIA_APPROVED = 4,
MEDIA_AVAILABLE = 8,
}
class NotificationManager {