Commit f5cf50fe authored by Mihkel Putrinš's avatar Mihkel Putrinš

refactor

parent 17399253
...@@ -116,21 +116,22 @@ function resourceLoaded() { ...@@ -116,21 +116,22 @@ function resourceLoaded() {
} }
} }
function registerFile(parent_resource, _path, stats, callback) {
var mimetype = mime.lookup(_path)
resource_stats.files.count++
resource_stats.files.size += stats.size
op.push(parent_resource, 'files', _path)
op.set(resource_stats, ['mime', mimetype, 'count'], op.get(resource_stats, ['mime', mimetype, 'count'], 0) + 1)
op.set(resource_stats, ['mime', mimetype, 'size'], op.get(resource_stats, ['mime', mimetype, 'size'], 0) + stats.size)
callback()
}
function recurseLocal(parent_resource, paths, loadedCB) { function recurseLocal(parent_resource, paths, loadedCB) {
async.each(paths, function iterator(_path, callback) { async.each(paths, function iterator(_path, callback) {
fs.stat(_path, function(err, stats) { fs.stat(_path, function(err, stats) {
if (err) { if (err) { return callback() }
return callback()
}
if (stats.isFile()) { if (stats.isFile()) {
var mimetype = mime.lookup(_path) registerFile(parent_resource, _path, stats, callback)
// console.log(mimetype)
resource_stats.files.count++
resource_stats.files.size += stats.size
op.push(parent_resource, 'files', _path)
op.set(resource_stats, ['mime', mimetype, 'count'], op.get(resource_stats, ['mime', mimetype, 'count'], 0) + 1)
op.set(resource_stats, ['mime', mimetype, 'size'], op.get(resource_stats, ['mime', mimetype, 'size'], 0) + stats.size)
callback()
} else if (stats.isDirectory()) { } else if (stats.isDirectory()) {
resource_stats.directories.count++ resource_stats.directories.count++
var directory = {name: _path} var directory = {name: _path}
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "Panustaja", "name": "Panustaja",
"description": "Ressursikataloogi upitamiseks keeleressurside Entu repositooriumisse.", "description": "Ressursikataloogi upitamiseks keeleressurside Entu repositooriumisse.",
"version": "1.0.1-d", "version": "1.0.1-d",
"build": 100, "build": 101,
"main": "./code/app.js", "main": "./code/app.js",
"license": "CC-SA", "license": "CC-SA",
"private": true, "private": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment