mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-11-30 12:14:06 +01:00
Merge pull request #5586 from binyaminyblatt/missing_declaration
fix: resolve ReferenceErrors in scandir.js under strict mode
This commit is contained in:
5 files changed
+32
-29
No files matched your search
@@ -15,20 +15,23 @@ module.exports = (function () {
|
||||
proc.stdout.setEncoding('utf8')
|
||||
proc.stderr.setEncoding('utf8')
|
||||
|
||||
proc.stdout.on('data', function (data) { probeData.push(data) })
|
||||
proc.stderr.on('data', function (data) { errData.push(data) })
|
||||
proc.stdout.on('data', function (data) {
|
||||
probeData.push(data)
|
||||
})
|
||||
proc.stderr.on('data', function (data) {
|
||||
errData.push(data)
|
||||
})
|
||||
|
||||
proc.on('exit', code => { exitCode = code })
|
||||
proc.on('error', err => reject(err))
|
||||
proc.on('error', (err) => reject(err))
|
||||
proc.on('close', () => {
|
||||
try {
|
||||
resolve(JSON.parse(probeData.join('')))
|
||||
resolve(JSON.parse(probeData.join('')))
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return doProbe
|
||||
})()
|
||||
})()
|
||||
@@ -112,7 +112,7 @@ class BackupManager {
|
||||
.mv(tempPath)
|
||||
.then(() => true)
|
||||
.catch((error) => {
|
||||
Logger.error('[BackupManager] Failed to move backup file', path, error)
|
||||
Logger.error('[BackupManager] Failed to move backup file', tempPath, error)
|
||||
return false
|
||||
})
|
||||
if (!success) {
|
||||
|
||||
@@ -369,8 +369,8 @@ class BinaryManager {
|
||||
* @param {Binary} binary
|
||||
*/
|
||||
async removeBinary(destination, binary) {
|
||||
const binaryPath = path.join(destination, binary.fileName)
|
||||
try {
|
||||
const binaryPath = path.join(destination, binary.fileName)
|
||||
if (await fs.pathExists(binaryPath)) {
|
||||
Logger.debug(`[BinaryManager] Removing binary: ${binaryPath}`)
|
||||
await fs.remove(binaryPath)
|
||||
|
||||
@@ -69,7 +69,7 @@ function extractStringOrStringify(json) {
|
||||
return json[Object.keys(json)[0]][0]
|
||||
}
|
||||
// Handles case where html was included without being wrapped in CDATA
|
||||
return JSON.stringify(value)
|
||||
return JSON.stringify(json)
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
|
||||
+19
-19
@@ -149,16 +149,16 @@ module.exports.buildLibraryFile = buildLibraryFile
|
||||
function getBookDataFromDir(relPath, parseSubtitle = false) {
|
||||
const splitDir = relPath.split('/')
|
||||
|
||||
var folder = splitDir.pop() // Audio files will always be in the directory named for the title
|
||||
series = splitDir.length > 1 ? splitDir.pop() : null // If there are at least 2 more directories, next furthest will be the series
|
||||
author = splitDir.length > 0 ? splitDir.pop() : null // There could be many more directories, but only the top 3 are used for naming /author/series/title/
|
||||
const titleFolder = splitDir.pop() // Audio files will always be in the directory named for the title
|
||||
const series = splitDir.length > 1 ? splitDir.pop() : null // If there are at least 2 more directories, next furthest will be the series
|
||||
const author = splitDir.length > 0 ? splitDir.pop() : null // There could be many more directories, but only the top 3 are used for naming /author/series/title/
|
||||
|
||||
// The may contain various other pieces of metadata, these functions extract it.
|
||||
var [folder, asin] = getASIN(folder)
|
||||
var [folder, narrators] = getNarrator(folder)
|
||||
var [folder, sequence] = series ? getSequence(folder) : [folder, null]
|
||||
var [folder, publishedYear] = getPublishedYear(folder)
|
||||
var [title, subtitle] = parseSubtitle ? getSubtitle(folder) : [folder, null]
|
||||
// Each extractor strips one piece of metadata and returns the remaining folder name.
|
||||
const [afterAsin, asin] = getASIN(titleFolder)
|
||||
const [afterNarrators, narrators] = getNarrator(afterAsin)
|
||||
const [afterSequence, sequence] = series ? getSequence(afterNarrators) : [afterNarrators, null]
|
||||
const [afterYear, publishedYear] = getPublishedYear(afterSequence)
|
||||
const [title, subtitle] = parseSubtitle ? getSubtitle(afterYear) : [afterYear, null]
|
||||
|
||||
return {
|
||||
title,
|
||||
@@ -180,8 +180,8 @@ module.exports.getBookDataFromDir = getBookDataFromDir
|
||||
* @returns {[string, string]} [folder, narrator]
|
||||
*/
|
||||
function getNarrator(folder) {
|
||||
let pattern = /^(?<title>.*) \{(?<narrators>.*)\}$/
|
||||
let match = folder.match(pattern)
|
||||
const pattern = /^(?<title>.*) \{(?<narrators>.*)\}$/
|
||||
const match = folder.match(pattern)
|
||||
return match ? [match.groups.title, match.groups.narrators] : [folder, null]
|
||||
}
|
||||
|
||||
@@ -204,12 +204,12 @@ function getNarrator(folder) {
|
||||
*/
|
||||
function getSequence(folder) {
|
||||
// Matches a valid volume string. Also matches a book whose title starts with a 1 to 3 digit number. Will handle that later.
|
||||
let pattern = /^(?<volumeLabel>vol\.? |volume |book )?(?<sequence>\d{0,3}(?:\.\d{1,2})?)(?<trailingDot>\.?)(?: (?<suffix>.*))?$/i
|
||||
const pattern = /^(?<volumeLabel>vol\.? |volume |book )?(?<sequence>\d{0,3}(?:\.\d{1,2})?)(?<trailingDot>\.?)(?: (?<suffix>.*))?$/i
|
||||
|
||||
let volumeNumber = null
|
||||
let parts = folder.split(' - ')
|
||||
const parts = folder.split(' - ')
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
let match = parts[i].match(pattern)
|
||||
const match = parts[i].match(pattern)
|
||||
// This excludes '101 Dalmations' but includes '101. Dalmations'
|
||||
if (match && !(match.groups.suffix && !(match.groups.volumeLabel || match.groups.trailingDot))) {
|
||||
volumeNumber = isNaN(match.groups.sequence) ? match.groups.sequence : Number(match.groups.sequence).toString()
|
||||
@@ -232,10 +232,10 @@ function getSequence(folder) {
|
||||
* @returns {[string, string]} [folder, publishedYear]
|
||||
*/
|
||||
function getPublishedYear(folder) {
|
||||
var publishedYear = null
|
||||
let publishedYear = null
|
||||
|
||||
pattern = /^ *\(?([0-9]{4})\)? * - *(.+)/ //Matches #### - title or (####) - title
|
||||
var match = folder.match(pattern)
|
||||
const pattern = /^ *\(?([0-9]{4})\)? * - *(.+)/ //Matches #### - title or (####) - title
|
||||
const match = folder.match(pattern)
|
||||
if (match) {
|
||||
publishedYear = match[1]
|
||||
folder = match[2]
|
||||
@@ -252,7 +252,7 @@ function getPublishedYear(folder) {
|
||||
*/
|
||||
function getSubtitle(folder) {
|
||||
// Subtitle is everything after " - "
|
||||
var splitTitle = folder.split(' - ')
|
||||
const splitTitle = folder.split(' - ')
|
||||
return [splitTitle.shift(), splitTitle.join(' - ')]
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ function getSubtitle(folder) {
|
||||
function getASIN(folder) {
|
||||
let asin = null
|
||||
|
||||
let pattern = /(?: |^)\[([A-Z0-9]{10})](?= |$)/ // Matches "[B0015T963C]"
|
||||
const pattern = /(?: |^)\[([A-Z0-9]{10})](?= |$)/ // Matches "[B0015T963C]"
|
||||
const match = folder.match(pattern)
|
||||
if (match) {
|
||||
asin = match[1]
|
||||
|
||||
Reference in new issue
Block a user