UNPKG

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