UNPKG

1.98 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.githubUrl = githubUrl;
7exports.getS3LikeProviderBaseUrl = getS3LikeProviderBaseUrl;
8
9/** @private */
10function githubUrl(options, defaultHost = "github.com") {
11 return `${options.protocol || "https"}://${options.host || defaultHost}`;
12}
13
14function 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
28function 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 } // special case, see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro
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
53function 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
65function 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// __ts-babel@6.0.4
77//# sourceMappingURL=publishOptions.js.map
\No newline at end of file