core: disable file proxy

This commit is contained in:
undefined committed 2021-12-29 18:09:30 +08:00
1 parent e94846f868
commit 3e7306e232
3 files changed
+7 -39

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.2.35",
"version": "3.2.36",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+3 -19
View File
@@ -95,25 +95,9 @@ export class FSDownloadHandler extends Handler {
target,
size: file?.size || 0,
});
if (!file) {
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
return;
}
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;
if (file['Content-Encoding']) this.response.addHeader('Content-Encoding', file['Content-Encoding']);
if (!noDisposition) this.response.disposition = `attachment; filename=${encodeURIComponent(filename)}`;
} else {
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
}
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
}
}
+3 -19
View File
@@ -617,25 +617,9 @@ export class ProblemFileDownloadHandler extends ProblemDetailHandler {
target,
size: file?.size || 0,
});
if (!file) {
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
return;
}
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;
if (file['Content-Encoding']) this.response.addHeader('Content-Encoding', file['Content-Encoding']);
if (!noDisposition) this.response.disposition = `attachment; filename=${encodeURIComponent(filename)}`;
} else {
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
}
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
}
}