Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sct committed Jan 7, 2021
2 parents fd90adb + 2bfe0f2 commit f969506
Show file tree
Hide file tree
Showing 24 changed files with 1,451 additions and 382 deletions.
66 changes: 66 additions & 0 deletions overseerr-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,26 @@ components:
type: string
chatId:
type: string
PushoverSettings:
type: object
properties:
enabled:
type: boolean
example: false
types:
type: number
example: 2
options:
type: object
properties:
accessToken:
type: string
userToken:
type: string
priority:
type: number
sound:
type: string
NotificationEmailSettings:
type: object
properties:
Expand Down Expand Up @@ -1720,6 +1740,52 @@ paths:
responses:
'204':
description: Test notification attempted
/settings/notifications/pushover:
get:
summary: Return current pushover notification settings
description: Returns current pushover notification settings in JSON format
tags:
- settings
responses:
'200':
description: Returned pushover settings
content:
application/json:
schema:
$ref: '#/components/schemas/PushoverSettings'
post:
summary: Update pushover notification settings
description: Update current pushover notification settings with provided values
tags:
- settings
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PushoverSettings'
responses:
'200':
description: 'Values were sucessfully updated'
content:
application/json:
schema:
$ref: '#/components/schemas/PushoverSettings'
/settings/notifications/pushover/test:
post:
summary: Test the provided pushover settings
description: Sends a test notification to the pushover agent
tags:
- settings
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PushoverSettings'
responses:
'204':
description: Test notification attempted
/settings/notifications/slack:
get:
summary: Return current slack notification settings
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
"license": "MIT",
"dependencies": {
"@svgr/webpack": "^5.5.0",
"axios": "^0.21.0",
"axios": "^0.21.1",
"body-parser": "^1.19.0",
"bowser": "^2.11.0",
"connect-typeorm": "^1.1.4",
"cookie-parser": "^1.4.5",
"email-templates": "^8.0.2",
"express": "^4.17.1",
"express-openapi-validator": "^4.9.4",
"express-openapi-validator": "^4.10.2",
"express-session": "^1.17.1",
"formik": "^2.2.6",
"intl": "^1.2.5",
"lodash": "^4.17.20",
"next": "^10.0.3",
"next": "^10.0.4",
"node-schedule": "^1.3.2",
"nodemailer": "^6.4.17",
"nookies": "^2.5.0",
Expand All @@ -39,16 +39,16 @@
"react": "17.0.1",
"react-dom": "17.0.1",
"react-intersection-observer": "^8.31.0",
"react-intl": "^5.10.9",
"react-intl": "^5.10.11",
"react-markdown": "^5.0.3",
"react-spring": "^8.0.27",
"react-toast-notifications": "^2.4.0",
"react-transition-group": "^4.4.1",
"react-truncate-markup": "^5.0.1",
"react-use-clipboard": "1.0.2",
"react-use-clipboard": "1.0.7",
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.0.0",
"swagger-ui-express": "^4.1.5",
"swagger-ui-express": "^4.1.6",
"swr": "^0.3.11",
"typeorm": "^0.2.29",
"uuid": "^8.3.2",
Expand All @@ -71,11 +71,11 @@
"@tailwindcss/typography": "^0.3.1",
"@types/body-parser": "^1.19.0",
"@types/cookie-parser": "^1.4.2",
"@types/email-templates": "^7.1.0",
"@types/email-templates": "^8.0.0",
"@types/express": "^4.17.9",
"@types/express-session": "^1.17.0",
"@types/lodash": "^4.14.165",
"@types/node": "^14.14.14",
"@types/lodash": "^4.14.167",
"@types/node": "^14.14.20",
"@types/node-schedule": "^1.3.1",
"@types/nodemailer": "^6.4.0",
"@types/react": "^17.0.0",
Expand All @@ -87,20 +87,20 @@
"@types/xml2js": "^0.4.7",
"@types/yamljs": "^0.2.31",
"@types/yup": "^0.29.11",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"@typescript-eslint/eslint-plugin": "^4.12.0",
"@typescript-eslint/parser": "^4.12.0",
"autoprefixer": "^9",
"babel-plugin-react-intl": "^8.2.22",
"babel-plugin-react-intl": "^8.2.25",
"babel-plugin-react-intl-auto": "^3.3.0",
"commitizen": "^4.2.2",
"copyfiles": "^2.4.1",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.16.0",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-formatjs": "^2.9.11",
"eslint-plugin-formatjs": "^2.10.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"extract-react-intl-messages": "^4.1.1",
"husky": "^4.3.6",
Expand All @@ -109,7 +109,7 @@
"postcss": "^7",
"postcss-preset-env": "^6.7.0",
"prettier": "^2.2.1",
"semantic-release": "^17.3.0",
"semantic-release": "^17.3.1",
"semantic-release-docker": "^2.2.0",
"tailwindcss": "npm:@tailwindcss/postcss7-compat",
"ts-node": "^9.1.1",
Expand Down
2 changes: 2 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import EmailAgent from './lib/notifications/agents/email';
import TelegramAgent from './lib/notifications/agents/telegram';
import { getAppVersion } from './utils/appVersion';
import SlackAgent from './lib/notifications/agents/slack';
import PushoverAgent from './lib/notifications/agents/pushover';

const API_SPEC_PATH = path.join(__dirname, '../overseerr-api.yml');

Expand Down Expand Up @@ -49,6 +50,7 @@ app
new EmailAgent(),
new SlackAgent(),
new TelegramAgent(),
new PushoverAgent(),
]);

// Start Jobs
Expand Down
8 changes: 6 additions & 2 deletions server/job/plexsync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class JobPlexSync {

private log(
message: string,
level: 'info' | 'error' | 'debug' = 'debug',
level: 'info' | 'error' | 'debug' | 'warn' = 'debug',
optional?: Record<string, unknown>
): void {
logger[level](message, { label: 'Plex Sync', ...optional });
Expand All @@ -356,11 +356,15 @@ class JobPlexSync {
if (!this.running) {
this.running = true;
const userRepository = getRepository(User);
const admin = await userRepository.findOneOrFail({
const admin = await userRepository.findOne({
select: ['id', 'plexToken'],
order: { id: 'ASC' },
});

if (!admin) {
return this.log('No admin configured. Plex sync skipped.', 'warn');
}

this.plexClient = new PlexAPI({ plexToken: admin.plexToken });

this.libraries = settings.plex.libraries.filter(
Expand Down
122 changes: 122 additions & 0 deletions server/lib/notifications/agents/pushover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import axios from 'axios';
import { hasNotificationType, Notification } from '..';
import logger from '../../../logger';
import { getSettings, NotificationAgentPushover } from '../../settings';
import { BaseAgent, NotificationAgent, NotificationPayload } from './agent';

interface PushoverPayload {
token: string;
user: string;
title: string;
message: string;
html: number;
}

class PushoverAgent
extends BaseAgent<NotificationAgentPushover>
implements NotificationAgent {
protected getSettings(): NotificationAgentPushover {
if (this.settings) {
return this.settings;
}

const settings = getSettings();

return settings.notifications.agents.pushover;
}

public shouldSend(type: Notification): boolean {
if (
this.getSettings().enabled &&
this.getSettings().options.accessToken &&
this.getSettings().options.userToken &&
hasNotificationType(type, this.getSettings().types)
) {
return true;
}

return false;
}

private constructMessageDetails(
type: Notification,
payload: NotificationPayload
): { title: string; message: string } {
const settings = getSettings();
let messageTitle = '';
let message = '';

const title = payload.subject;
const plot = payload.message;
const user = payload.notifyUser.username;

switch (type) {
case Notification.MEDIA_PENDING:
messageTitle = 'New Request';
message += `${title}\n\n`;
message += `${plot}\n\n`;
message += `<b>Requested By</b>\n${user}\n\n`;
message += `<b>Status</b>\nPending Approval\n`;
break;
case Notification.MEDIA_APPROVED:
messageTitle = 'Request Approved';
message += `${title}\n\n`;
message += `${plot}\n\n`;
message += `<b>Requested By</b>\n${user}\n\n`;
message += `<b>Status</b>\nProcessing Request\n`;
break;
case Notification.MEDIA_AVAILABLE:
messageTitle = 'Now available!';
message += `${title}\n\n`;
message += `${plot}\n\n`;
message += `<b>Requested By</b>\n${user}\n\n`;
message += `<b>Status</b>\nAvailable\n`;
break;
case Notification.TEST_NOTIFICATION:
messageTitle = 'Test Notification';
message += `${title}\n\n`;
message += `${plot}\n\n`;
message += `<b>Requested By</b>\n${user}\n`;
break;
}

if (settings.main.applicationUrl && payload.media) {
const actionUrl = `${settings.main.applicationUrl}/${payload.media.mediaType}/${payload.media.tmdbId}`;
message += `<a href="${actionUrl}">Open in Overseerr</a>`;
}

return { title: messageTitle, message };
}

public async send(
type: Notification,
payload: NotificationPayload
): Promise<boolean> {
logger.debug('Sending Pushover notification', { label: 'Notifications' });
try {
const endpoint = 'https://api.pushover.net/1/messages.json';

const { accessToken, userToken } = this.getSettings().options;

const { title, message } = this.constructMessageDetails(type, payload);

await axios.post(endpoint, {
token: accessToken,
user: userToken,
title: title,
message: message,
html: 1,
} as PushoverPayload);

return true;
} catch (e) {
logger.error('Error sending Pushover notification', {
label: 'Notifications',
message: e.message,
});
return false;
}
}
}

export default PushoverAgent;
20 changes: 20 additions & 0 deletions server/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,21 @@ export interface NotificationAgentTelegram extends NotificationAgentConfig {
};
}

export interface NotificationAgentPushover extends NotificationAgentConfig {
options: {
accessToken: string;
userToken: string;
priority: number;
sound: string;
};
}

interface NotificationAgents {
email: NotificationAgentEmail;
discord: NotificationAgentDiscord;
slack: NotificationAgentSlack;
telegram: NotificationAgentTelegram;
pushover: NotificationAgentPushover;
}

interface NotificationSettings {
Expand Down Expand Up @@ -174,6 +184,16 @@ class Settings {
chatId: '',
},
},
pushover: {
enabled: false,
types: 0,
options: {
accessToken: '',
userToken: '',
priority: 0,
sound: '',
},
},
},
},
};
Expand Down
Loading

0 comments on commit f969506

Please sign in to comment.