From c92d03e2044fc8b3dbdc17e89d5bdda169d20d9c Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 12 Apr 2023 21:18:07 +0800 Subject: [PATCH] core: fix s3 proxy --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/service/storage.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index f75c9a8f..3ac53504 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "4.9.13", + "version": "4.9.14", "bin": "bin/hydrooj.js", "main": "src/plugin-api", "module": "src/plugin-api", diff --git a/packages/hydrooj/src/service/storage.ts b/packages/hydrooj/src/service/storage.ts index 1680545e..77c52327 100644 --- a/packages/hydrooj/src/service/storage.ts +++ b/packages/hydrooj/src/service/storage.ts @@ -61,6 +61,7 @@ class RemoteStorageService { public client: S3Client; public error = ''; public bucket = 'hydro'; + private replaceWithAlternativeUrlFor: Partial string>>; private alternatives: Record<'user' | 'judge', S3Client> = { user: null, judge: null, @@ -92,17 +93,22 @@ class RemoteStorageService { endpoint: endPoint, ...base, }); + this.replaceWithAlternativeUrlFor = {}; if (/^https?:\/\//.test(endPointForUser)) { this.alternatives.user = new S3Client({ endpoint: endPointForUser, ...base, }); + } else { + this.replaceWithAlternativeUrlFor.user = parseAlternativeEndpointUrl(endPointForUser); } if (/^https?:\/\//.test(endPointForJudge)) { this.alternatives.judge = new S3Client({ endpoint: endPointForJudge, ...base, }); + } else { + this.replaceWithAlternativeUrlFor.judge = parseAlternativeEndpointUrl(endPointForJudge); } logger.success('Storage connected.'); this.error = null; @@ -205,6 +211,10 @@ class RemoteStorageService { }), { expiresIn: noExpire ? 24 * 60 * 60 * 7 : 10 * 60, }); + // using something like /fs/ + if (useAlternativeEndpointFor && this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor]) { + return this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor](url); + } return url; } @@ -224,6 +234,12 @@ class RemoteStorageService { }, Expires: 600, }); + if (this.replaceWithAlternativeUrlFor.user) { + return { + url: this.replaceWithAlternativeUrlFor.user(url), + fields, + }; + } return { url, fields }; }