1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getS3LikeProviderBaseUrl = exports.githubUrl = void 0;
|
4 |
|
5 | function githubUrl(options, defaultHost = "github.com") {
|
6 | return `${options.protocol || "https"}://${options.host || defaultHost}`;
|
7 | }
|
8 | exports.githubUrl = githubUrl;
|
9 | function getS3LikeProviderBaseUrl(configuration) {
|
10 | const provider = configuration.provider;
|
11 | if (provider === "s3") {
|
12 | return s3Url(configuration);
|
13 | }
|
14 | if (provider === "spaces") {
|
15 | return spacesUrl(configuration);
|
16 | }
|
17 | throw new Error(`Not supported provider: ${provider}`);
|
18 | }
|
19 | exports.getS3LikeProviderBaseUrl = getS3LikeProviderBaseUrl;
|
20 | function s3Url(options) {
|
21 | let url;
|
22 | if (options.endpoint != null) {
|
23 | url = `${options.endpoint}/${options.bucket}`;
|
24 | }
|
25 | else if (options.bucket.includes(".")) {
|
26 | if (options.region == null) {
|
27 | throw new Error(`Bucket name "${options.bucket}" includes a dot, but S3 region is missing`);
|
28 | }
|
29 |
|
30 | if (options.region === "us-east-1") {
|
31 | url = `https://s3.amazonaws.com/${options.bucket}`;
|
32 | }
|
33 | else {
|
34 | url = `https://s3-${options.region}.amazonaws.com/${options.bucket}`;
|
35 | }
|
36 | }
|
37 | else if (options.region === "cn-north-1") {
|
38 | url = `https://${options.bucket}.s3.${options.region}.amazonaws.com.cn`;
|
39 | }
|
40 | else {
|
41 | url = `https://${options.bucket}.s3.amazonaws.com`;
|
42 | }
|
43 | return appendPath(url, options.path);
|
44 | }
|
45 | function appendPath(url, p) {
|
46 | if (p != null && p.length > 0) {
|
47 | if (!p.startsWith("/")) {
|
48 | url += "/";
|
49 | }
|
50 | url += p;
|
51 | }
|
52 | return url;
|
53 | }
|
54 | function spacesUrl(options) {
|
55 | if (options.name == null) {
|
56 | throw new Error(`name is missing`);
|
57 | }
|
58 | if (options.region == null) {
|
59 | throw new Error(`region is missing`);
|
60 | }
|
61 | return appendPath(`https://${options.name}.${options.region}.digitaloceanspaces.com`, options.path);
|
62 | }
|
63 |
|
\ | No newline at end of file |