mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-11-04 03:17:00 -05:00 
			
		
		
		
	Add:Notification system max queue and max failed attempts settings #996
This commit is contained in:
		
							parent
							
								
									7aa89f16c9
								
							
						
					
					
						commit
						39a13e3610
					
				@ -8,7 +8,24 @@
 | 
				
			|||||||
      </p>
 | 
					      </p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <form @submit.prevent="submitForm">
 | 
					      <form @submit.prevent="submitForm">
 | 
				
			||||||
        <ui-text-input-with-label ref="apiUrlInput" v-model="appriseApiUrl" :disabled="savingSettings" label="Apprise API Url" />
 | 
					        <ui-text-input-with-label ref="apiUrlInput" v-model="appriseApiUrl" :disabled="savingSettings" label="Apprise API Url" class="mb-2" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <div class="flex items-center py-2">
 | 
				
			||||||
 | 
					          <ui-text-input ref="maxNotificationQueueInput" type="number" v-model="maxNotificationQueue" no-spinner :disabled="savingSettings" :padding-x="1" text-center class="w-10" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          <ui-tooltip text="Events are limited to firing 1 per second. Events will be ignored if the queue is at max size. This prevents notification spamming." direction="right">
 | 
				
			||||||
 | 
					            <p class="pl-4 text-lg">Max queue size for notification events<span class="material-icons icon-text ml-1">info_outlined</span></p>
 | 
				
			||||||
 | 
					          </ui-tooltip>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <div class="flex items-center py-2">
 | 
				
			||||||
 | 
					          <ui-text-input ref="maxFailedAttemptsInput" type="number" v-model="maxFailedAttempts" no-spinner :disabled="savingSettings" :padding-x="1" text-center class="w-10" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          <ui-tooltip text="Notifications are disabled once they fail to send this many times." direction="right">
 | 
				
			||||||
 | 
					            <p class="pl-4 text-lg">Max failed attempts<span class="material-icons icon-text ml-1">info_outlined</span></p>
 | 
				
			||||||
 | 
					          </ui-tooltip>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <div class="flex items-center justify-end pt-4">
 | 
					        <div class="flex items-center justify-end pt-4">
 | 
				
			||||||
          <ui-btn :loading="savingSettings" type="submit">Save</ui-btn>
 | 
					          <ui-btn :loading="savingSettings" type="submit">Save</ui-btn>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
@ -40,6 +57,8 @@ export default {
 | 
				
			|||||||
      loading: false,
 | 
					      loading: false,
 | 
				
			||||||
      savingSettings: false,
 | 
					      savingSettings: false,
 | 
				
			||||||
      appriseApiUrl: null,
 | 
					      appriseApiUrl: null,
 | 
				
			||||||
 | 
					      maxNotificationQueue: 0,
 | 
				
			||||||
 | 
					      maxFailedAttempts: 0,
 | 
				
			||||||
      notifications: [],
 | 
					      notifications: [],
 | 
				
			||||||
      notificationSettings: null,
 | 
					      notificationSettings: null,
 | 
				
			||||||
      notificationData: null,
 | 
					      notificationData: null,
 | 
				
			||||||
@ -71,23 +90,40 @@ export default {
 | 
				
			|||||||
        return false
 | 
					        return false
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    submitForm() {
 | 
					    validateForm() {
 | 
				
			||||||
      if (this.notificationSettings && this.notificationSettings.appriseApiUrl == this.appriseApiUrl) {
 | 
					 | 
				
			||||||
        this.$toast.info('No update necessary')
 | 
					 | 
				
			||||||
        return
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (this.$refs.apiUrlInput) {
 | 
					      if (this.$refs.apiUrlInput) {
 | 
				
			||||||
        this.$refs.apiUrlInput.blur()
 | 
					        this.$refs.apiUrlInput.blur()
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      if (this.$refs.maxNotificationQueueInput) {
 | 
				
			||||||
      const isValid = this.validateAppriseApiUrl()
 | 
					        this.$refs.maxNotificationQueueInput.blur()
 | 
				
			||||||
      if (!isValid) {
 | 
					      }
 | 
				
			||||||
        return
 | 
					      if (this.$refs.maxFailedAttemptsInput) {
 | 
				
			||||||
 | 
					        this.$refs.maxFailedAttemptsInput.blur()
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!this.validateAppriseApiUrl()) {
 | 
				
			||||||
 | 
					        return false
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (isNaN(this.maxNotificationQueue) || this.maxNotificationQueue <= 0) {
 | 
				
			||||||
 | 
					        this.$toast.error('Max notification queue must be >= 0')
 | 
				
			||||||
 | 
					        return false
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (isNaN(this.maxFailedAttempts) || this.maxFailedAttempts <= 0) {
 | 
				
			||||||
 | 
					        this.$toast.error('Max failed attempts must be >= 0')
 | 
				
			||||||
 | 
					        return false
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      return true
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    submitForm() {
 | 
				
			||||||
 | 
					      if (!this.validateForm()) return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const updatePayload = {
 | 
					      const updatePayload = {
 | 
				
			||||||
        appriseApiUrl: this.appriseApiUrl || null
 | 
					        appriseApiUrl: this.appriseApiUrl || null,
 | 
				
			||||||
 | 
					        maxNotificationQueue: Number(this.maxNotificationQueue),
 | 
				
			||||||
 | 
					        maxFailedAttempts: Number(this.maxFailedAttempts)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      this.savingSettings = true
 | 
					      this.savingSettings = true
 | 
				
			||||||
      this.$axios
 | 
					      this.$axios
 | 
				
			||||||
@ -120,6 +156,8 @@ export default {
 | 
				
			|||||||
    setNotificationSettings(notificationSettings) {
 | 
					    setNotificationSettings(notificationSettings) {
 | 
				
			||||||
      this.notificationSettings = notificationSettings
 | 
					      this.notificationSettings = notificationSettings
 | 
				
			||||||
      this.appriseApiUrl = notificationSettings.appriseApiUrl
 | 
					      this.appriseApiUrl = notificationSettings.appriseApiUrl
 | 
				
			||||||
 | 
					      this.maxNotificationQueue = notificationSettings.maxNotificationQueue
 | 
				
			||||||
 | 
					      this.maxFailedAttempts = notificationSettings.maxFailedAttempts
 | 
				
			||||||
      this.notifications = notificationSettings.notifications || []
 | 
					      this.notifications = notificationSettings.notifications || []
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    notificationsUpdated(notificationSettings) {
 | 
					    notificationsUpdated(notificationSettings) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
const Logger = require('../../Logger')
 | 
					const Logger = require('../../Logger')
 | 
				
			||||||
const Notification = require('../Notification')
 | 
					const Notification = require('../Notification')
 | 
				
			||||||
 | 
					const { isNullOrNaN } = require('../../utils')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class NotificationSettings {
 | 
					class NotificationSettings {
 | 
				
			||||||
  constructor(settings = null) {
 | 
					  constructor(settings = null) {
 | 
				
			||||||
@ -59,11 +60,26 @@ class NotificationSettings {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  update(payload) {
 | 
					  update(payload) {
 | 
				
			||||||
    if (!payload) return false
 | 
					    if (!payload) return false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var hasUpdates = false
 | 
				
			||||||
    if (payload.appriseApiUrl !== this.appriseApiUrl) {
 | 
					    if (payload.appriseApiUrl !== this.appriseApiUrl) {
 | 
				
			||||||
      this.appriseApiUrl = payload.appriseApiUrl || null
 | 
					      this.appriseApiUrl = payload.appriseApiUrl || null
 | 
				
			||||||
      return true
 | 
					      hasUpdates = true
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return false
 | 
					
 | 
				
			||||||
 | 
					    const _maxFailedAttempts = isNullOrNaN(payload.maxFailedAttempts) ? 5 : Number(payload.maxFailedAttempts)
 | 
				
			||||||
 | 
					    if (_maxFailedAttempts !== this.maxFailedAttempts) {
 | 
				
			||||||
 | 
					      this.maxFailedAttempts = _maxFailedAttempts
 | 
				
			||||||
 | 
					      hasUpdates = true
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const _maxNotificationQueue = isNullOrNaN(payload.maxNotificationQueue) ? 20 : Number(payload.maxNotificationQueue)
 | 
				
			||||||
 | 
					    if (_maxNotificationQueue !== this.maxNotificationQueue) {
 | 
				
			||||||
 | 
					      this.maxNotificationQueue = _maxNotificationQueue
 | 
				
			||||||
 | 
					      hasUpdates = true
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return hasUpdates
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createNotification(payload) {
 | 
					  createNotification(payload) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user