Add more stat collection
This commit is contained in:
parent
741f49ad63
commit
e254114625
7 changed files with 79 additions and 29 deletions
|
@ -17,16 +17,28 @@ const userAgentCheck = function(userAgent) {
|
|||
};
|
||||
|
||||
const hotlinkCheck = function(file, userAgent, referrer) {
|
||||
debug(file, userAgent, referrer);
|
||||
return !userAgentCheck(userAgent) && !file.width && !(referrer.match(/^https:\/\/hostr.co/) || referrer.match(/^http:\/\/localhost:4040/))
|
||||
};
|
||||
|
||||
export function* get(id, name, size) {
|
||||
const file = yield this.db.Files.findOne({_id: id, 'file_name': name, 'status': 'active'});
|
||||
this.assert(file, 404);
|
||||
|
||||
if (hotlinkCheck(file, this.headers['user-agent'], this.headers['referer'])) {
|
||||
this.redirect('/' + id);
|
||||
return this.redirect('/' + id);
|
||||
}
|
||||
|
||||
if (!file.width && this.request.query.warning != 'on') {
|
||||
return this.redirect('/' + id);
|
||||
}
|
||||
|
||||
if (file.malware) {
|
||||
let alert = this.request.query.alert;
|
||||
if (!alert || !alert.match(/i want to download malware/i)) {
|
||||
return this.redirect('/' + id);
|
||||
}
|
||||
}
|
||||
|
||||
let localPath = path.join(storePath, file._id[0], file._id + '_' + file.file_name);
|
||||
let remotePath = path.join(file._id[0], file._id + '_' + file.file_name);
|
||||
if (size > 0) {
|
||||
|
@ -34,9 +46,22 @@ export function* get(id, name, size) {
|
|||
remotePath = path.join(size, file._id + '_' + file.file_name);
|
||||
}
|
||||
|
||||
if (file.malware) {
|
||||
this.statsd.incr('file.malware.download', 1);
|
||||
}
|
||||
|
||||
let type = 'application/octet-stream';
|
||||
if (file.width > 0) {
|
||||
if (size) {
|
||||
this.statsd.incr('file.view', 1);
|
||||
}
|
||||
type = mime.lookup(file.file_name);
|
||||
} else {
|
||||
this.statsd.incr('file.download', 1);
|
||||
}
|
||||
|
||||
if (userAgentCheck(this.headers['user-agent'])) {
|
||||
this.set('Content-Disposition', 'attachment; filename=' + file.file_name);
|
||||
}
|
||||
|
||||
this.set('Content-type', type);
|
||||
|
@ -59,8 +84,7 @@ export function* landing(id, next) {
|
|||
if(userAgentCheck(this.headers['user-agent'])) {
|
||||
return yield get.call(this, file._id, file.file_name);
|
||||
}
|
||||
|
||||
this.statsd.incr('file.landing', 1);
|
||||
const formattedFile = formatFile(file);
|
||||
debug(formattedFile);
|
||||
yield this.render('file', {file: formattedFile});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue