2021-11-23 02:58:20 +01:00
|
|
|
const Folder = require('../objects/Folder')
|
2021-11-25 03:15:50 +01:00
|
|
|
const Constants = require('../utils/constants')
|
2021-11-23 02:58:20 +01:00
|
|
|
|
2021-11-25 03:15:50 +01:00
|
|
|
const { getId, secondsToTimestamp } = require('../utils/index')
|
2021-11-23 02:58:20 +01:00
|
|
|
|
|
|
|
class LibraryScan {
|
|
|
|
constructor() {
|
|
|
|
this.id = null
|
|
|
|
this.libraryId = null
|
|
|
|
this.libraryName = null
|
|
|
|
this.folders = null
|
|
|
|
|
|
|
|
this.scanOptions = null
|
|
|
|
|
|
|
|
this.startedAt = null
|
|
|
|
this.finishedAt = null
|
2021-11-25 03:15:50 +01:00
|
|
|
this.elapsed = null
|
2021-11-23 02:58:20 +01:00
|
|
|
|
2021-11-25 03:15:50 +01:00
|
|
|
this.status = Constants.ScanStatus.NOTHING
|
|
|
|
this.resultsMissing = 0
|
|
|
|
this.resultsAdded = 0
|
|
|
|
this.resultsUpdated = 0
|
2021-11-23 02:58:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get _scanOptions() { return this.scanOptions || {} }
|
|
|
|
get forceRescan() { return !!this._scanOptions.forceRescan }
|
|
|
|
|
2021-11-25 03:15:50 +01:00
|
|
|
get resultStats() {
|
|
|
|
return `${this.resultsAdded} Added | ${this.resultsUpdated} Updated | ${this.resultsMissing} Missing`
|
|
|
|
}
|
|
|
|
get elapsedTimestamp() {
|
|
|
|
return secondsToTimestamp(this.elapsed / 1000)
|
|
|
|
}
|
|
|
|
get getScanEmitData() {
|
|
|
|
return {
|
|
|
|
id: this.libraryId,
|
|
|
|
name: this.libraryName,
|
|
|
|
results: {
|
|
|
|
added: this.resultsAdded,
|
|
|
|
updated: this.resultsUpdated,
|
|
|
|
missing: this.resultsMissing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 02:58:20 +01:00
|
|
|
setData(library, scanOptions) {
|
|
|
|
this.id = getId('lscan')
|
|
|
|
this.libraryId = library.id
|
|
|
|
this.libraryName = library.name
|
2021-11-25 03:15:50 +01:00
|
|
|
this.folders = library.folders.map(folder => new Folder(folder.toJSON()))
|
2021-11-23 02:58:20 +01:00
|
|
|
|
|
|
|
this.scanOptions = scanOptions
|
|
|
|
|
|
|
|
this.startedAt = Date.now()
|
|
|
|
}
|
2021-11-25 03:15:50 +01:00
|
|
|
|
|
|
|
setComplete() {
|
|
|
|
this.finishedAt = Date.now()
|
|
|
|
this.elapsed = this.finishedAt - this.startedAt
|
|
|
|
}
|
2021-11-23 02:58:20 +01:00
|
|
|
}
|
|
|
|
module.exports = LibraryScan
|