core: add file fallback

This commit is contained in:
undefined committed 2021-08-18 23:20:40 +08:00
1 parent 9037a9bfd3
commit d37f485e30
6 files changed
+27 -7

No files matched your search

+6 -1
View File
@@ -320,7 +320,12 @@ export class ContestProblemFileDownloadHandler extends ContestProblemHandler {
if (typeof this.pdoc.docId === 'string') this.pdoc.docId = this.pdoc.docId.split(':')[1];
const target = `problem/${this.pdoc.domainId}/${this.pdoc.docId}/additional_file/${filename}`;
const file = await storage.getMeta(target);
if (!file) throw new NotFoundError(filename);
if (!file) {
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
return;
}
this.response.etag = file.etag;
const type = lookup(filename).toString();
const shouldProxy = ['image', 'video', 'audio', 'pdf', 'vnd'].filter((i) => type.includes(i)).length;
+6 -1
View File
@@ -184,7 +184,12 @@ export class HomeworkProblemFileDownloadHandler extends HomeworkDetailProblemHan
if (typeof this.pdoc.docId === 'string') this.pdoc.docId = this.pdoc.docId.split(':')[1];
const target = `problem/${this.pdoc.domainId}/${this.pdoc.docId}/additional_file/${filename}`;
const file = await storage.getMeta(target);
if (!file) throw new NotFoundError(filename);
if (!file) {
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
return;
}
this.response.etag = file.etag;
const type = lookup(filename).toString();
const shouldProxy = ['image', 'video', 'audio', 'pdf', 'vnd'].filter((i) => type.includes(i)).length;
+6 -1
View File
@@ -111,7 +111,12 @@ export class FSDownloadHandler extends Handler {
this.response.addHeader('Cache-Control', 'public');
const target = `user/${uid}/${filename}`;
const file = await storage.getMeta(target);
if (!file) throw new NotFoundError(filename);
if (!file) {
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
return;
}
this.response.etag = file.etag;
const type = lookup(filename).toString();
const shouldProxy = ['image', 'video', 'audio', 'pdf', 'vnd'].filter((i) => type.includes(i)).length;
+6 -1
View File
@@ -417,7 +417,12 @@ export class ProblemFileDownloadHandler extends ProblemDetailHandler {
}
const target = `problem/${domainId}/${this.pdoc.docId}/${type}/${filename}`;
const file = await storage.getMeta(target);
if (!file) throw new NotFoundError(filename);
if (!file) {
this.response.redirect = await storage.signDownloadLink(
target, noDisposition ? undefined : filename, false, 'user',
);
return;
}
this.response.etag = file.etag;
const fileType = lookup(filename).toString();
const shouldProxy = ['image', 'video', 'audio', 'pdf', 'vnd'].filter((i) => fileType.includes(i)).length;