mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-28 01:16:10 +02:00
task notifications
This commit is contained in:
parent
9e28ee036f
commit
7b62b6be86
@ -17,7 +17,7 @@ class SocketAuthority {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.Server = null
|
this.Server = null
|
||||||
this.socketIoServers = []
|
this.socketIoServers = []
|
||||||
this.emittedNotifications = new Set(['item_added', 'item_updated', 'user_online']);
|
this.emittedNotifications = new Set(['item_added', 'item_updated', 'user_online', 'task_started', 'task_finished']);
|
||||||
|
|
||||||
/** @type {Object.<string, SocketClient>} */
|
/** @type {Object.<string, SocketClient>} */
|
||||||
this.clients = {}
|
this.clients = {}
|
||||||
@ -69,7 +69,7 @@ class SocketAuthority {
|
|||||||
* @param {Function} [filter] optional filter function to only send event to specific users
|
* @param {Function} [filter] optional filter function to only send event to specific users
|
||||||
*/
|
*/
|
||||||
emitter(evt, data, filter = null) {
|
emitter(evt, data, filter = null) {
|
||||||
void this._fireNotification(evt, data)
|
void this._fireNotification(evt, flattenAny(data))
|
||||||
for (const socketId in this.clients) {
|
for (const socketId in this.clients) {
|
||||||
if (this.clients[socketId].user) {
|
if (this.clients[socketId].user) {
|
||||||
if (filter && !filter(this.clients[socketId].user)) continue
|
if (filter && !filter(this.clients[socketId].user)) continue
|
||||||
@ -81,7 +81,7 @@ class SocketAuthority {
|
|||||||
|
|
||||||
// Emits event to all clients for a specific user
|
// Emits event to all clients for a specific user
|
||||||
clientEmitter(userId, evt, data) {
|
clientEmitter(userId, evt, data) {
|
||||||
void this._fireNotification(evt, data)
|
void this._fireNotification(evt, flattenAny(data))
|
||||||
const clients = this.getClientsForUser(userId)
|
const clients = this.getClientsForUser(userId)
|
||||||
if (!clients.length) {
|
if (!clients.length) {
|
||||||
return Logger.debug(`[SocketAuthority] clientEmitter - no clients found for user ${userId}`)
|
return Logger.debug(`[SocketAuthority] clientEmitter - no clients found for user ${userId}`)
|
||||||
@ -95,7 +95,7 @@ class SocketAuthority {
|
|||||||
|
|
||||||
// Emits event to all admin user clients
|
// Emits event to all admin user clients
|
||||||
adminEmitter(evt, data) {
|
adminEmitter(evt, data) {
|
||||||
void this._fireNotification(evt, data);
|
void this._fireNotification(evt, flattenAny(data));
|
||||||
for (const socketId in this.clients) {
|
for (const socketId in this.clients) {
|
||||||
if (this.clients[socketId].user?.isAdminOrUp) {
|
if (this.clients[socketId].user?.isAdminOrUp) {
|
||||||
this.clients[socketId].socket.emit(evt, data)
|
this.clients[socketId].socket.emit(evt, data)
|
||||||
|
@ -173,6 +173,57 @@ module.exports.notificationData = {
|
|||||||
body: 'User {{username}} (ID: {{id}}) is now online.'
|
body: 'User {{username}} (ID: {{id}}) is now online.'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'onTaskStarted',
|
||||||
|
requiresLibrary: false,
|
||||||
|
description: 'Triggered when a task starts',
|
||||||
|
descriptionKey: 'NotificationOnTaskStartedDescription',
|
||||||
|
variables: [
|
||||||
|
'id', 'action',
|
||||||
|
'data.libraryId', 'data.libraryName',
|
||||||
|
'title', 'titleKey',
|
||||||
|
'titleSubs', 'description',
|
||||||
|
'descriptionKey', 'descriptionSubs',
|
||||||
|
'error', 'errorKey',
|
||||||
|
'errorSubs', 'showSuccess',
|
||||||
|
'isFailed', 'isFinished',
|
||||||
|
'startedAt', 'finishedAt'
|
||||||
|
],
|
||||||
|
defaults: {
|
||||||
|
title: 'Task Started: {{title}}',
|
||||||
|
body: 'Task {{title}} has started.\n\nAction: {{action}}\nLibrary ID: {{data.libraryId}}\nLibrary Name: {{data.libraryName}}'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'onTaskFinished',
|
||||||
|
requiresLibrary: false,
|
||||||
|
description: 'Triggered when a task finishes',
|
||||||
|
descriptionKey: 'NotificationOnTaskFinishesDescription',
|
||||||
|
variables: [
|
||||||
|
'id',
|
||||||
|
'action',
|
||||||
|
'data.libraryId',
|
||||||
|
'data.libraryName',
|
||||||
|
'title',
|
||||||
|
'titleKey',
|
||||||
|
'titleSubs',
|
||||||
|
'description',
|
||||||
|
'descriptionKey',
|
||||||
|
'descriptionSubs',
|
||||||
|
'error',
|
||||||
|
'errorKey',
|
||||||
|
'errorSubs',
|
||||||
|
'showSuccess',
|
||||||
|
'isFailed',
|
||||||
|
'isFinished',
|
||||||
|
'startedAt',
|
||||||
|
'finishedAt'
|
||||||
|
],
|
||||||
|
defaults: {
|
||||||
|
title: 'Task Started: {{title}}',
|
||||||
|
body: 'Task {{title}} has started.\n\nAction: {{action}}\nLibrary ID: {{data.libraryId}}\nLibrary Name: {{data.libraryName}}'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user