mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-15 00:09:38 +00:00
narrator filter, no series filter, full paths toggle, book landing page details, new sans font, update query string on filter/sort, persist experimental feature flag, batch edit redirect bug, upload file permissions and owner
This commit is contained in:
parent
75aede914f
commit
f752c19418
36 changed files with 454 additions and 230 deletions
85
server/utils/filePerms.js
Normal file
85
server/utils/filePerms.js
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
const fs = require('fs-extra')
|
||||
const Path = require('path')
|
||||
const Logger = require('../Logger')
|
||||
|
||||
// Modified from:
|
||||
// https://github.com/isaacs/chmodr/blob/master/chmodr.js
|
||||
|
||||
// If a party has r, add x
|
||||
// so that dirs are listable
|
||||
const dirMode = mode => {
|
||||
if (mode & 0o400)
|
||||
mode |= 0o100
|
||||
if (mode & 0o40)
|
||||
mode |= 0o10
|
||||
if (mode & 0o4)
|
||||
mode |= 0o1
|
||||
return mode
|
||||
}
|
||||
|
||||
const chmodrKid = (p, child, mode, uid, gid, cb) => {
|
||||
if (typeof child === 'string')
|
||||
return fs.lstat(Path.resolve(p, child), (er, stats) => {
|
||||
if (er)
|
||||
return cb(er)
|
||||
stats.name = child
|
||||
chmodrKid(p, stats, mode, uid, gid, cb)
|
||||
})
|
||||
|
||||
if (child.isDirectory()) {
|
||||
chmodr(Path.resolve(p, child.name), mode, uid, gid, er => {
|
||||
if (er)
|
||||
return cb(er)
|
||||
|
||||
var _path = Path.resolve(p, child.name)
|
||||
fs.chmod(_path, dirMode(mode)).then(() => {
|
||||
fs.chown(_path, uid, gid, cb)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
var _path = Path.resolve(p, child.name)
|
||||
fs.chmod(_path, mode).then(() => {
|
||||
fs.chown(_path, uid, gid, cb)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const chmodr = (p, mode, uid, gid, cb) => {
|
||||
fs.readdir(p, { withFileTypes: true }, (er, children) => {
|
||||
// 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) {
|
||||
return fs.chmod(p, mode).then(() => {
|
||||
fs.chown(p, uid, gid, cb)
|
||||
})
|
||||
}
|
||||
if (!children.length) {
|
||||
return fs.chmod(p, dirMode(mode)).then(() => {
|
||||
fs.chown(p, uid, gid, cb)
|
||||
})
|
||||
}
|
||||
|
||||
let len = children.length
|
||||
let errState = null
|
||||
const then = er => {
|
||||
if (errState) return
|
||||
if (er) return cb(errState = er)
|
||||
if (--len === 0) {
|
||||
return fs.chmod(p, dirMode(mode)).then(() => {
|
||||
fs.chown(p, uid, gid, cb)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
children.forEach(child => chmodrKid(p, child, mode, uid, gid, then))
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = (p, 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)
|
||||
})
|
||||
}
|
||||
|
|
@ -75,4 +75,14 @@ function secondsToTimestamp(seconds) {
|
|||
}
|
||||
return `${_hours}:${_minutes.toString().padStart(2, '0')}:${_seconds.toString().padStart(2, '0')}`
|
||||
}
|
||||
module.exports.secondsToTimestamp = secondsToTimestamp
|
||||
module.exports.secondsToTimestamp = secondsToTimestamp
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ async function generate(audiobook, nfoFilename = 'metadata.nfo') {
|
|||
'Title': book.title,
|
||||
'Subtitle': book.subtitle,
|
||||
'Author': book.author,
|
||||
'Narrator': book.narrarator,
|
||||
'Narrator': book.narrator,
|
||||
'Series': book.series,
|
||||
'Volume Number': book.volumeNumber,
|
||||
'Publish Year': book.publishYear,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue