Fix:Downloading podcasts with watcher causing duplicate episodes #2122

This commit is contained in:
advplyr 2023-09-30 15:12:37 -05:00
parent 1dc369180c
commit 3d96749d38
3 changed files with 20 additions and 9 deletions

View File

@ -191,7 +191,7 @@ export default {
} }
}, },
methods: { methods: {
search() {}, submit() {},
inputUpdate() { inputUpdate() {
clearTimeout(this.searchTimeout) clearTimeout(this.searchTimeout)
this.searchTimeout = setTimeout(() => { this.searchTimeout = setTimeout(() => {

View File

@ -92,7 +92,7 @@ class Logger {
* @param {...any} args * @param {...any} args
*/ */
dev(...args) { dev(...args) {
if (!this.isDev) return if (!this.isDev || process.env.HIDE_DEV_LOGS === '1') return
console.log(`[${this.timestamp}] DEV:`, ...args) console.log(`[${this.timestamp}] DEV:`, ...args)
} }

View File

@ -28,6 +28,8 @@ class FolderWatcher extends EventEmitter {
this.ignoreDirs = [] this.ignoreDirs = []
/** @type {string[]} */ /** @type {string[]} */
this.pendingDirsToRemoveFromIgnore = [] this.pendingDirsToRemoveFromIgnore = []
/** @type {NodeJS.Timeout} */
this.removeFromIgnoreTimer = null
this.disabled = false this.disabled = false
} }
@ -240,9 +242,12 @@ class FolderWatcher extends EventEmitter {
*/ */
addIgnoreDir(path) { addIgnoreDir(path) {
path = this.cleanDirPath(path) path = this.cleanDirPath(path)
if (this.ignoreDirs.includes(path)) return
this.pendingDirsToRemoveFromIgnore = this.pendingDirsToRemoveFromIgnore.filter(p => p !== path) this.pendingDirsToRemoveFromIgnore = this.pendingDirsToRemoveFromIgnore.filter(p => p !== path)
Logger.debug(`[Watcher] Ignoring directory "${path}"`) if (this.ignoreDirs.includes(path)) {
// Already ignoring dir
return
}
Logger.debug(`[Watcher] addIgnoreDir: Ignoring directory "${path}"`)
this.ignoreDirs.push(path) this.ignoreDirs.push(path)
} }
@ -255,18 +260,24 @@ class FolderWatcher extends EventEmitter {
*/ */
removeIgnoreDir(path) { removeIgnoreDir(path) {
path = this.cleanDirPath(path) path = this.cleanDirPath(path)
if (!this.ignoreDirs.includes(path) || this.pendingDirsToRemoveFromIgnore.includes(path)) return if (!this.ignoreDirs.includes(path)) {
Logger.debug(`[Watcher] removeIgnoreDir: Path is not being ignored "${path}"`)
return
}
// Add a 5 second delay before removing the ignore from this dir // Add a 5 second delay before removing the ignore from this dir
if (!this.pendingDirsToRemoveFromIgnore.includes(path)) {
this.pendingDirsToRemoveFromIgnore.push(path) this.pendingDirsToRemoveFromIgnore.push(path)
setTimeout(() => { }
clearTimeout(this.removeFromIgnoreTimer)
this.removeFromIgnoreTimer = setTimeout(() => {
if (this.pendingDirsToRemoveFromIgnore.includes(path)) { if (this.pendingDirsToRemoveFromIgnore.includes(path)) {
this.pendingDirsToRemoveFromIgnore = this.pendingDirsToRemoveFromIgnore.filter(p => p !== path) this.pendingDirsToRemoveFromIgnore = this.pendingDirsToRemoveFromIgnore.filter(p => p !== path)
Logger.debug(`[Watcher] No longer ignoring directory "${path}"`) Logger.debug(`[Watcher] removeIgnoreDir: No longer ignoring directory "${path}"`)
this.ignoreDirs = this.ignoreDirs.filter(p => p !== path) this.ignoreDirs = this.ignoreDirs.filter(p => p !== path)
} }
}, 5000) }, 5000)
} }
} }
module.exports = FolderWatcher module.exports = FolderWatcher