mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Add API to update a path on a watched library folder
This commit is contained in:
		
							parent
							
								
									0ee6336b02
								
							
						
					
					
						commit
						e054b9a54c
					
				@ -527,6 +527,54 @@ class MiscController {
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
  * POST: /api/watcher/update
 | 
			
		||||
  * Update a watch path
 | 
			
		||||
  * Req.body { libraryId, path, type, [oldPath] } 
 | 
			
		||||
  * type = add, unlink, rename
 | 
			
		||||
  * oldPath = required only for rename
 | 
			
		||||
  * @param {*} req 
 | 
			
		||||
  * @param {*} res 
 | 
			
		||||
  */
 | 
			
		||||
  updateWatchedPath(req, res) {
 | 
			
		||||
    if (!req.user.isAdminOrUp) {
 | 
			
		||||
      Logger.error(`[MiscController] Non-admin user attempted to updateWatchedPath`)
 | 
			
		||||
      return res.sendStatus(404)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const libraryId = req.body.libraryId
 | 
			
		||||
    const path = req.body.path
 | 
			
		||||
    const type = req.body.type
 | 
			
		||||
    if (!libraryId || !path || !type) {
 | 
			
		||||
      Logger.error(`[MiscController] Invalid request body for updateWatchedPath. libraryId: "${libraryId}", path: "${path}", type: "${type}"`)
 | 
			
		||||
      return res.sendStatus(400)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    switch (type) {
 | 
			
		||||
      case 'add':
 | 
			
		||||
        this.watcher.onNewFile(libraryId, path)
 | 
			
		||||
        break;
 | 
			
		||||
      case 'unlink':
 | 
			
		||||
        this.watcher.onFileRemoved(libraryId, path)
 | 
			
		||||
        break;
 | 
			
		||||
      case 'rename':
 | 
			
		||||
        const oldPath = req.body.oldPath
 | 
			
		||||
        if (!oldPath) {
 | 
			
		||||
          Logger.error(`[MiscController] Invalid request body for updateWatchedPath. oldPath is required for rename.`)
 | 
			
		||||
          return res.sendStatus(400)
 | 
			
		||||
        }
 | 
			
		||||
        this.watcher.onRename(libraryId, oldPath, path)
 | 
			
		||||
        break;
 | 
			
		||||
      default:
 | 
			
		||||
        Logger.error(`[MiscController] Invalid type for updateWatchedPath. type: "${type}"`)
 | 
			
		||||
        return res.sendStatus(400)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    res.sendStatus(200)
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  validateCronExpression(req, res) {
 | 
			
		||||
    const expression = req.body.expression
 | 
			
		||||
    if (!expression) {
 | 
			
		||||
 | 
			
		||||
@ -308,6 +308,7 @@ class ApiRouter {
 | 
			
		||||
    this.router.post('/genres/rename', MiscController.renameGenre.bind(this))
 | 
			
		||||
    this.router.delete('/genres/:genre', MiscController.deleteGenre.bind(this))
 | 
			
		||||
    this.router.post('/validate-cron', MiscController.validateCronExpression.bind(this))
 | 
			
		||||
    this.router.post('/watcher/update', MiscController.updateWatchedPath.bind(this))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async getDirectories(dir, relpath, excludedDirs, level = 0) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user