core: use etag when proxy files

This commit is contained in:
undefined committed 2021-08-23 12:04:11 +08:00
1 parent ebe0a08d3e
commit bff83350a0
5 files changed
+5 -5

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.33.2",
"version": "2.33.3",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+1 -1
View File
@@ -325,10 +325,10 @@ export class ContestProblemFileDownloadHandler extends ContestProblemHandler {
);
return;
}
this.response.etag = file.etag;
const type = lookup(filename).toString();
const shouldProxy = ['image', 'video', 'audio', 'pdf', 'vnd'].filter((i) => type.includes(i)).length;
if (shouldProxy && file.size! < 32 * 1024 * 1024) {
this.response.etag = file.etag;
this.response.body = await storage.get(target);
this.response.type = file['Content-Type'] || type;
this.response.disposition = `attachment; filename=${encodeURIComponent(filename)}`;
+1 -1
View File
@@ -190,10 +190,10 @@ export class HomeworkProblemFileDownloadHandler extends HomeworkDetailProblemHan
);
return;
}
this.response.etag = file.etag;
const type = lookup(filename).toString();
const shouldProxy = ['image', 'video', 'audio', 'pdf', 'vnd'].filter((i) => type.includes(i)).length;
if (shouldProxy && file.size! < 32 * 1024 * 1024) {
this.response.etag = file.etag;
this.response.body = await storage.get(target);
this.response.type = file['Content-Type'] || type;
this.response.disposition = `attachment; filename=${encodeURIComponent(filename)}`;
+1 -1
View File
@@ -116,10 +116,10 @@ export class FSDownloadHandler extends Handler {
);
return;
}
this.response.etag = file.etag;
const type = lookup(filename).toString();
const shouldProxy = ['image', 'video', 'audio', 'pdf', 'vnd'].filter((i) => type.includes(i)).length;
if (shouldProxy && file.size! < 32 * 1024 * 1024) {
this.response.etag = file.etag;
this.response.body = await storage.get(target);
this.response.type = file['Content-Type'] || type;
this.response.disposition = `attachment; filename=${encodeURIComponent(filename)}`;
+1 -1
View File
@@ -424,10 +424,10 @@ export class ProblemFileDownloadHandler extends ProblemDetailHandler {
);
return;
}
this.response.etag = file.etag;
const fileType = lookup(filename).toString();
const shouldProxy = ['image', 'video', 'audio', 'pdf', 'vnd'].filter((i) => fileType.includes(i)).length;
if (shouldProxy && file.size! < 32 * 1024 * 1024) {
this.response.etag = file.etag;
this.response.body = await storage.get(target);
this.response.type = file['Content-Type'] || fileType;
this.response.disposition = `attachment; filename=${encodeURIComponent(filename)}`;