publishOptions.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.githubUrl = githubUrl;
  6. exports.getS3LikeProviderBaseUrl = getS3LikeProviderBaseUrl;
  7. /** @private */
  8. function githubUrl(options, defaultHost = "github.com") {
  9. return `${options.protocol || "https"}://${options.host || defaultHost}`;
  10. }
  11. function getS3LikeProviderBaseUrl(configuration) {
  12. const provider = configuration.provider;
  13. if (provider === "s3") {
  14. return s3Url(configuration);
  15. }
  16. if (provider === "spaces") {
  17. return spacesUrl(configuration);
  18. }
  19. throw new Error(`Not supported provider: ${provider}`);
  20. }
  21. function s3Url(options) {
  22. let url;
  23. if (options.endpoint != null) {
  24. url = `${options.endpoint}/${options.bucket}`;
  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. } // special case, see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro
  29. if (options.region === "us-east-1") {
  30. url = `https://s3.amazonaws.com/${options.bucket}`;
  31. } else {
  32. url = `https://s3-${options.region}.amazonaws.com/${options.bucket}`;
  33. }
  34. } else if (options.region === "cn-north-1") {
  35. url = `https://${options.bucket}.s3.${options.region}.amazonaws.com.cn`;
  36. } else {
  37. url = `https://${options.bucket}.s3.amazonaws.com`;
  38. }
  39. return appendPath(url, options.path);
  40. }
  41. function appendPath(url, p) {
  42. if (p != null && p.length > 0) {
  43. if (!p.startsWith("/")) {
  44. url += "/";
  45. }
  46. url += p;
  47. }
  48. return url;
  49. }
  50. function spacesUrl(options) {
  51. if (options.name == null) {
  52. throw new Error(`name is missing`);
  53. }
  54. if (options.region == null) {
  55. throw new Error(`region is missing`);
  56. }
  57. return appendPath(`https://${options.name}.${options.region}.digitaloceanspaces.com`, options.path);
  58. }
  59. //# sourceMappingURL=publishOptions.js.map