mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Fix: set downloaded/uploaded cover owner and permissions and if creating intitial config/metadata directories at startup then set owner of those #394
This commit is contained in:
parent
e253939c1e
commit
dcd4f69383
@ -10,6 +10,7 @@ const { version } = require('../package.json')
|
|||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
const dbMigration = require('./utils/dbMigration')
|
const dbMigration = require('./utils/dbMigration')
|
||||||
|
const filePerms = require('./utils/filePerms')
|
||||||
const Logger = require('./Logger')
|
const Logger = require('./Logger')
|
||||||
|
|
||||||
// Classes
|
// Classes
|
||||||
@ -46,9 +47,18 @@ class Server {
|
|||||||
global.MetadataPath = global.MetadataPath.replace(/\\/g, '/')
|
global.MetadataPath = global.MetadataPath.replace(/\\/g, '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.ensureDirSync(global.ConfigPath, 0o774)
|
if (!fs.pathExistsSync(global.ConfigPath)) {
|
||||||
fs.ensureDirSync(global.MetadataPath, 0o774)
|
fs.mkdirSync(global.ConfigPath)
|
||||||
fs.ensureDirSync(global.AudiobookPath, 0o774)
|
filePerms.setDefaultDirSync(global.ConfigPath, false)
|
||||||
|
}
|
||||||
|
if (!fs.pathExistsSync(global.MetadataPath)) {
|
||||||
|
fs.mkdirSync(global.MetadataPath)
|
||||||
|
filePerms.setDefaultDirSync(global.MetadataPath, false)
|
||||||
|
}
|
||||||
|
if (!fs.pathExistsSync(global.AudiobookPath)) {
|
||||||
|
fs.mkdirSync(global.AudiobookPath)
|
||||||
|
filePerms.setDefaultDirSync(global.AudiobookPath, false)
|
||||||
|
}
|
||||||
|
|
||||||
this.db = new Db()
|
this.db = new Db()
|
||||||
this.watcher = new Watcher()
|
this.watcher = new Watcher()
|
||||||
|
@ -113,6 +113,7 @@ class CoverManager {
|
|||||||
|
|
||||||
Logger.info(`[CoverManager] Uploaded libraryItem cover "${coverFullPath}" for "${libraryItem.media.metadata.title}"`)
|
Logger.info(`[CoverManager] Uploaded libraryItem cover "${coverFullPath}" for "${libraryItem.media.metadata.title}"`)
|
||||||
|
|
||||||
|
await filePerms.setDefault(coverFullPath)
|
||||||
libraryItem.updateMediaCover(coverFullPath)
|
libraryItem.updateMediaCover(coverFullPath)
|
||||||
return {
|
return {
|
||||||
cover: coverFullPath
|
cover: coverFullPath
|
||||||
@ -151,6 +152,7 @@ class CoverManager {
|
|||||||
|
|
||||||
Logger.info(`[CoverManager] Downloaded libraryItem cover "${coverFullPath}" from url "${url}" for "${libraryItem.media.metadata.title}"`)
|
Logger.info(`[CoverManager] Downloaded libraryItem cover "${coverFullPath}" from url "${url}" for "${libraryItem.media.metadata.title}"`)
|
||||||
|
|
||||||
|
await filePerms.setDefault(coverFullPath)
|
||||||
libraryItem.updateMediaCover(coverFullPath)
|
libraryItem.updateMediaCover(coverFullPath)
|
||||||
return {
|
return {
|
||||||
cover: coverFullPath
|
cover: coverFullPath
|
||||||
@ -250,6 +252,8 @@ class CoverManager {
|
|||||||
|
|
||||||
var success = await extractCoverArt(audioFileWithCover.metadata.path, coverFilePath)
|
var success = await extractCoverArt(audioFileWithCover.metadata.path, coverFilePath)
|
||||||
if (success) {
|
if (success) {
|
||||||
|
await filePerms.setDefault(coverFilePath)
|
||||||
|
|
||||||
libraryItem.updateMediaCover(coverFilePath)
|
libraryItem.updateMediaCover(coverFilePath)
|
||||||
return coverFilePath
|
return coverFilePath
|
||||||
}
|
}
|
||||||
|
@ -94,4 +94,21 @@ module.exports.setDefault = (path, silent = false) => {
|
|||||||
if (!silent) Logger.debug(`[FilePerms] Setting permission "${mode}" for uid ${uid} and gid ${gid} | "${path}"`)
|
if (!silent) Logger.debug(`[FilePerms] Setting permission "${mode}" for uid ${uid} and gid ${gid} | "${path}"`)
|
||||||
chmodr(path, mode, uid, gid, resolve)
|
chmodr(path, mode, uid, gid, resolve)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default permissions 0o744 and global Uid/Gid
|
||||||
|
// Used for setting default permission to initial config/metadata directories
|
||||||
|
module.exports.setDefaultDirSync = (path, silent = false) => {
|
||||||
|
const mode = 0o744
|
||||||
|
const uid = global.Uid
|
||||||
|
const gid = global.Gid
|
||||||
|
if (!silent) Logger.debug(`[FilePerms] Setting dir permission "${mode}" for uid ${uid} and gid ${gid} | "${path}"`)
|
||||||
|
try {
|
||||||
|
fs.chmodSync(path, mode)
|
||||||
|
fs.chownSync(path, uid, gid)
|
||||||
|
return true
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(`[FilePerms] Error setting dir permissions for path "${path}"`, error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user