Fix init being smarter and less io intensive, skip reading size of files during startup
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed

This commit is contained in:
Jonatan Nilsson 2022-08-15 19:51:13 +00:00
parent 71c8937f93
commit 9790f298f3
2 changed files with 19 additions and 19 deletions

View file

@ -19,7 +19,7 @@ export default class MediaRoutes {
}
register(server) {
this.init().then(function() {}, function(err) {
this.init(server).then(function() {}, function(err) {
server.core.log.error(err, 'Error initing media')
})
@ -32,24 +32,24 @@ export default class MediaRoutes {
server.flaska.delete('/media/:filename', [server.queryHandler()], this.remove.bind(this))
}
init() {
return fs.readdir(config.get('uploadFolder')).then(folders => {
init(server) {
let folders = Object.keys(config.get('sites'))
return Promise.all(folders.map(folder => {
return fs.readdir(config.get('uploadFolder') + '/' + folder)
.then(files => {
return Promise.all(files.map(file => {
return fs.stat(`${config.get('uploadFolder')}/${folder}/${file}`)
.then(function(stat) {
return { filename: file, size: stat.size }
return files.map(file => {
return { filename: file, size: null }
})
}))
})
.catch(err => {
server.core.log.error(err, `Error reading folder "${config.get('uploadFolder')}/${folder}"`)
return []
})
.then(files => {
this.siteCache.set(folder, files)
})
.catch(function() {})
}))
})
}
filesCacheGet(site) {

View file

@ -1,6 +1,6 @@
{
"name": "storage-upload",
"version": "2.2.3",
"version": "2.2.4",
"description": "Micro service for uploading and image resizing files to a storage server.",
"main": "index.js",
"scripts": {