mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-02-03 08:49:40 +00:00
Change: Using posix file paths, Change: njodb version bump, Change: Ignore directories and files starting with . #169
This commit is contained in:
parent
36d7c04d21
commit
28ccd4e568
13 changed files with 201 additions and 196 deletions
|
|
@ -350,9 +350,9 @@ class Audiobook {
|
|||
if (this.otherFiles && this.otherFiles.length) {
|
||||
var imageFile = this.otherFiles.find(f => f.filetype === 'image')
|
||||
if (imageFile) {
|
||||
data.coverFullPath = Path.normalize(imageFile.fullPath)
|
||||
data.coverFullPath = imageFile.fullPath
|
||||
var relImagePath = imageFile.path.replace(this.path, '')
|
||||
data.cover = Path.normalize(Path.join(`/s/book/${this.id}`, relImagePath))
|
||||
data.cover = Path.posix.join(`/s/book/${this.id}`, relImagePath)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -366,10 +366,10 @@ class Audiobook {
|
|||
return false
|
||||
}
|
||||
var updateBookPayload = {}
|
||||
updateBookPayload.coverFullPath = Path.normalize(file.fullPath)
|
||||
updateBookPayload.coverFullPath = file.fullPath
|
||||
// Set ab local static path from file relative path
|
||||
var relImagePath = file.path.replace(this.path, '')
|
||||
updateBookPayload.cover = Path.normalize(Path.join(`/s/book/${this.id}`, relImagePath))
|
||||
updateBookPayload.cover = Path.posix.join(`/s/book/${this.id}`, relImagePath)
|
||||
return this.book.update(updateBookPayload)
|
||||
}
|
||||
|
||||
|
|
@ -556,23 +556,24 @@ class Audiobook {
|
|||
var oldFormat = this.book.cover
|
||||
|
||||
// Update book cover path to new format
|
||||
this.book.coverFullPath = Path.normalize(Path.join(this.fullPath, this.book.cover.substr(7)))
|
||||
this.book.cover = Path.normalize(coverStripped.replace(this.path, `/s/book/${this.id}`))
|
||||
this.book.coverFullPath = Path.join(this.fullPath, this.book.cover.substr(7)).replace(/\\/g, '/')
|
||||
this.book.cover = coverStripped.replace(this.path, `/s/book/${this.id}`)
|
||||
Logger.debug(`[Audiobook] updated book cover to new format "${oldFormat}" => "${this.book.cover}"`)
|
||||
}
|
||||
hasUpdates = true
|
||||
}
|
||||
|
||||
// Check if book was removed from book dir
|
||||
if (this.book.cover && this.book.cover.substr(1).startsWith('s\\book\\')) {
|
||||
var bookCoverPath = this.book.cover ? this.book.cover.replace(/\\/g, '/') : null
|
||||
if (bookCoverPath && bookCoverPath.startsWith('/s/book/')) {
|
||||
// Fixing old cover paths
|
||||
if (!this.book.coverFullPath) {
|
||||
this.book.coverFullPath = Path.normalize(Path.join(this.fullPath, this.book.cover.substr(`/s/book/${this.id}`.length)))
|
||||
this.book.coverFullPath = Path.join(this.fullPath, this.book.cover.substr(`/s/book/${this.id}`.length)).replace(/\\/g, '/').replace(/\/\//g, '/')
|
||||
Logger.debug(`[Audiobook] Metadata cover full path set "${this.book.coverFullPath}" for "${this.title}"`)
|
||||
hasUpdates = true
|
||||
}
|
||||
|
||||
var coverStillExists = imageFiles.find(f => f.fullPath === this.book.coverFullPath)
|
||||
var coverStillExists = imageFiles.find(f => comparePaths(f.fullPath, this.book.coverFullPath))
|
||||
if (!coverStillExists) {
|
||||
Logger.info(`[Audiobook] Local cover "${this.book.cover}" was removed | "${this.title}"`)
|
||||
this.book.removeCover()
|
||||
|
|
@ -580,14 +581,14 @@ class Audiobook {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.book.cover && this.book.cover.substr(1).startsWith('metadata')) {
|
||||
if (bookCoverPath && bookCoverPath.startsWith('/metadata')) {
|
||||
// Fixing old cover paths
|
||||
if (!this.book.coverFullPath) {
|
||||
this.book.coverFullPath = Path.normalize(Path.join(metadataPath, this.book.cover.substr('/metadata/'.length)))
|
||||
this.book.coverFullPath = Path.join(metadataPath, this.book.cover.substr('/metadata/'.length)).replace(/\\/g, '/').replace(/\/\//g, '/')
|
||||
Logger.debug(`[Audiobook] Metadata cover full path set "${this.book.coverFullPath}" for "${this.title}"`)
|
||||
hasUpdates = true
|
||||
}
|
||||
var coverStillExists = imageFiles.find(f => f.fullPath === this.book.coverFullPath)
|
||||
var coverStillExists = imageFiles.find(f => comparePaths(f.fullPath, this.book.coverFullPath))
|
||||
if (!coverStillExists) {
|
||||
Logger.info(`[Audiobook] Metadata cover "${this.book.cover}" was removed | "${this.title}"`)
|
||||
this.book.removeCover()
|
||||
|
|
@ -608,7 +609,7 @@ class Audiobook {
|
|||
// If no cover set and image file exists then use it
|
||||
if (!this.book.cover && imageFiles.length) {
|
||||
var imagePathRelativeToBook = imageFiles[0].path.replace(this.path, '')
|
||||
this.book.cover = Path.normalize(Path.join(`/s/book/${this.id}`, imagePathRelativeToBook))
|
||||
this.book.cover = Path.posix.join(`/s/book/${this.id}`, imagePathRelativeToBook)
|
||||
this.book.coverFullPath = imageFiles[0].fullPath
|
||||
Logger.info(`[Audiobook] Local cover was set to "${this.book.cover}" | "${this.title}"`)
|
||||
hasUpdates = true
|
||||
|
|
@ -733,7 +734,7 @@ class Audiobook {
|
|||
|
||||
var success = await extractCoverArt(audioFileWithCover.fullPath, coverFilePath)
|
||||
if (success) {
|
||||
var coverRelPath = Path.join(coverDirRelPath, coverFilename)
|
||||
var coverRelPath = Path.join(coverDirRelPath, coverFilename).replace(/\\/g, '/').replace(/\/\//g, '/')
|
||||
this.update({ book: { cover: coverRelPath } })
|
||||
return coverRelPath
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,18 +136,18 @@ class Book {
|
|||
update(payload) {
|
||||
var hasUpdates = false
|
||||
|
||||
// Normalize cover paths if passed
|
||||
// Clean cover paths if passed
|
||||
if (payload.cover) {
|
||||
if (!payload.cover.startsWith('http:') && !payload.cover.startsWith('https:')) {
|
||||
payload.cover = Path.normalize(payload.cover)
|
||||
if (payload.coverFullPath) payload.coverFullPath = Path.normalize(payload.coverFullPath)
|
||||
payload.cover = payload.cover.replace(/\\/g, '/')
|
||||
if (payload.coverFullPath) payload.coverFullPath = payload.coverFullPath.replace(/\\/g, '/')
|
||||
else {
|
||||
Logger.warn(`[Book] "${this.title}" updating book cover to "${payload.cover}" but no full path was passed`)
|
||||
}
|
||||
}
|
||||
} else if (payload.coverFullPath) {
|
||||
Logger.warn(`[Book] "${this.title}" updating book full cover path to "${payload.coverFullPath}" but no relative path was passed`)
|
||||
payload.coverFullPath = Path.normalize(payload.coverFullPath)
|
||||
payload.coverFullPath = payload.coverFullPath.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
for (const key in payload) {
|
||||
|
|
@ -191,8 +191,8 @@ class Book {
|
|||
updateCover(cover, coverFullPath) {
|
||||
if (!cover) return false
|
||||
if (!cover.startsWith('http:') && !cover.startsWith('https:')) {
|
||||
cover = Path.normalize(cover)
|
||||
this.coverFullPath = Path.normalize(coverFullPath)
|
||||
cover = cover.replace(/\\/g, '/')
|
||||
this.coverFullPath = coverFullPath.replace(/\\/g, '/')
|
||||
} else {
|
||||
this.coverFullPath = cover
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue