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
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed
This commit is contained in:
parent
71c8937f93
commit
9790f298f3
2 changed files with 19 additions and 19 deletions
|
@ -19,7 +19,7 @@ export default class MediaRoutes {
|
||||||
}
|
}
|
||||||
|
|
||||||
register(server) {
|
register(server) {
|
||||||
this.init().then(function() {}, function(err) {
|
this.init(server).then(function() {}, function(err) {
|
||||||
server.core.log.error(err, 'Error initing media')
|
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))
|
server.flaska.delete('/media/:filename', [server.queryHandler()], this.remove.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init(server) {
|
||||||
return fs.readdir(config.get('uploadFolder')).then(folders => {
|
let folders = Object.keys(config.get('sites'))
|
||||||
return Promise.all(folders.map(folder => {
|
|
||||||
return fs.readdir(config.get('uploadFolder') + '/' + folder)
|
return Promise.all(folders.map(folder => {
|
||||||
.then(files => {
|
return fs.readdir(config.get('uploadFolder') + '/' + folder)
|
||||||
return Promise.all(files.map(file => {
|
.then(files => {
|
||||||
return fs.stat(`${config.get('uploadFolder')}/${folder}/${file}`)
|
return files.map(file => {
|
||||||
.then(function(stat) {
|
return { filename: file, size: null }
|
||||||
return { filename: file, size: stat.size }
|
|
||||||
})
|
|
||||||
}))
|
|
||||||
})
|
})
|
||||||
.then(files => {
|
})
|
||||||
this.siteCache.set(folder, files)
|
.catch(err => {
|
||||||
})
|
server.core.log.error(err, `Error reading folder "${config.get('uploadFolder')}/${folder}"`)
|
||||||
.catch(function() {})
|
return []
|
||||||
}))
|
})
|
||||||
})
|
.then(files => {
|
||||||
|
this.siteCache.set(folder, files)
|
||||||
|
})
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
filesCacheGet(site) {
|
filesCacheGet(site) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "storage-upload",
|
"name": "storage-upload",
|
||||||
"version": "2.2.3",
|
"version": "2.2.4",
|
||||||
"description": "Micro service for uploading and image resizing files to a storage server.",
|
"description": "Micro service for uploading and image resizing files to a storage server.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in a new issue