From 775dedc3388f2ee8ad464a2df0df96f636497d95 Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 26 Dec 2022 16:08:53 -0600 Subject: [PATCH] Cleanup and remove more vars --- server/objects/LibraryItem.js | 16 ++++++++-------- server/objects/entities/Author.js | 6 +++--- server/objects/entities/PodcastEpisode.js | 4 ++-- server/objects/entities/Series.js | 2 +- server/objects/files/AudioFile.js | 23 ++++------------------- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/server/objects/LibraryItem.js b/server/objects/LibraryItem.js index 382f312f..95674288 100644 --- a/server/objects/LibraryItem.js +++ b/server/objects/LibraryItem.js @@ -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() diff --git a/server/objects/entities/Author.js b/server/objects/entities/Author.js index 179b92bd..9684eebb 100644 --- a/server/objects/entities/Author.js +++ b/server/objects/entities/Author.js @@ -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] diff --git a/server/objects/entities/PodcastEpisode.js b/server/objects/entities/PodcastEpisode.js index d86855cb..b6363189 100644 --- a/server/objects/entities/PodcastEpisode.js +++ b/server/objects/entities/PodcastEpisode.js @@ -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] diff --git a/server/objects/entities/Series.js b/server/objects/entities/Series.js index 0f74c503..702f41f5 100644 --- a/server/objects/entities/Series.js +++ b/server/objects/entities/Series.js @@ -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] diff --git a/server/objects/files/AudioFile.js b/server/objects/files/AudioFile.js index 683834ec..46d6666a 100644 --- a/server/objects/files/AudioFile.js +++ b/server/objects/files/AudioFile.js @@ -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