First pass formatting with Prettier
* Added .prettierrc.json * Added .prettierignore * Formatted
This commit is contained in:
@@ -2,30 +2,30 @@
|
||||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
const Config = require('./config.js').get;
|
||||
const FileDb = require('./database.js').dbs.file;
|
||||
const Config = require('./config.js').get;
|
||||
const FileDb = require('./database.js').dbs.file;
|
||||
const getISOTimestampString = require('./database.js').getISOTimestampString;
|
||||
const FileEntry = require('./file_entry.js');
|
||||
const getServer = require('./listening_server.js').getServer;
|
||||
const Errors = require('./enig_error.js').Errors;
|
||||
const ErrNotEnabled = require('./enig_error.js').ErrorReasons.NotEnabled;
|
||||
const StatLog = require('./stat_log.js');
|
||||
const User = require('./user.js');
|
||||
const Log = require('./logger.js').log;
|
||||
const FileEntry = require('./file_entry.js');
|
||||
const getServer = require('./listening_server.js').getServer;
|
||||
const Errors = require('./enig_error.js').Errors;
|
||||
const ErrNotEnabled = require('./enig_error.js').ErrorReasons.NotEnabled;
|
||||
const StatLog = require('./stat_log.js');
|
||||
const User = require('./user.js');
|
||||
const Log = require('./logger.js').log;
|
||||
const getConnectionByUserId = require('./client_connections.js').getConnectionByUserId;
|
||||
const webServerPackageName = require('./servers/content/web.js').moduleInfo.packageName;
|
||||
const Events = require('./events.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
const SysProps = require('./system_menu_method.js');
|
||||
const webServerPackageName = require('./servers/content/web.js').moduleInfo.packageName;
|
||||
const Events = require('./events.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
const SysProps = require('./system_menu_method.js');
|
||||
|
||||
// deps
|
||||
const hashids = require('hashids/cjs');
|
||||
const moment = require('moment');
|
||||
const paths = require('path');
|
||||
const async = require('async');
|
||||
const fs = require('graceful-fs');
|
||||
const mimeTypes = require('mime-types');
|
||||
const yazl = require('yazl');
|
||||
const hashids = require('hashids/cjs');
|
||||
const moment = require('moment');
|
||||
const paths = require('path');
|
||||
const async = require('async');
|
||||
const fs = require('graceful-fs');
|
||||
const mimeTypes = require('mime-types');
|
||||
const yazl = require('yazl');
|
||||
|
||||
function notEnabledError() {
|
||||
return Errors.General('Web server is not enabled', ErrNotEnabled);
|
||||
@@ -33,8 +33,8 @@ function notEnabledError() {
|
||||
|
||||
class FileAreaWebAccess {
|
||||
constructor() {
|
||||
this.hashids = new hashids(Config().general.boardName);
|
||||
this.expireTimers = {}; // hashId->timer
|
||||
this.hashids = new hashids(Config().general.boardName);
|
||||
this.expireTimers = {}; // hashId->timer
|
||||
}
|
||||
|
||||
startup(cb) {
|
||||
@@ -47,21 +47,27 @@ class FileAreaWebAccess {
|
||||
},
|
||||
function addWebRoute(callback) {
|
||||
self.webServer = getServer(webServerPackageName);
|
||||
if(!self.webServer) {
|
||||
return callback(Errors.DoesNotExist(`Server with package name "${webServerPackageName}" does not exist`));
|
||||
if (!self.webServer) {
|
||||
return callback(
|
||||
Errors.DoesNotExist(
|
||||
`Server with package name "${webServerPackageName}" does not exist`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(self.isEnabled()) {
|
||||
if (self.isEnabled()) {
|
||||
const routeAdded = self.webServer.instance.addRoute({
|
||||
method : 'GET',
|
||||
path : Config().fileBase.web.routePath,
|
||||
handler : self.routeWebRequest.bind(self),
|
||||
method: 'GET',
|
||||
path: Config().fileBase.web.routePath,
|
||||
handler: self.routeWebRequest.bind(self),
|
||||
});
|
||||
return callback(routeAdded ? null : Errors.General('Failed adding route'));
|
||||
return callback(
|
||||
routeAdded ? null : Errors.General('Failed adding route')
|
||||
);
|
||||
} else {
|
||||
return callback(null); // not enabled, but no error
|
||||
return callback(null); // not enabled, but no error
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
err => {
|
||||
return cb(err);
|
||||
@@ -79,8 +85,8 @@ class FileAreaWebAccess {
|
||||
|
||||
static getHashIdTypes() {
|
||||
return {
|
||||
SingleFile : 0,
|
||||
BatchArchive : 1,
|
||||
SingleFile: 0,
|
||||
BatchArchive: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -92,7 +98,7 @@ class FileAreaWebAccess {
|
||||
`SELECT hash_id, expire_timestamp
|
||||
FROM file_web_serve;`,
|
||||
(err, row) => {
|
||||
if(row) {
|
||||
if (row) {
|
||||
this.scheduleExpire(row.hash_id, moment(row.expire_timestamp));
|
||||
}
|
||||
},
|
||||
@@ -109,29 +115,28 @@ class FileAreaWebAccess {
|
||||
FileDb.run(
|
||||
`DELETE FROM file_web_serve
|
||||
WHERE hash_id = ?;`,
|
||||
[ hashId ]
|
||||
[hashId]
|
||||
);
|
||||
|
||||
delete this.expireTimers[hashId];
|
||||
}
|
||||
|
||||
scheduleExpire(hashId, expireTime) {
|
||||
|
||||
// remove any previous entry for this hashId
|
||||
const previous = this.expireTimers[hashId];
|
||||
if(previous) {
|
||||
if (previous) {
|
||||
clearTimeout(previous);
|
||||
delete this.expireTimers[hashId];
|
||||
}
|
||||
|
||||
const timeoutMs = expireTime.diff(moment());
|
||||
|
||||
if(timeoutMs <= 0) {
|
||||
setImmediate( () => {
|
||||
if (timeoutMs <= 0) {
|
||||
setImmediate(() => {
|
||||
this.removeEntry(hashId);
|
||||
});
|
||||
} else {
|
||||
this.expireTimers[hashId] = setTimeout( () => {
|
||||
this.expireTimers[hashId] = setTimeout(() => {
|
||||
this.removeEntry(hashId);
|
||||
}, timeoutMs);
|
||||
}
|
||||
@@ -142,27 +147,32 @@ class FileAreaWebAccess {
|
||||
`SELECT expire_timestamp FROM
|
||||
file_web_serve
|
||||
WHERE hash_id = ?`,
|
||||
[ hashId ],
|
||||
[hashId],
|
||||
(err, result) => {
|
||||
if(err || !result) {
|
||||
return cb(err ? err : Errors.DoesNotExist('Invalid or missing hash ID'));
|
||||
if (err || !result) {
|
||||
return cb(
|
||||
err ? err : Errors.DoesNotExist('Invalid or missing hash ID')
|
||||
);
|
||||
}
|
||||
|
||||
const decoded = this.hashids.decode(hashId);
|
||||
|
||||
// decode() should provide an array of [ userId, hashIdType, id, ... ]
|
||||
if(!Array.isArray(decoded) || decoded.length < 3) {
|
||||
if (!Array.isArray(decoded) || decoded.length < 3) {
|
||||
return cb(Errors.Invalid('Invalid or unknown hash ID'));
|
||||
}
|
||||
|
||||
const servedItem = {
|
||||
hashId : hashId,
|
||||
userId : decoded[0],
|
||||
hashIdType : decoded[1],
|
||||
expireTimestamp : moment(result.expire_timestamp),
|
||||
hashId: hashId,
|
||||
userId: decoded[0],
|
||||
hashIdType: decoded[1],
|
||||
expireTimestamp: moment(result.expire_timestamp),
|
||||
};
|
||||
|
||||
if(FileAreaWebAccess.getHashIdTypes().SingleFile === servedItem.hashIdType) {
|
||||
if (
|
||||
FileAreaWebAccess.getHashIdTypes().SingleFile ===
|
||||
servedItem.hashIdType
|
||||
) {
|
||||
servedItem.fileIds = decoded.slice(2);
|
||||
}
|
||||
|
||||
@@ -172,11 +182,17 @@ class FileAreaWebAccess {
|
||||
}
|
||||
|
||||
getSingleFileHashId(client, fileEntry) {
|
||||
return this.getHashId(client, FileAreaWebAccess.getHashIdTypes().SingleFile, [ fileEntry.fileId ] );
|
||||
return this.getHashId(client, FileAreaWebAccess.getHashIdTypes().SingleFile, [
|
||||
fileEntry.fileId,
|
||||
]);
|
||||
}
|
||||
|
||||
getBatchArchiveHashId(client, batchId) {
|
||||
return this.getHashId(client, FileAreaWebAccess.getHashIdTypes().BatchArchive, batchId);
|
||||
return this.getHashId(
|
||||
client,
|
||||
FileAreaWebAccess.getHashIdTypes().BatchArchive,
|
||||
batchId
|
||||
);
|
||||
}
|
||||
|
||||
getHashId(client, hashIdType, identifier) {
|
||||
@@ -194,13 +210,13 @@ class FileAreaWebAccess {
|
||||
}
|
||||
|
||||
getExistingTempDownloadServeItem(client, fileEntry, cb) {
|
||||
if(!this.isEnabled()) {
|
||||
if (!this.isEnabled()) {
|
||||
return cb(notEnabledError());
|
||||
}
|
||||
|
||||
const hashId = this.getSingleFileHashId(client, fileEntry);
|
||||
this.loadServedHashId(hashId, (err, servedItem) => {
|
||||
if(err) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
@@ -215,9 +231,9 @@ class FileAreaWebAccess {
|
||||
dbOrTrans.run(
|
||||
`REPLACE INTO file_web_serve (hash_id, expire_timestamp)
|
||||
VALUES (?, ?);`,
|
||||
[ hashId, getISOTimestampString(expireTime) ],
|
||||
[hashId, getISOTimestampString(expireTime)],
|
||||
err => {
|
||||
if(err) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
@@ -229,13 +245,13 @@ class FileAreaWebAccess {
|
||||
}
|
||||
|
||||
createAndServeTempDownload(client, fileEntry, options, cb) {
|
||||
if(!this.isEnabled()) {
|
||||
if (!this.isEnabled()) {
|
||||
return cb(notEnabledError());
|
||||
}
|
||||
|
||||
const hashId = this.getSingleFileHashId(client, fileEntry);
|
||||
const url = this.buildSingleFileTempDownloadLink(client, fileEntry, hashId);
|
||||
options.expireTime = options.expireTime || moment().add(2, 'days');
|
||||
const hashId = this.getSingleFileHashId(client, fileEntry);
|
||||
const url = this.buildSingleFileTempDownloadLink(client, fileEntry, hashId);
|
||||
options.expireTime = options.expireTime || moment().add(2, 'days');
|
||||
|
||||
this._addOrUpdateHashIdRecord(FileDb, hashId, options.expireTime, err => {
|
||||
return cb(err, url);
|
||||
@@ -243,41 +259,45 @@ class FileAreaWebAccess {
|
||||
}
|
||||
|
||||
createAndServeTempBatchDownload(client, fileEntries, options, cb) {
|
||||
if(!this.isEnabled()) {
|
||||
if (!this.isEnabled()) {
|
||||
return cb(notEnabledError());
|
||||
}
|
||||
|
||||
const batchId = moment().utc().unix();
|
||||
const hashId = this.getBatchArchiveHashId(client, batchId);
|
||||
const url = this.buildBatchArchiveTempDownloadLink(client, hashId);
|
||||
options.expireTime = options.expireTime || moment().add(2, 'days');
|
||||
const batchId = moment().utc().unix();
|
||||
const hashId = this.getBatchArchiveHashId(client, batchId);
|
||||
const url = this.buildBatchArchiveTempDownloadLink(client, hashId);
|
||||
options.expireTime = options.expireTime || moment().add(2, 'days');
|
||||
|
||||
FileDb.beginTransaction( (err, trans) => {
|
||||
if(err) {
|
||||
FileDb.beginTransaction((err, trans) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
this._addOrUpdateHashIdRecord(trans, hashId, options.expireTime, err => {
|
||||
if(err) {
|
||||
return trans.rollback( () => {
|
||||
if (err) {
|
||||
return trans.rollback(() => {
|
||||
return cb(err);
|
||||
});
|
||||
}
|
||||
|
||||
async.eachSeries(fileEntries, (entry, nextEntry) => {
|
||||
trans.run(
|
||||
`INSERT INTO file_web_serve_batch (hash_id, file_id)
|
||||
async.eachSeries(
|
||||
fileEntries,
|
||||
(entry, nextEntry) => {
|
||||
trans.run(
|
||||
`INSERT INTO file_web_serve_batch (hash_id, file_id)
|
||||
VALUES (?, ?);`,
|
||||
[ hashId, entry.fileId ],
|
||||
err => {
|
||||
return nextEntry(err);
|
||||
}
|
||||
);
|
||||
}, err => {
|
||||
trans[err ? 'rollback' : 'commit']( () => {
|
||||
return cb(err, url);
|
||||
});
|
||||
});
|
||||
[hashId, entry.fileId],
|
||||
err => {
|
||||
return nextEntry(err);
|
||||
}
|
||||
);
|
||||
},
|
||||
err => {
|
||||
trans[err ? 'rollback' : 'commit'](() => {
|
||||
return cb(err, url);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -289,47 +309,46 @@ class FileAreaWebAccess {
|
||||
routeWebRequest(req, resp) {
|
||||
const hashId = paths.basename(req.url);
|
||||
|
||||
Log.debug( { hashId : hashId, url : req.url }, 'File area web request');
|
||||
Log.debug({ hashId: hashId, url: req.url }, 'File area web request');
|
||||
|
||||
this.loadServedHashId(hashId, (err, servedItem) => {
|
||||
|
||||
if(err) {
|
||||
if (err) {
|
||||
return this.fileNotFound(resp);
|
||||
}
|
||||
|
||||
const hashIdTypes = FileAreaWebAccess.getHashIdTypes();
|
||||
switch(servedItem.hashIdType) {
|
||||
case hashIdTypes.SingleFile :
|
||||
switch (servedItem.hashIdType) {
|
||||
case hashIdTypes.SingleFile:
|
||||
return this.routeWebRequestForSingleFile(servedItem, req, resp);
|
||||
|
||||
case hashIdTypes.BatchArchive :
|
||||
case hashIdTypes.BatchArchive:
|
||||
return this.routeWebRequestForBatchArchive(servedItem, req, resp);
|
||||
|
||||
default :
|
||||
default:
|
||||
return this.fileNotFound(resp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
routeWebRequestForSingleFile(servedItem, req, resp) {
|
||||
Log.debug( { servedItem : servedItem }, 'Single file web request');
|
||||
Log.debug({ servedItem: servedItem }, 'Single file web request');
|
||||
|
||||
const fileEntry = new FileEntry();
|
||||
|
||||
servedItem.fileId = servedItem.fileIds[0];
|
||||
|
||||
fileEntry.load(servedItem.fileId, err => {
|
||||
if(err) {
|
||||
if (err) {
|
||||
return this.fileNotFound(resp);
|
||||
}
|
||||
|
||||
const filePath = fileEntry.filePath;
|
||||
if(!filePath) {
|
||||
if (!filePath) {
|
||||
return this.fileNotFound(resp);
|
||||
}
|
||||
|
||||
fs.stat(filePath, (err, stats) => {
|
||||
if(err) {
|
||||
if (err) {
|
||||
return this.fileNotFound(resp);
|
||||
}
|
||||
|
||||
@@ -340,13 +359,18 @@ class FileAreaWebAccess {
|
||||
|
||||
resp.on('finish', () => {
|
||||
// transfer completed fully
|
||||
this.updateDownloadStatsForUserIdAndSystem(servedItem.userId, stats.size, [ fileEntry ]);
|
||||
this.updateDownloadStatsForUserIdAndSystem(
|
||||
servedItem.userId,
|
||||
stats.size,
|
||||
[fileEntry]
|
||||
);
|
||||
});
|
||||
|
||||
const headers = {
|
||||
'Content-Type' : mimeTypes.contentType(filePath) || mimeTypes.contentType('.bin'),
|
||||
'Content-Length' : stats.size,
|
||||
'Content-Disposition' : `attachment; filename="${fileEntry.fileName}"`,
|
||||
'Content-Type':
|
||||
mimeTypes.contentType(filePath) || mimeTypes.contentType('.bin'),
|
||||
'Content-Length': stats.size,
|
||||
'Content-Disposition': `attachment; filename="${fileEntry.fileName}"`,
|
||||
};
|
||||
|
||||
const readStream = fs.createReadStream(filePath);
|
||||
@@ -357,7 +381,7 @@ class FileAreaWebAccess {
|
||||
}
|
||||
|
||||
routeWebRequestForBatchArchive(servedItem, req, resp) {
|
||||
Log.debug( { servedItem : servedItem }, 'Batch file web request');
|
||||
Log.debug({ servedItem: servedItem }, 'Batch file web request');
|
||||
|
||||
//
|
||||
// We are going to build an on-the-fly zip file stream of 1:n
|
||||
@@ -374,53 +398,80 @@ class FileAreaWebAccess {
|
||||
`SELECT file_id
|
||||
FROM file_web_serve_batch
|
||||
WHERE hash_id = ?;`,
|
||||
[ servedItem.hashId ],
|
||||
[servedItem.hashId],
|
||||
(err, fileIdRows) => {
|
||||
if(err || !Array.isArray(fileIdRows) || 0 === fileIdRows.length) {
|
||||
return callback(Errors.DoesNotExist('Could not get file IDs for batch'));
|
||||
if (
|
||||
err ||
|
||||
!Array.isArray(fileIdRows) ||
|
||||
0 === fileIdRows.length
|
||||
) {
|
||||
return callback(
|
||||
Errors.DoesNotExist(
|
||||
'Could not get file IDs for batch'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return callback(null, fileIdRows.map(r => r.file_id));
|
||||
return callback(
|
||||
null,
|
||||
fileIdRows.map(r => r.file_id)
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
function loadFileEntries(fileIds, callback) {
|
||||
async.map(fileIds, (fileId, nextFileId) => {
|
||||
const fileEntry = new FileEntry();
|
||||
fileEntry.load(fileId, err => {
|
||||
return nextFileId(err, fileEntry);
|
||||
});
|
||||
}, (err, fileEntries) => {
|
||||
if(err) {
|
||||
return callback(Errors.DoesNotExist('Could not load file IDs for batch'));
|
||||
}
|
||||
async.map(
|
||||
fileIds,
|
||||
(fileId, nextFileId) => {
|
||||
const fileEntry = new FileEntry();
|
||||
fileEntry.load(fileId, err => {
|
||||
return nextFileId(err, fileEntry);
|
||||
});
|
||||
},
|
||||
(err, fileEntries) => {
|
||||
if (err) {
|
||||
return callback(
|
||||
Errors.DoesNotExist(
|
||||
'Could not load file IDs for batch'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return callback(null, fileEntries);
|
||||
});
|
||||
return callback(null, fileEntries);
|
||||
}
|
||||
);
|
||||
},
|
||||
function createAndServeStream(fileEntries, callback) {
|
||||
const filePaths = fileEntries.map(fe => fe.filePath);
|
||||
Log.trace( { filePaths : filePaths }, 'Creating zip archive for batch web request');
|
||||
Log.trace(
|
||||
{ filePaths: filePaths },
|
||||
'Creating zip archive for batch web request'
|
||||
);
|
||||
|
||||
const zipFile = new yazl.ZipFile();
|
||||
|
||||
zipFile.on('error', err => {
|
||||
Log.warn( { error : err.message }, 'Error adding file to batch web request archive');
|
||||
Log.warn(
|
||||
{ error: err.message },
|
||||
'Error adding file to batch web request archive'
|
||||
);
|
||||
});
|
||||
|
||||
filePaths.forEach(fp => {
|
||||
zipFile.addFile(
|
||||
fp, // path to physical file
|
||||
fp, // path to physical file
|
||||
paths.basename(fp), // filename/path *stored in archive*
|
||||
{
|
||||
compress : false, // :TODO: do this smartly - if ext is in set = false, else true via isArchive() or such... mimeDB has this for us.
|
||||
compress: false, // :TODO: do this smartly - if ext is in set = false, else true via isArchive() or such... mimeDB has this for us.
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
zipFile.end( finalZipSize => {
|
||||
if(-1 === finalZipSize) {
|
||||
return callback(Errors.UnexpectedState('Unable to acquire final zip size'));
|
||||
zipFile.end(finalZipSize => {
|
||||
if (-1 === finalZipSize) {
|
||||
return callback(
|
||||
Errors.UnexpectedState('Unable to acquire final zip size')
|
||||
);
|
||||
}
|
||||
|
||||
resp.on('close', () => {
|
||||
@@ -430,24 +481,30 @@ class FileAreaWebAccess {
|
||||
|
||||
resp.on('finish', () => {
|
||||
// transfer completed fully
|
||||
self.updateDownloadStatsForUserIdAndSystem(servedItem.userId, finalZipSize, fileEntries);
|
||||
self.updateDownloadStatsForUserIdAndSystem(
|
||||
servedItem.userId,
|
||||
finalZipSize,
|
||||
fileEntries
|
||||
);
|
||||
});
|
||||
|
||||
const batchFileName = `batch_${servedItem.hashId}.zip`;
|
||||
|
||||
const headers = {
|
||||
'Content-Type' : mimeTypes.contentType(batchFileName) || mimeTypes.contentType('.bin'),
|
||||
'Content-Length' : finalZipSize,
|
||||
'Content-Disposition' : `attachment; filename="${batchFileName}"`,
|
||||
'Content-Type':
|
||||
mimeTypes.contentType(batchFileName) ||
|
||||
mimeTypes.contentType('.bin'),
|
||||
'Content-Length': finalZipSize,
|
||||
'Content-Disposition': `attachment; filename="${batchFileName}"`,
|
||||
};
|
||||
|
||||
resp.writeHead(200, headers);
|
||||
return zipFile.outputStream.pipe(resp);
|
||||
});
|
||||
}
|
||||
},
|
||||
],
|
||||
err => {
|
||||
if(err) {
|
||||
if (err) {
|
||||
// :TODO: Log me!
|
||||
return this.fileNotFound(resp);
|
||||
}
|
||||
@@ -458,41 +515,36 @@ class FileAreaWebAccess {
|
||||
}
|
||||
|
||||
updateDownloadStatsForUserIdAndSystem(userId, dlBytes, fileEntries) {
|
||||
async.waterfall(
|
||||
[
|
||||
function fetchActiveUser(callback) {
|
||||
const clientForUserId = getConnectionByUserId(userId);
|
||||
if(clientForUserId) {
|
||||
return callback(null, clientForUserId.user);
|
||||
}
|
||||
|
||||
// not online now - look 'em up
|
||||
User.getUser(userId, (err, assocUser) => {
|
||||
return callback(err, assocUser);
|
||||
});
|
||||
},
|
||||
function updateStats(user, callback) {
|
||||
StatLog.incrementUserStat(user, UserProps.FileDlTotalCount, 1);
|
||||
StatLog.incrementUserStat(user, UserProps.FileDlTotalBytes, dlBytes);
|
||||
|
||||
StatLog.incrementSystemStat(SysProps.FileDlTotalCount, 1);
|
||||
StatLog.incrementSystemStat(SysProps.FileDlTotalBytes, dlBytes);
|
||||
|
||||
return callback(null, user);
|
||||
},
|
||||
function sendEvent(user, callback) {
|
||||
Events.emit(
|
||||
Events.getSystemEvents().UserDownload,
|
||||
{
|
||||
user : user,
|
||||
files : fileEntries,
|
||||
}
|
||||
);
|
||||
return callback(null);
|
||||
async.waterfall([
|
||||
function fetchActiveUser(callback) {
|
||||
const clientForUserId = getConnectionByUserId(userId);
|
||||
if (clientForUserId) {
|
||||
return callback(null, clientForUserId.user);
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
// not online now - look 'em up
|
||||
User.getUser(userId, (err, assocUser) => {
|
||||
return callback(err, assocUser);
|
||||
});
|
||||
},
|
||||
function updateStats(user, callback) {
|
||||
StatLog.incrementUserStat(user, UserProps.FileDlTotalCount, 1);
|
||||
StatLog.incrementUserStat(user, UserProps.FileDlTotalBytes, dlBytes);
|
||||
|
||||
StatLog.incrementSystemStat(SysProps.FileDlTotalCount, 1);
|
||||
StatLog.incrementSystemStat(SysProps.FileDlTotalBytes, dlBytes);
|
||||
|
||||
return callback(null, user);
|
||||
},
|
||||
function sendEvent(user, callback) {
|
||||
Events.emit(Events.getSystemEvents().UserDownload, {
|
||||
user: user,
|
||||
files: fileEntries,
|
||||
});
|
||||
return callback(null);
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new FileAreaWebAccess();
|
||||
module.exports = new FileAreaWebAccess();
|
||||
|
||||
Reference in New Issue
Block a user