mirror of
https://github.com/unraid/api.git
synced 2026-04-27 02:32:54 -05:00
010efe75bd
This reverts commit 4ef387b5bb.
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
/*!
|
|
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
|
|
* Written by: Alexis Tyler
|
|
*/
|
|
|
|
import { HttpNotifier, Options as HttpNotifierOptions } from './http';
|
|
import { NotifierSendOptions } from './notifier';
|
|
|
|
type Transport = 'email' | 'push' | 'ios' | 'android';
|
|
|
|
interface Options extends HttpNotifierOptions {
|
|
transport?: Transport;
|
|
}
|
|
|
|
/**
|
|
* Send notification through UNRAID's remote server.
|
|
*/
|
|
export class UnraidNotifier extends HttpNotifier {
|
|
private readonly transport: Transport;
|
|
private readonly endpoint: string;
|
|
|
|
constructor(options: Options) {
|
|
super(options);
|
|
|
|
this.transport = options.transport ?? 'email';
|
|
this.endpoint = 'https://forums.unraid.net/api/notifier.php';
|
|
}
|
|
|
|
/**
|
|
* Send notification.
|
|
*/
|
|
async send(options: NotifierSendOptions) {
|
|
const { endpoint, transport } = this;
|
|
const { type = 'generic', title = 'Unraid Server Notification' } = options;
|
|
const { ...body } = options.data;
|
|
|
|
const headers = {
|
|
Accept: 'application/json, text/plain, */*',
|
|
'Content-Type': 'application/json'
|
|
};
|
|
|
|
return this.$http(endpoint, {
|
|
method: 'POST',
|
|
headers,
|
|
body: JSON.stringify({
|
|
type,
|
|
title,
|
|
body,
|
|
transport
|
|
})
|
|
});
|
|
}
|
|
}
|