mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Add:Check metadata.abs file modified date to rescan
This commit is contained in:
parent
42604331ff
commit
74a68a4557
@ -546,10 +546,11 @@ class Audiobook {
|
||||
var currOtherFileNum = this.otherFiles.length
|
||||
|
||||
var otherFilenamesAlreadyInBook = this.otherFiles.map(ofile => ofile.filename)
|
||||
var alreadyHasAbsMetadata = otherFilenamesAlreadyInBook.includes('metadata.abs')
|
||||
var alreadyHasDescTxt = otherFilenamesAlreadyInBook.includes('desc.txt')
|
||||
var alreadyHasReaderTxt = otherFilenamesAlreadyInBook.includes('reader.txt')
|
||||
|
||||
var existingAbMetadata = this.otherFiles.find(file => file.filename === 'metadata.abs')
|
||||
|
||||
// Filter out other files no longer in directory
|
||||
var newOtherFilePaths = newOtherFiles.map(f => f.path)
|
||||
this.otherFiles = this.otherFiles.filter(f => newOtherFilePaths.includes(f.path))
|
||||
@ -580,9 +581,14 @@ class Audiobook {
|
||||
}
|
||||
|
||||
|
||||
// If metadata.abs is new then read it and set all defined keys (will overwrite)
|
||||
// If metadata.abs is new OR modified then read it and set all defined keys (will overwrite)
|
||||
var metadataAbs = newOtherFiles.find(file => file.filename === 'metadata.abs')
|
||||
if (metadataAbs && !alreadyHasAbsMetadata) {
|
||||
var shouldUpdateAbs = !!metadataAbs && (metadataAbs.modified || !existingAbMetadata)
|
||||
if (metadataAbs && metadataAbs.modified) {
|
||||
Logger.debug(`[Audiobook] metadata.abs file was modified for "${this.title}"`)
|
||||
}
|
||||
|
||||
if (shouldUpdateAbs) {
|
||||
var abmetadataText = await readTextFile(metadataAbs.fullPath)
|
||||
if (abmetadataText) {
|
||||
var metadataUpdateObject = abmetadataGenerator.parse(abmetadataText)
|
||||
@ -933,6 +939,12 @@ class Audiobook {
|
||||
var keysToCheck = ['filename', 'ext', 'mtimeMs', 'ctimeMs', 'birthtimeMs', 'size']
|
||||
keysToCheck.forEach((key) => {
|
||||
if (existingFile[key] !== fileFound[key]) {
|
||||
|
||||
// Add modified flag on file data object if exists and was changed
|
||||
if (key === 'mtimeMs' && existingFile[key]) {
|
||||
fileFound.modified = true
|
||||
}
|
||||
|
||||
existingFile[key] = fileFound[key]
|
||||
hasUpdated = true
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ class Scanner {
|
||||
|
||||
// Sync other files first so that local images are used as cover art
|
||||
// TODO: Cleanup other file sync
|
||||
var allOtherFiles = checkRes.newOtherFileData.concat(audiobook._otherFiles)
|
||||
var allOtherFiles = checkRes.newOtherFileData.concat(checkRes.existingOtherFileData)
|
||||
if (await audiobook.syncOtherFiles(allOtherFiles, this.db.serverSettings.scannerPreferOpfMetadata)) {
|
||||
hasUpdated = true
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ function generate(audiobook, outputPath) {
|
||||
}
|
||||
|
||||
return fs.writeFile(outputPath, fileString).then(() => {
|
||||
return filePerms(outputPath, 0o774, global.Uid, global.Gid).then(() => true)
|
||||
return filePerms(outputPath, 0o774, global.Uid, global.Gid, true).then((data) => true)
|
||||
}).catch((error) => {
|
||||
Logger.error(`[absMetaFileGenerator] Failed to save abs file`, error)
|
||||
return false
|
||||
|
@ -50,7 +50,7 @@ const chmodr = (p, mode, uid, gid, cb) => {
|
||||
// any error other than ENOTDIR means it's not readable, or
|
||||
// doesn't exist. give up.
|
||||
if (er && er.code !== 'ENOTDIR') return cb(er)
|
||||
if (er) {
|
||||
if (er) { // Is a file
|
||||
return fs.chmod(p, mode).then(() => {
|
||||
fs.chown(p, uid, gid, cb)
|
||||
})
|
||||
@ -77,9 +77,9 @@ const chmodr = (p, mode, uid, gid, cb) => {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = (path, mode, uid, gid) => {
|
||||
module.exports = (path, mode, uid, gid, silent = false) => {
|
||||
return new Promise((resolve) => {
|
||||
Logger.debug(`[FilePerms] Setting permission "${mode}" for uid ${uid} and gid ${gid} | "${path}"`)
|
||||
if (!silent) Logger.debug(`[FilePerms] Setting permission "${mode}" for uid ${uid} and gid ${gid} | "${path}"`)
|
||||
chmodr(path, mode, uid, gid, resolve)
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user