arma-server-web-admin/lib/mods/folderSize.js
Björn Dahlgren 8a16c69e3e Add metadata about mods
* Mod info
* Size
* Steam Workshop info
2021-12-27 20:12:04 +01:00

27 lines
693 B
JavaScript

var async = require('async')
var fs = require('fs')
var glob = require('glob')
var path = require('path')
module.exports = function (modPath, config, callback) {
var basePath = path.resolve(config.path, modPath)
var total = 0
glob('**/*', { cwd: basePath, dot: true }, function (err, files) {
if (err) {
return callback(err, 0)
}
async.forEach(files, function (file, cb) {
fs.stat(path.join(basePath, file), function stat (err, stats) {
if (!err && (stats.isFile() || stats.isSymbolicLink())) {
var size = stats.size || 0
total += size
}
cb()
})
}, function (err) {
callback(err, total)
})
})
}