Cleanup and remove more vars

This commit is contained in:
advplyr 2022-12-26 16:08:53 -06:00
parent 45c9038954
commit 775dedc338
5 changed files with 18 additions and 33 deletions

View File

@ -198,7 +198,7 @@ class LibraryItem {
this.libraryFiles = payload.libraryFiles.map(lf => lf.clone())
// Use first image library file as cover
var firstImageFile = this.libraryFiles.find(lf => lf.fileType === 'image')
const firstImageFile = this.libraryFiles.find(lf => lf.fileType === 'image')
if (firstImageFile) this.media.coverPath = firstImageFile.metadata.path
} else if (this[key] !== undefined && key !== 'media') {
this[key] = payload[key]
@ -214,8 +214,8 @@ class LibraryItem {
}
update(payload) {
var json = this.toJSON()
var hasUpdates = false
const json = this.toJSON()
let hasUpdates = false
for (const key in json) {
if (payload[key] !== undefined) {
if (key === 'media') {
@ -259,10 +259,10 @@ class LibraryItem {
// Returns null if file not found, true if file was updated, false if up to date
// updates existing LibraryFile, AudioFile, EBookFile's
checkFileFound(fileFound) {
var hasUpdated = false
let hasUpdated = false
var existingFile = this.libraryFiles.find(lf => lf.ino === fileFound.ino)
var mediaFile = null
let existingFile = this.libraryFiles.find(lf => lf.ino === fileFound.ino)
let mediaFile = null
if (!existingFile) {
existingFile = this.libraryFiles.find(lf => lf.metadata.path === fileFound.metadata.path)
if (existingFile) {
@ -315,7 +315,7 @@ class LibraryItem {
// Data pulled from scandir during a scan, check it with current data
checkScanData(dataFound) {
var hasUpdated = false
let hasUpdated = false
if (this.isMissing) {
// Item no longer missing
@ -498,7 +498,7 @@ class LibraryItem {
removeLibraryFile(ino) {
if (!ino) return false
var libraryFile = this.libraryFiles.find(lf => lf.ino === ino)
const libraryFile = this.libraryFiles.find(lf => lf.ino === ino)
if (libraryFile) {
this.libraryFiles = this.libraryFiles.filter(lf => lf.ino !== ino)
this.updatedAt = Date.now()

View File

@ -40,7 +40,7 @@ class Author {
}
toJSONExpanded(numBooks = 0) {
var json = this.toJSON()
const json = this.toJSON()
json.numBooks = numBooks
return json
}
@ -63,11 +63,11 @@ class Author {
}
update(payload) {
var json = this.toJSON()
const json = this.toJSON()
delete json.id
delete json.addedAt
delete json.updatedAt
var hasUpdates = false
let hasUpdates = false
for (const key in json) {
if (payload[key] !== undefined && json[key] != payload[key]) {
this[key] = payload[key]

View File

@ -92,7 +92,7 @@ class PodcastEpisode {
}
get audioTrack() {
var audioTrack = new AudioTrack()
const audioTrack = new AudioTrack()
audioTrack.setData(this.libraryItemId, this.audioFile, 0)
return audioTrack
}
@ -133,7 +133,7 @@ class PodcastEpisode {
}
update(payload) {
var hasUpdates = false
let hasUpdates = false
for (const key in this.toJSON()) {
if (payload[key] != undefined && payload[key] != this[key]) {
this[key] = payload[key]

View File

@ -50,7 +50,7 @@ class Series {
update(series) {
if (!series) return false
const keysToUpdate = ['name', 'description']
var hasUpdated = false
let hasUpdated = false
for (const key of keysToUpdate) {
if (series[key] !== undefined && series[key] !== this[key]) {
this[key] = series[key]

View File

@ -102,7 +102,7 @@ class AudioFile {
}
get mimeType() {
var format = this.metadata.format.toUpperCase()
const format = this.metadata.format.toUpperCase()
if (AudioMimeType[format]) {
return AudioMimeType[format]
} else {
@ -147,7 +147,7 @@ class AudioFile {
return false
}
var hasUpdates = false
let hasUpdates = false
for (let i = 0; i < updatedChapters.length; i++) {
if (JSON.stringify(updatedChapters[i]) !== JSON.stringify(this.chapters[i])) {
hasUpdates = true
@ -163,25 +163,10 @@ class AudioFile {
return new AudioFile(this.toJSON())
}
// If the file or parent directory was renamed it is synced here
syncFile(newFile) {
// TODO: Sync file would update the file info if needed
return false
// var hasUpdates = false
// var keysToSync = ['path', 'relPath', 'ext', 'filename']
// keysToSync.forEach((key) => {
// if (newFile[key] !== undefined && newFile[key] !== this[key]) {
// hasUpdates = true
// this[key] = newFile[key]
// }
// })
// return hasUpdates
}
updateFromScan(scannedAudioFile) {
var hasUpdated = false
let hasUpdated = false
var newjson = scannedAudioFile.toJSON()
const newjson = scannedAudioFile.toJSON()
if (this.manuallyVerified) newjson.manuallyVerified = true
if (this.exclude) newjson.exclude = true
newjson.addedAt = this.addedAt