mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-21 16:39:13 +02:00
Update:Check if directory already exists before upload #1497
This commit is contained in:
parent
0678c26627
commit
9712bdf5f0
5 changed files with 61 additions and 12 deletions
|
@ -1,27 +1,50 @@
|
|||
const Logger = require('../Logger')
|
||||
const Path = require('path')
|
||||
const Logger = require('../Logger')
|
||||
const fs = require('../libs/fsExtra')
|
||||
|
||||
class FileSystemController {
|
||||
constructor() { }
|
||||
|
||||
async getPaths(req, res) {
|
||||
var excludedDirs = ['node_modules', 'client', 'server', '.git', 'static', 'build', 'dist', 'metadata', 'config', 'sys', 'proc'].map(dirname => {
|
||||
if (!req.user.isAdminOrUp) {
|
||||
Logger.error(`[FileSystemController] Non-admin user attempting to get filesystem paths`, req.user)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
const excludedDirs = ['node_modules', 'client', 'server', '.git', 'static', 'build', 'dist', 'metadata', 'config', 'sys', 'proc'].map(dirname => {
|
||||
return Path.sep + dirname
|
||||
})
|
||||
|
||||
// Do not include existing mapped library paths in response
|
||||
this.db.libraries.forEach(lib => {
|
||||
lib.folders.forEach((folder) => {
|
||||
var dir = folder.fullPath
|
||||
let dir = folder.fullPath
|
||||
if (dir.includes(global.appRoot)) dir = dir.replace(global.appRoot, '')
|
||||
excludedDirs.push(dir)
|
||||
})
|
||||
})
|
||||
|
||||
Logger.debug(`[Server] get file system paths, excluded: ${excludedDirs.join(', ')}`)
|
||||
res.json({
|
||||
directories: await this.getDirectories(global.appRoot, '/', excludedDirs)
|
||||
})
|
||||
}
|
||||
|
||||
// POST: api/filesystem/pathexists
|
||||
async checkPathExists(req, res) {
|
||||
if (!req.user.canUpload) {
|
||||
Logger.error(`[FileSystemController] Non-admin user attempting to check path exists`, req.user)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
const filepath = req.body.filepath
|
||||
if (!filepath?.length) {
|
||||
return res.sendStatus(400)
|
||||
}
|
||||
|
||||
const exists = await fs.pathExists(filepath)
|
||||
res.json({
|
||||
exists
|
||||
})
|
||||
}
|
||||
}
|
||||
module.exports = new FileSystemController()
|
Loading…
Add table
Add a link
Reference in a new issue