mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-28 14:49:38 +00:00
Update:Replace library scan toast with task manager #1279
This commit is contained in:
parent
6f65350269
commit
bef6549805
7 changed files with 61 additions and 19 deletions
|
|
@ -6,7 +6,7 @@ const date = require('../libs/dateAndTime')
|
|||
const Logger = require('../Logger')
|
||||
const Library = require('../objects/Library')
|
||||
const { LogLevel } = require('../utils/constants')
|
||||
const { secondsToTimestamp } = require('../utils/index')
|
||||
const { secondsToTimestamp, elapsedPretty } = require('../utils/index')
|
||||
|
||||
class LibraryScan {
|
||||
constructor() {
|
||||
|
|
@ -67,6 +67,15 @@ class LibraryScan {
|
|||
get logFilename() {
|
||||
return date.format(new Date(), 'YYYY-MM-DD') + '_' + this.id + '.txt'
|
||||
}
|
||||
get scanResultsString() {
|
||||
if (this.error) return this.error
|
||||
const strs = []
|
||||
if (this.resultsAdded) strs.push(`${this.resultsAdded} added`)
|
||||
if (this.resultsUpdated) strs.push(`${this.resultsUpdated} updated`)
|
||||
if (this.resultsMissing) strs.push(`${this.resultsMissing} missing`)
|
||||
if (!strs.length) return `Everything was up to date (${elapsedPretty(this.elapsed / 1000)})`
|
||||
return strs.join(', ') + ` (${elapsedPretty(this.elapsed / 1000)})`
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ const fileUtils = require('../utils/fileUtils')
|
|||
const scanUtils = require('../utils/scandir')
|
||||
const { LogLevel, ScanResult } = require('../utils/constants')
|
||||
const libraryFilters = require('../utils/queries/libraryFilters')
|
||||
const TaskManager = require('../managers/TaskManager')
|
||||
const LibraryItemScanner = require('./LibraryItemScanner')
|
||||
const LibraryScan = require('./LibraryScan')
|
||||
const LibraryItemScanData = require('./LibraryItemScanData')
|
||||
|
|
@ -68,7 +69,12 @@ class LibraryScanner {
|
|||
libraryScan.verbose = true
|
||||
this.librariesScanning.push(libraryScan.getScanEmitData)
|
||||
|
||||
SocketAuthority.emitter('scan_start', libraryScan.getScanEmitData)
|
||||
const taskData = {
|
||||
libraryId: library.id,
|
||||
libraryName: library.name,
|
||||
libraryMediaType: library.mediaType
|
||||
}
|
||||
const task = TaskManager.createAndAddTask('library-scan', `Scanning "${library.name}" library`, null, true, taskData)
|
||||
|
||||
Logger.info(`[LibraryScanner] Starting${forceRescan ? ' (forced)' : ''} library scan ${libraryScan.id} for ${libraryScan.libraryName}`)
|
||||
|
||||
|
|
@ -85,9 +91,11 @@ class LibraryScanner {
|
|||
this.librariesScanning = this.librariesScanning.filter(ls => ls.id !== library.id)
|
||||
|
||||
if (canceled && !libraryScan.totalResults) {
|
||||
task.setFinished('Scan canceled')
|
||||
TaskManager.taskFinished(task)
|
||||
|
||||
const emitData = libraryScan.getScanEmitData
|
||||
emitData.results = null
|
||||
SocketAuthority.emitter('scan_complete', emitData)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +106,8 @@ class LibraryScanner {
|
|||
}
|
||||
await Database.libraryModel.updateFromOld(library)
|
||||
|
||||
SocketAuthority.emitter('scan_complete', libraryScan.getScanEmitData)
|
||||
task.setFinished(libraryScan.scanResultsString)
|
||||
TaskManager.taskFinished(task)
|
||||
|
||||
if (libraryScan.totalResults) {
|
||||
libraryScan.saveLog()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue