mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix s3 proxy
This commit is contained in:
2 files changed
+17
-1
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "4.9.13",
|
"version": "4.9.14",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/plugin-api",
|
"main": "src/plugin-api",
|
||||||
"module": "src/plugin-api",
|
"module": "src/plugin-api",
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class RemoteStorageService {
|
|||||||
public client: S3Client;
|
public client: S3Client;
|
||||||
public error = '';
|
public error = '';
|
||||||
public bucket = 'hydro';
|
public bucket = 'hydro';
|
||||||
|
private replaceWithAlternativeUrlFor: Partial<Record<'user' | 'judge', (originalUrl: string) => string>>;
|
||||||
private alternatives: Record<'user' | 'judge', S3Client> = {
|
private alternatives: Record<'user' | 'judge', S3Client> = {
|
||||||
user: null,
|
user: null,
|
||||||
judge: null,
|
judge: null,
|
||||||
@@ -92,17 +93,22 @@ class RemoteStorageService {
|
|||||||
endpoint: endPoint,
|
endpoint: endPoint,
|
||||||
...base,
|
...base,
|
||||||
});
|
});
|
||||||
|
this.replaceWithAlternativeUrlFor = {};
|
||||||
if (/^https?:\/\//.test(endPointForUser)) {
|
if (/^https?:\/\//.test(endPointForUser)) {
|
||||||
this.alternatives.user = new S3Client({
|
this.alternatives.user = new S3Client({
|
||||||
endpoint: endPointForUser,
|
endpoint: endPointForUser,
|
||||||
...base,
|
...base,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.replaceWithAlternativeUrlFor.user = parseAlternativeEndpointUrl(endPointForUser);
|
||||||
}
|
}
|
||||||
if (/^https?:\/\//.test(endPointForJudge)) {
|
if (/^https?:\/\//.test(endPointForJudge)) {
|
||||||
this.alternatives.judge = new S3Client({
|
this.alternatives.judge = new S3Client({
|
||||||
endpoint: endPointForJudge,
|
endpoint: endPointForJudge,
|
||||||
...base,
|
...base,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.replaceWithAlternativeUrlFor.judge = parseAlternativeEndpointUrl(endPointForJudge);
|
||||||
}
|
}
|
||||||
logger.success('Storage connected.');
|
logger.success('Storage connected.');
|
||||||
this.error = null;
|
this.error = null;
|
||||||
@@ -205,6 +211,10 @@ class RemoteStorageService {
|
|||||||
}), {
|
}), {
|
||||||
expiresIn: noExpire ? 24 * 60 * 60 * 7 : 10 * 60,
|
expiresIn: noExpire ? 24 * 60 * 60 * 7 : 10 * 60,
|
||||||
});
|
});
|
||||||
|
// using something like /fs/
|
||||||
|
if (useAlternativeEndpointFor && this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor]) {
|
||||||
|
return this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor](url);
|
||||||
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,6 +234,12 @@ class RemoteStorageService {
|
|||||||
},
|
},
|
||||||
Expires: 600,
|
Expires: 600,
|
||||||
});
|
});
|
||||||
|
if (this.replaceWithAlternativeUrlFor.user) {
|
||||||
|
return {
|
||||||
|
url: this.replaceWithAlternativeUrlFor.user(url),
|
||||||
|
fields,
|
||||||
|
};
|
||||||
|
}
|
||||||
return { url, fields };
|
return { url, fields };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user