providerFactory.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isUrlProbablySupportMultiRangeRequests = isUrlProbablySupportMultiRangeRequests;
  6. exports.createClient = createClient;
  7. function _builderUtilRuntime() {
  8. const data = require("builder-util-runtime");
  9. _builderUtilRuntime = function () {
  10. return data;
  11. };
  12. return data;
  13. }
  14. function _BintrayProvider() {
  15. const data = require("./providers/BintrayProvider");
  16. _BintrayProvider = function () {
  17. return data;
  18. };
  19. return data;
  20. }
  21. function _GenericProvider() {
  22. const data = require("./providers/GenericProvider");
  23. _GenericProvider = function () {
  24. return data;
  25. };
  26. return data;
  27. }
  28. function _GitHubProvider() {
  29. const data = require("./providers/GitHubProvider");
  30. _GitHubProvider = function () {
  31. return data;
  32. };
  33. return data;
  34. }
  35. function _PrivateGitHubProvider() {
  36. const data = require("./providers/PrivateGitHubProvider");
  37. _PrivateGitHubProvider = function () {
  38. return data;
  39. };
  40. return data;
  41. }
  42. function isUrlProbablySupportMultiRangeRequests(url) {
  43. return !url.includes("s3.amazonaws.com");
  44. }
  45. function createClient(data, updater) {
  46. // noinspection SuspiciousTypeOfGuard
  47. if (typeof data === "string") {
  48. throw (0, _builderUtilRuntime().newError)("Please pass PublishConfiguration object", "ERR_UPDATER_INVALID_PROVIDER_CONFIGURATION");
  49. }
  50. const httpExecutor = updater.httpExecutor;
  51. const provider = data.provider;
  52. switch (provider) {
  53. case "github":
  54. const githubOptions = data;
  55. const token = (githubOptions.private ? process.env.GH_TOKEN || process.env.GITHUB_TOKEN : null) || githubOptions.token;
  56. if (token == null) {
  57. return new (_GitHubProvider().GitHubProvider)(githubOptions, updater, httpExecutor);
  58. } else {
  59. return new (_PrivateGitHubProvider().PrivateGitHubProvider)(githubOptions, updater, token, httpExecutor);
  60. }
  61. case "s3":
  62. case "spaces":
  63. return new (_GenericProvider().GenericProvider)({
  64. provider: "generic",
  65. url: (0, _builderUtilRuntime().getS3LikeProviderBaseUrl)(data),
  66. channel: data.channel || null
  67. }, updater, provider === "spaces"
  68. /* https://github.com/minio/minio/issues/5285#issuecomment-350428955 */
  69. );
  70. case "generic":
  71. const options = data;
  72. return new (_GenericProvider().GenericProvider)(options, updater, options.useMultipleRangeRequest !== false && isUrlProbablySupportMultiRangeRequests(options.url));
  73. case "bintray":
  74. return new (_BintrayProvider().BintrayProvider)(data, httpExecutor);
  75. default:
  76. throw (0, _builderUtilRuntime().newError)(`Unsupported provider: ${provider}`, "ERR_UPDATER_UNSUPPORTED_PROVIDER");
  77. }
  78. }
  79. //# sourceMappingURL=providerFactory.js.map