mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-30 00:06:54 +01:00
Update formatting in CacheManager
This commit is contained in:
parent
26d2c5a8f0
commit
8be08882d8
@ -16,7 +16,8 @@ class CacheManager {
|
|||||||
/**
|
/**
|
||||||
* Create cache directory paths if they dont exist
|
* Create cache directory paths if they dont exist
|
||||||
*/
|
*/
|
||||||
async ensureCachePaths() { // Creates cache paths if necessary and sets owner and permissions
|
async ensureCachePaths() {
|
||||||
|
// Creates cache paths if necessary and sets owner and permissions
|
||||||
this.CachePath = Path.join(global.MetadataPath, 'cache')
|
this.CachePath = Path.join(global.MetadataPath, 'cache')
|
||||||
this.CoverCachePath = Path.join(this.CachePath, 'covers')
|
this.CoverCachePath = Path.join(this.CachePath, 'covers')
|
||||||
this.ImageCachePath = Path.join(this.CachePath, 'images')
|
this.ImageCachePath = Path.join(this.CachePath, 'images')
|
||||||
@ -89,23 +90,28 @@ class CacheManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async purgeEntityCache(entityId, cachePath) {
|
async purgeEntityCache(entityId, cachePath) {
|
||||||
return Promise.all((await fs.readdir(cachePath)).reduce((promises, file) => {
|
return Promise.all(
|
||||||
if (file.startsWith(entityId)) {
|
(await fs.readdir(cachePath)).reduce((promises, file) => {
|
||||||
Logger.debug(`[CacheManager] Going to purge ${file}`);
|
if (file.startsWith(entityId)) {
|
||||||
promises.push(this.removeCache(Path.join(cachePath, file)))
|
Logger.debug(`[CacheManager] Going to purge ${file}`)
|
||||||
}
|
promises.push(this.removeCache(Path.join(cachePath, file)))
|
||||||
return promises
|
}
|
||||||
}, []))
|
return promises
|
||||||
|
}, [])
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
removeCache(path) {
|
removeCache(path) {
|
||||||
if (!path) return false
|
if (!path) return false
|
||||||
return fs.pathExists(path).then((exists) => {
|
return fs.pathExists(path).then((exists) => {
|
||||||
if (!exists) return false
|
if (!exists) return false
|
||||||
return fs.unlink(path).then(() => true).catch((err) => {
|
return fs
|
||||||
Logger.error(`[CacheManager] Failed to remove cache "${path}"`, err)
|
.unlink(path)
|
||||||
return false
|
.then(() => true)
|
||||||
})
|
.catch((err) => {
|
||||||
|
Logger.error(`[CacheManager] Failed to remove cache "${path}"`, err)
|
||||||
|
return false
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,4 +164,4 @@ class CacheManager {
|
|||||||
readStream.pipe(res)
|
readStream.pipe(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = new CacheManager()
|
module.exports = new CacheManager()
|
||||||
|
Loading…
Reference in New Issue
Block a user