electronHttpExecutor.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ElectronHttpExecutor = void 0;
  6. function _bluebirdLst() {
  7. const data = require("bluebird-lst");
  8. _bluebirdLst = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _builderUtilRuntime() {
  14. const data = require("builder-util-runtime");
  15. _builderUtilRuntime = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _electron() {
  21. const data = require("electron");
  22. _electron = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _fsExtraP() {
  28. const data = require("fs-extra-p");
  29. _fsExtraP = function () {
  30. return data;
  31. };
  32. return data;
  33. }
  34. var path = _interopRequireWildcard(require("path"));
  35. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  36. class ElectronHttpExecutor extends _builderUtilRuntime().HttpExecutor {
  37. constructor(proxyLoginCallback) {
  38. super();
  39. this.proxyLoginCallback = proxyLoginCallback;
  40. }
  41. download(url, destination, options) {
  42. var _this = this;
  43. return (0, _bluebirdLst().coroutine)(function* () {
  44. if (options == null || !options.skipDirCreation) {
  45. yield (0, _fsExtraP().ensureDir)(path.dirname(destination));
  46. }
  47. return yield options.cancellationToken.createPromise((resolve, reject, onCancel) => {
  48. _this.doDownload(Object.assign({}, (0, _builderUtilRuntime().configureRequestOptionsFromUrl)(url, {
  49. headers: options.headers || undefined
  50. }), {
  51. redirect: "manual"
  52. }), destination, 0, options, error => {
  53. if (error == null) {
  54. resolve(destination);
  55. } else {
  56. reject(error);
  57. }
  58. }, onCancel);
  59. });
  60. })();
  61. }
  62. doRequest(options, callback) {
  63. const request = _electron().net.request(options);
  64. request.on("response", callback);
  65. this.addProxyLoginHandler(request);
  66. return request;
  67. }
  68. addProxyLoginHandler(request) {
  69. if (this.proxyLoginCallback != null) {
  70. request.on("login", this.proxyLoginCallback);
  71. }
  72. }
  73. addRedirectHandlers(request, options, reject, redirectCount, handler) {
  74. request.on("redirect", (statusCode, method, redirectUrl) => {
  75. if (redirectCount > 10) {
  76. reject(new Error("Too many redirects (> 10)"));
  77. return;
  78. }
  79. handler(_builderUtilRuntime().HttpExecutor.prepareRedirectUrlOptions(redirectUrl, options));
  80. });
  81. }
  82. } exports.ElectronHttpExecutor = ElectronHttpExecutor;
  83. //# sourceMappingURL=electronHttpExecutor.js.map