Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Job Launcher] Parse url #1182

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions packages/apps/job-launcher/server/src/common/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export async function getRate(from: string, to: string): Promise<number> {
export const parseUrl = (url: string): {
endPoint: string,
bucket: string,
region: string,
useSSL: boolean,
filename?: string,
port?: number,
Expand All @@ -50,14 +51,15 @@ export const parseUrl = (url: string): {
endPoint: 'storage.googleapis.com',
},
{
regex: /^https:\/\/s3\.[a-z0-9-]+\.amazonaws\.com\/([^/]+)\/?$/,
regex: /^https:\/\/s3\.([a-z0-9-]+)\.amazonaws\.com\/([^/]+)\/?$/,
endPoint: 's3.amazonaws.com',

},
{
regex: /^https:\/\/([^\.]+)\.s3\.[a-z0-9-]+\.amazonaws\.com\/?$/,
regex: /^https:\/\/([^\.]+)\.s3\.([a-z0-9-]+)\.amazonaws\.com\/?$/,
endPoint: 's3.amazonaws.com',
},
{
{
regex: /^https?:\/\/([^/:]+)(?::(\d+))?(\/.*)?/,
endPoint: '$1',
port: '$2',
Expand All @@ -66,16 +68,25 @@ export const parseUrl = (url: string): {

for (const { regex, endPoint, port } of patterns) {
const match = url.match(regex);

if (match) {
const parts = match[3] ? match[3].split('/').filter(part => part) : [];
const bucket = parts[0] || match[1] || '';
const [, param1, param2, path] = match;
const parts = path ? path.split('/').filter(part => part) : [];
const bucket = parts[0] || (patterns[2].regex === regex ? param2 : param1);
const filename = parts.length > 1 ? parts[parts.length - 1] : undefined;

let region = '';
if (regex === patterns[2].regex) {
region = param1;
} else if (regex === patterns[3].regex) {
region = param2;
}

return {
useSSL: url.startsWith('https:'),
endPoint: endPoint.replace('$1', match[1]),
port: port && match[2] ? Number(match[2]) : undefined,
endPoint: endPoint.replace('$1', param1),
region,
port: port && param2 ? Number(param2) || undefined : undefined,
bucket,
filename,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ export class JobService {
const storageClient = new StorageClient({
endPoint: storageData.endPoint,
port: storageData.port,
useSSL: false,
useSSL: storageData.useSSL,
region: storageData.region
});

const totalImages = (await storageClient.listObjects(storageData.bucket))
Expand Down