Cleanup & start of abs metadata file

This commit is contained in:
advplyr 2022-02-10 17:05:15 -06:00
parent 8a0508342b
commit 30e0cc4c07
4 changed files with 41 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
})
}

View File

@ -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 + '/'