summaryrefslogtreecommitdiff
path: root/src/misc/download-url.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/download-url.ts')
-rw-r--r--src/misc/download-url.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/misc/download-url.ts b/src/misc/download-url.ts
index 463fb555bb..8a8640a8cd 100644
--- a/src/misc/download-url.ts
+++ b/src/misc/download-url.ts
@@ -18,6 +18,7 @@ export async function downloadUrl(url: string, path: string) {
const timeout = 30 * 1000;
const operationTimeout = 60 * 1000;
+ const maxSize = config.maxFileSize || 262144000;
const req = got.stream(url, {
headers: {
@@ -44,6 +45,20 @@ export async function downloadUrl(url: string, path: string) {
req.destroy();
}
}
+
+ const contentLength = res.headers['content-length'];
+ if (contentLength != null) {
+ const size = Number(contentLength);
+ if (size > maxSize) {
+ logger.warn(`maxSize exceeded (${size} > ${maxSize}) on response`);
+ req.destroy();
+ }
+ }
+ }).on('downloadProgress', (progress: Got.Progress) => {
+ if (progress.transferred > maxSize) {
+ logger.warn(`maxSize exceeded (${progress.transferred} > ${maxSize}) on downloadProgress`);
+ req.destroy();
+ }
}).on('error', (e: any) => {
if (e.name === 'HTTPError') {
const statusCode = e.response?.statusCode;