Added deviceId in addition to inode to uniquely identify files

This commit is contained in:
Jason Axley 2025-08-15 09:09:06 -07:00
parent d8f07eb956
commit 3a4aacb7bf
17 changed files with 1445 additions and 227 deletions

View file

@ -6,6 +6,7 @@ class AudioFile {
constructor(data) {
this.index = null
this.ino = null
this.deviceId = null
/** @type {FileMetadata} */
this.metadata = null
this.addedAt = null
@ -44,6 +45,7 @@ class AudioFile {
return {
index: this.index,
ino: this.ino,
deviceId: this.deviceId,
metadata: this.metadata.toJSON(),
addedAt: this.addedAt,
updatedAt: this.updatedAt,
@ -72,6 +74,7 @@ class AudioFile {
construct(data) {
this.index = data.index
this.ino = data.ino
this.deviceId = data.dev
this.metadata = new FileMetadata(data.metadata || {})
this.addedAt = data.addedAt
this.updatedAt = data.updatedAt
@ -112,6 +115,7 @@ class AudioFile {
// New scanner creates AudioFile from AudioFileScanner
setDataFromProbe(libraryFile, probeData) {
this.ino = libraryFile.ino || null
this.deviceId = libraryFile.deviceId || null
if (libraryFile.metadata instanceof FileMetadata) {
this.metadata = libraryFile.metadata.clone()
@ -137,7 +141,7 @@ class AudioFile {
syncChapters(updatedChapters) {
if (this.chapters.length !== updatedChapters.length) {
this.chapters = updatedChapters.map(ch => ({ ...ch }))
this.chapters = updatedChapters.map((ch) => ({ ...ch }))
return true
} else if (updatedChapters.length === 0) {
if (this.chapters.length > 0) {
@ -154,7 +158,7 @@ class AudioFile {
}
}
if (hasUpdates) {
this.chapters = updatedChapters.map(ch => ({ ...ch }))
this.chapters = updatedChapters.map((ch) => ({ ...ch }))
}
return hasUpdates
}
@ -164,8 +168,8 @@ class AudioFile {
}
/**
*
* @param {AudioFile} scannedAudioFile
*
* @param {AudioFile} scannedAudioFile
* @returns {boolean} true if updates were made
*/
updateFromScan(scannedAudioFile) {
@ -196,4 +200,4 @@ class AudioFile {
return hasUpdated
}
}
module.exports = AudioFile
module.exports = AudioFile