mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2026-01-01 04:08:45 -05:00
feat(notifications): add option to send notifications for auto-approved requests
closes #267
This commit is contained in:
@@ -201,6 +201,18 @@ export class MediaRequest {
|
||||
}
|
||||
}
|
||||
|
||||
@AfterInsert()
|
||||
public async autoapprovalNotification(): Promise<void> {
|
||||
const settings = getSettings().notifications;
|
||||
|
||||
if (
|
||||
settings.autoapprovalEnabled &&
|
||||
this.status === MediaRequestStatus.APPROVED
|
||||
) {
|
||||
this.notifyApprovedOrDeclined();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterUpdate()
|
||||
@AfterInsert()
|
||||
public async updateParentStatus(): Promise<void> {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import logger from '../../logger';
|
||||
import { getSettings } from '../settings';
|
||||
import type { NotificationAgent, NotificationPayload } from './agents/agent';
|
||||
|
||||
export enum Notification {
|
||||
@@ -43,11 +44,12 @@ class NotificationManager {
|
||||
type: Notification,
|
||||
payload: NotificationPayload
|
||||
): void {
|
||||
const settings = getSettings().notifications;
|
||||
logger.info(`Sending notification for ${Notification[type]}`, {
|
||||
label: 'Notifications',
|
||||
});
|
||||
this.activeAgents.forEach((agent) => {
|
||||
if (agent.shouldSend(type)) {
|
||||
if (settings.enabled && agent.shouldSend(type)) {
|
||||
agent.send(type, payload);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -126,6 +126,8 @@ interface NotificationAgents {
|
||||
}
|
||||
|
||||
interface NotificationSettings {
|
||||
enabled: boolean;
|
||||
autoapprovalEnabled: boolean;
|
||||
agents: NotificationAgents;
|
||||
}
|
||||
|
||||
@@ -168,6 +170,8 @@ class Settings {
|
||||
initialized: false,
|
||||
},
|
||||
notifications: {
|
||||
enabled: true,
|
||||
autoapprovalEnabled: false,
|
||||
agents: {
|
||||
email: {
|
||||
enabled: false,
|
||||
|
||||
@@ -10,6 +10,29 @@ import WebhookAgent from '../../lib/notifications/agents/webhook';
|
||||
|
||||
const notificationRoutes = Router();
|
||||
|
||||
notificationRoutes.get('/', (_req, res) => {
|
||||
const settings = getSettings().notifications;
|
||||
return res.status(200).json({
|
||||
enabled: settings.enabled,
|
||||
autoapprovalEnabled: settings.autoapprovalEnabled,
|
||||
});
|
||||
});
|
||||
|
||||
notificationRoutes.post('/', (req, res) => {
|
||||
const settings = getSettings();
|
||||
|
||||
Object.assign(settings.notifications, {
|
||||
enabled: req.body.enabled,
|
||||
autoapprovalEnabled: req.body.autoapprovalEnabled,
|
||||
});
|
||||
settings.save();
|
||||
|
||||
return res.status(200).json({
|
||||
enabled: settings.notifications.enabled,
|
||||
autoapprovalEnabled: settings.notifications.autoapprovalEnabled,
|
||||
});
|
||||
});
|
||||
|
||||
notificationRoutes.get('/discord', (_req, res) => {
|
||||
const settings = getSettings();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user