diff --git a/server/objects/Book.js b/server/objects/Book.js index 3bf149ac..6023feea 100644 --- a/server/objects/Book.js +++ b/server/objects/Book.js @@ -47,6 +47,7 @@ class Book { get _language() { return this.language || '' } get _isbn() { return this.isbn || '' } get _asin() { return this.asin || '' } + get genresCommaSeparated() { return this._genres.join(', ') } get shouldSearchForCover() { if (this.cover) return false diff --git a/server/utils/absFileGenerator.js b/server/utils/absFileGenerator.js new file mode 100644 index 00000000..a74d78e2 --- /dev/null +++ b/server/utils/absFileGenerator.js @@ -0,0 +1,37 @@ +const fs = require('fs-extra') +const filePerms = require('./filePerms') +const package = require('../../package.json') +const Logger = require('../Logger') + +const bookKeyMap = { + title: 'title', + subtitle: 'subtitle', + author: 'authorFL', + narrator: 'narratorFL', + series: 'series', + volumeNumber: 'volumeNumber', + publishYear: 'publishYear', + publisher: 'publisher', + description: 'description', + isbn: 'isbn', + asin: 'asin', + language: 'language', + genres: 'genresCommaSeparated' +} + +function generate(audiobook, outputPath, uid, gid) { + var fileString = `[audiobookshelf v${package.version}]\n` + + for (const key in bookKeyMap) { + const value = audiobook.book[bookKeyMap[key]] || '' + fileString += `${key}=${value}\n` + } + + return fs.writeFile(outputPath, fileString).then(() => { + return filePerms(outputPath, 0o774, uid, gid).then(() => true) + }).catch((error) => { + Logger.error(`[absMetaFileGenerator] Failed to save abs file`, error) + return false + }) +} +module.exports.generate = generate \ No newline at end of file diff --git a/server/utils/filePerms.js b/server/utils/filePerms.js index 531e224d..4b64851a 100644 --- a/server/utils/filePerms.js +++ b/server/utils/filePerms.js @@ -77,9 +77,9 @@ const chmodr = (p, mode, uid, gid, cb) => { }) } -module.exports = (p, mode, uid, gid) => { +module.exports = (path, mode, uid, gid) => { return new Promise((resolve) => { - Logger.debug(`[FilePerms] Setting permission "${mode}" for uid ${uid} and gid ${gid} | "${p}"`) - chmodr(p, mode, uid, gid, resolve) + Logger.debug(`[FilePerms] Setting permission "${mode}" for uid ${uid} and gid ${gid} | "${path}"`) + chmodr(path, mode, uid, gid, resolve) }) } \ No newline at end of file diff --git a/server/utils/fileUtils.js b/server/utils/fileUtils.js index 2876a562..44288e81 100644 --- a/server/utils/fileUtils.js +++ b/server/utils/fileUtils.js @@ -51,16 +51,6 @@ function bytesPretty(bytes, decimals = 0) { } module.exports.bytesPretty = bytesPretty -function setFileOwner(path, uid, gid) { - try { - return fs.chown(path, uid, gid).then(() => true) - } catch (err) { - console.error('Failed set file owner', err) - return false - } -} -module.exports.setFileOwner = setFileOwner - async function recurseFiles(path, relPathToReplace = null) { path = path.replace(/\\/g, '/') if (!path.endsWith('/')) path = path + '/'