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