mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-13 15:29:38 +00:00
Update:Refactor socket connection management into SocketAuthority
This commit is contained in:
parent
42e68edc65
commit
e2af33e136
22 changed files with 386 additions and 341 deletions
|
|
@ -1,8 +1,9 @@
|
|||
const fs = require('../libs/fsExtra')
|
||||
const Path = require('path')
|
||||
const Logger = require('../Logger')
|
||||
const SocketAuthority = require('../SocketAuthority')
|
||||
|
||||
// Utils
|
||||
const Logger = require('../Logger')
|
||||
const { groupFilesIntoLibraryItemPaths, getLibraryItemFileData, scanFolder } = require('../utils/scandir')
|
||||
const { comparePaths } = require('../utils/index')
|
||||
const { getIno } = require('../utils/fileUtils')
|
||||
|
|
@ -20,12 +21,11 @@ const Author = require('../objects/entities/Author')
|
|||
const Series = require('../objects/entities/Series')
|
||||
|
||||
class Scanner {
|
||||
constructor(db, coverManager, emitter) {
|
||||
constructor(db, coverManager) {
|
||||
this.ScanLogPath = Path.posix.join(global.MetadataPath, 'logs', 'scans')
|
||||
|
||||
this.db = db
|
||||
this.coverManager = coverManager
|
||||
this.emitter = emitter
|
||||
|
||||
this.cancelLibraryScan = {}
|
||||
this.librariesScanning = []
|
||||
|
|
@ -113,7 +113,7 @@ class Scanner {
|
|||
}
|
||||
|
||||
if (hasUpdated) {
|
||||
this.emitter('item_updated', libraryItem.toJSONExpanded())
|
||||
SocketAuthority.emitter('item_updated', libraryItem.toJSONExpanded())
|
||||
await this.db.updateLibraryItem(libraryItem)
|
||||
return ScanResult.UPDATED
|
||||
}
|
||||
|
|
@ -139,7 +139,7 @@ class Scanner {
|
|||
libraryScan.verbose = false
|
||||
this.librariesScanning.push(libraryScan.getScanEmitData)
|
||||
|
||||
this.emitter('scan_start', libraryScan.getScanEmitData)
|
||||
SocketAuthority.emitter('scan_start', libraryScan.getScanEmitData)
|
||||
|
||||
Logger.info(`[Scanner] Starting library scan ${libraryScan.id} for ${libraryScan.libraryName}`)
|
||||
|
||||
|
|
@ -158,11 +158,11 @@ class Scanner {
|
|||
if (canceled && !libraryScan.totalResults) {
|
||||
var emitData = libraryScan.getScanEmitData
|
||||
emitData.results = null
|
||||
this.emitter('scan_complete', emitData)
|
||||
SocketAuthority.emitter('scan_complete', emitData)
|
||||
return
|
||||
}
|
||||
|
||||
this.emitter('scan_complete', libraryScan.getScanEmitData)
|
||||
SocketAuthority.emitter('scan_complete', libraryScan.getScanEmitData)
|
||||
|
||||
if (libraryScan.totalResults) {
|
||||
libraryScan.saveLog(this.ScanLogPath)
|
||||
|
|
@ -302,7 +302,7 @@ class Scanner {
|
|||
|
||||
async updateLibraryItemChunk(itemsToUpdate) {
|
||||
await this.db.updateLibraryItems(itemsToUpdate)
|
||||
this.emitter('items_updated', itemsToUpdate.map(li => li.toJSONExpanded()))
|
||||
SocketAuthority.emitter('items_updated', itemsToUpdate.map(li => li.toJSONExpanded()))
|
||||
}
|
||||
|
||||
async rescanLibraryItemDataChunk(itemDataToRescan, libraryScan) {
|
||||
|
|
@ -320,7 +320,7 @@ class Scanner {
|
|||
if (itemsUpdated.length) {
|
||||
libraryScan.resultsUpdated += itemsUpdated.length
|
||||
await this.db.updateLibraryItems(itemsUpdated)
|
||||
this.emitter('items_updated', itemsUpdated.map(li => li.toJSONExpanded()))
|
||||
SocketAuthority.emitter('items_updated', itemsUpdated.map(li => li.toJSONExpanded()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -337,7 +337,7 @@ class Scanner {
|
|||
|
||||
libraryScan.resultsAdded += newLibraryItems.length
|
||||
await this.db.insertLibraryItems(newLibraryItems)
|
||||
this.emitter('items_added', newLibraryItems.map(li => li.toJSONExpanded()))
|
||||
SocketAuthority.emitter('items_added', newLibraryItems.map(li => li.toJSONExpanded()))
|
||||
}
|
||||
|
||||
async rescanLibraryItem(libraryItemCheckData, libraryScan) {
|
||||
|
|
@ -458,7 +458,7 @@ class Scanner {
|
|||
})
|
||||
if (newAuthors.length) {
|
||||
await this.db.insertEntities('author', newAuthors)
|
||||
this.emitter('authors_added', newAuthors.map(au => au.toJSON()))
|
||||
SocketAuthority.emitter('authors_added', newAuthors.map(au => au.toJSON()))
|
||||
}
|
||||
}
|
||||
if (libraryItem.media.metadata.series.some(se => se.id.startsWith('new'))) {
|
||||
|
|
@ -479,7 +479,7 @@ class Scanner {
|
|||
})
|
||||
if (newSeries.length) {
|
||||
await this.db.insertEntities('series', newSeries)
|
||||
this.emitter('series_added', newSeries.map(se => se.toJSON()))
|
||||
SocketAuthority.emitter('series_added', newSeries.map(se => se.toJSON()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -602,7 +602,7 @@ class Scanner {
|
|||
Logger.info(`[Scanner] Scanning file update group and library item was deleted "${existingLibraryItem.media.metadata.title}" - marking as missing`)
|
||||
existingLibraryItem.setMissing()
|
||||
await this.db.updateLibraryItem(existingLibraryItem)
|
||||
this.emitter('item_updated', existingLibraryItem.toJSONExpanded())
|
||||
SocketAuthority.emitter('item_updated', existingLibraryItem.toJSONExpanded())
|
||||
|
||||
itemGroupingResults[itemDir] = ScanResult.REMOVED
|
||||
continue;
|
||||
|
|
@ -629,7 +629,7 @@ class Scanner {
|
|||
if (newLibraryItem) {
|
||||
await this.createNewAuthorsAndSeries(newLibraryItem)
|
||||
await this.db.insertLibraryItem(newLibraryItem)
|
||||
this.emitter('item_added', newLibraryItem.toJSONExpanded())
|
||||
SocketAuthority.emitter('item_added', newLibraryItem.toJSONExpanded())
|
||||
}
|
||||
itemGroupingResults[itemDir] = newLibraryItem ? ScanResult.ADDED : ScanResult.NOTHING
|
||||
}
|
||||
|
|
@ -747,7 +747,7 @@ class Scanner {
|
|||
}
|
||||
|
||||
await this.db.updateLibraryItem(libraryItem)
|
||||
this.emitter('item_updated', libraryItem.toJSONExpanded())
|
||||
SocketAuthority.emitter('item_updated', libraryItem.toJSONExpanded())
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
@ -846,7 +846,7 @@ class Scanner {
|
|||
author = new Author()
|
||||
author.setData({ name: authorName })
|
||||
await this.db.insertEntity('author', author)
|
||||
this.emitter('author_added', author)
|
||||
SocketAuthority.emitter('author_added', author)
|
||||
}
|
||||
authorPayload.push(author.toJSONMinimal())
|
||||
}
|
||||
|
|
@ -864,7 +864,7 @@ class Scanner {
|
|||
seriesItem = new Series()
|
||||
seriesItem.setData({ name: seriesMatchItem.series })
|
||||
await this.db.insertEntity('series', seriesItem)
|
||||
this.emitter('series_added', seriesItem)
|
||||
SocketAuthority.emitter('series_added', seriesItem)
|
||||
}
|
||||
seriesPayload.push(seriesItem.toJSONMinimal(seriesMatchItem.sequence))
|
||||
}
|
||||
|
|
@ -955,7 +955,7 @@ class Scanner {
|
|||
var libraryScan = new LibraryScan()
|
||||
libraryScan.setData(library, null, 'match')
|
||||
this.librariesScanning.push(libraryScan.getScanEmitData)
|
||||
this.emitter('scan_start', libraryScan.getScanEmitData)
|
||||
SocketAuthority.emitter('scan_start', libraryScan.getScanEmitData)
|
||||
|
||||
Logger.info(`[Scanner] matchLibraryItems: Starting library match scan ${libraryScan.id} for ${libraryScan.libraryName}`)
|
||||
|
||||
|
|
@ -987,14 +987,14 @@ class Scanner {
|
|||
delete this.cancelLibraryScan[libraryScan.libraryId]
|
||||
var scanData = libraryScan.getScanEmitData
|
||||
scanData.results = false
|
||||
this.emitter('scan_complete', scanData)
|
||||
SocketAuthority.emitter('scan_complete', scanData)
|
||||
this.librariesScanning = this.librariesScanning.filter(ls => ls.id !== library.id)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.librariesScanning = this.librariesScanning.filter(ls => ls.id !== library.id)
|
||||
this.emitter('scan_complete', libraryScan.getScanEmitData)
|
||||
SocketAuthority.emitter('scan_complete', libraryScan.getScanEmitData)
|
||||
}
|
||||
|
||||
probeAudioFileWithTone(audioFile) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue