mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Add:Ability to ignore directories by putting a file named .ignore inside dir #516
This commit is contained in:
		
							parent
							
								
									2cc055a1ad
								
							
						
					
					
						commit
						0a73dd6437
					
				@ -1,6 +1,7 @@
 | 
				
			|||||||
const fs = require('fs-extra')
 | 
					const fs = require('fs-extra')
 | 
				
			||||||
const rra = require('recursive-readdir-async')
 | 
					const rra = require('recursive-readdir-async')
 | 
				
			||||||
const axios = require('axios')
 | 
					const axios = require('axios')
 | 
				
			||||||
 | 
					const Path = require('path')
 | 
				
			||||||
const Logger = require('../Logger')
 | 
					const Logger = require('../Logger')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getFileStat(path) {
 | 
					async function getFileStat(path) {
 | 
				
			||||||
@ -104,20 +105,39 @@ async function recurseFiles(path, relPathToReplace = null) {
 | 
				
			|||||||
    return []
 | 
					    return []
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const directoriesToIgnore = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  list = list.filter((item) => {
 | 
					  list = list.filter((item) => {
 | 
				
			||||||
    if (item.error) {
 | 
					    if (item.error) {
 | 
				
			||||||
      Logger.error(`[fileUtils] Recurse files file "${item.fullName}" has error`, item.error)
 | 
					      Logger.error(`[fileUtils] Recurse files file "${item.fullname}" has error`, item.error)
 | 
				
			||||||
 | 
					      return false
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var relpath = item.fullname.replace(relPathToReplace, '')
 | 
				
			||||||
 | 
					    var reldirname = Path.dirname(relpath)
 | 
				
			||||||
 | 
					    var dirname = Path.dirname(item.fullname)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Directory has a file named ".ignore" flag directory and ignore
 | 
				
			||||||
 | 
					    if (item.name === '.ignore' && reldirname && reldirname !== '.' && !directoriesToIgnore.includes(dirname)) {
 | 
				
			||||||
 | 
					      Logger.debug(`[fileUtils] .ignore found - ignoring directory "${reldirname}"`)
 | 
				
			||||||
 | 
					      directoriesToIgnore.push(dirname)
 | 
				
			||||||
      return false
 | 
					      return false
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Ignore any file if a directory or the filename starts with "."
 | 
					    // Ignore any file if a directory or the filename starts with "."
 | 
				
			||||||
    var relpath = item.fullname.replace(relPathToReplace, '')
 | 
					 | 
				
			||||||
    var pathStartsWithPeriod = relpath.split('/').find(p => p.startsWith('.'))
 | 
					    var pathStartsWithPeriod = relpath.split('/').find(p => p.startsWith('.'))
 | 
				
			||||||
    if (pathStartsWithPeriod) {
 | 
					    if (pathStartsWithPeriod) {
 | 
				
			||||||
      Logger.debug(`[fileUtils] Ignoring path has . "${relpath}"`)
 | 
					      Logger.debug(`[fileUtils] Ignoring path has . "${relpath}"`)
 | 
				
			||||||
      return false
 | 
					      return false
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true
 | 
				
			||||||
 | 
					  }).filter(item => {
 | 
				
			||||||
 | 
					    // Filter out items in ignore directories
 | 
				
			||||||
 | 
					    if (directoriesToIgnore.includes(Path.dirname(item.fullname))) {
 | 
				
			||||||
 | 
					      Logger.debug(`[fileUtils] Ignoring path in dir with .ignore "${item.fullname}"`)
 | 
				
			||||||
 | 
					      return false
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return true
 | 
					    return true
 | 
				
			||||||
  }).map((item) => ({
 | 
					  }).map((item) => ({
 | 
				
			||||||
    name: item.name,
 | 
					    name: item.name,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user