mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add log for file download event
This commit is contained in:
1 parent
1f9d9a6b94
commit
2c1ce1593c
4 files changed
+39
-6
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "3.1.11",
|
||||
"version": "3.1.12",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -153,12 +153,8 @@ class HomeSecurityHandler extends Handler {
|
||||
);
|
||||
}
|
||||
}
|
||||
const path = [
|
||||
['Hydro', 'homepage'],
|
||||
['home_security', null],
|
||||
];
|
||||
this.response.template = 'home_security.html';
|
||||
this.response.body = { sessions, geoipProvider: geoip?.provider, path };
|
||||
this.response.body = { sessions, geoipProvider: geoip?.provider };
|
||||
if (useragent) this.response.body.icon = useragent.icon;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
BadRequestError, ForbiddenError, ValidationError,
|
||||
} from '../error';
|
||||
import { PRIV } from '../model/builtin';
|
||||
import * as oplog from '../model/oplog';
|
||||
import storage from '../model/storage';
|
||||
import * as system from '../model/system';
|
||||
import user from '../model/user';
|
||||
@@ -83,6 +84,16 @@ export class FSDownloadHandler extends Handler {
|
||||
this.response.addHeader('Cache-Control', 'public');
|
||||
const target = `user/${uid}/${filename}`;
|
||||
const file = await storage.getMeta(target);
|
||||
await oplog.add({
|
||||
type: 'download',
|
||||
time: new Date(),
|
||||
uid: this.user._id,
|
||||
ip: this.request.ip,
|
||||
fileType: 'user',
|
||||
target,
|
||||
referer: this.request.referer,
|
||||
size: file?.size || 0,
|
||||
});
|
||||
if (!file) {
|
||||
this.response.redirect = await storage.signDownloadLink(
|
||||
target, noDisposition ? undefined : filename, false, 'user',
|
||||
|
||||
@@ -21,6 +21,7 @@ import { PERM, PRIV } from '../model/builtin';
|
||||
import * as contest from '../model/contest';
|
||||
import * as discussion from '../model/discussion';
|
||||
import domain from '../model/domain';
|
||||
import * as oplog from '../model/oplog';
|
||||
import problem from '../model/problem';
|
||||
import record from '../model/record';
|
||||
import solution from '../model/solution';
|
||||
@@ -477,6 +478,21 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
||||
}
|
||||
if (this.pdoc.reference) this.pdoc = await problem.get(this.pdoc.reference.domainId, this.pdoc.reference.pid);
|
||||
const links = {};
|
||||
const size = Math.sum(
|
||||
this.pdoc[type === 'testdata' ? 'data' : 'additional_file']
|
||||
.filter((i) => files.has(i.name))
|
||||
.map((i) => i.size),
|
||||
);
|
||||
await oplog.add({
|
||||
type: 'bulkDownload',
|
||||
time: new Date(),
|
||||
uid: this.user._id,
|
||||
ip: this.request.ip,
|
||||
fileType: 'problem',
|
||||
target: Array.from(files).map((file) => `problem/${this.pdoc.domainId}/${this.pdoc.docId}/${type}/${file}`),
|
||||
referer: this.request.referer,
|
||||
size,
|
||||
});
|
||||
for (const file of files) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
links[file] = await storage.signDownloadLink(
|
||||
@@ -570,6 +586,16 @@ export class ProblemFileDownloadHandler extends ProblemDetailHandler {
|
||||
}
|
||||
const target = `problem/${this.pdoc.domainId}/${this.pdoc.docId}/${type}/${filename}`;
|
||||
const file = await storage.getMeta(target);
|
||||
await oplog.add({
|
||||
type: 'download',
|
||||
time: new Date(),
|
||||
uid: this.user._id,
|
||||
ip: this.request.ip,
|
||||
fileType: 'problem',
|
||||
target,
|
||||
referer: this.request.referer,
|
||||
size: file?.size || 0,
|
||||
});
|
||||
if (!file) {
|
||||
this.response.redirect = await storage.signDownloadLink(
|
||||
target, noDisposition ? undefined : filename, false, 'user',
|
||||
|
||||
Reference in new issue
Block a user