download.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Download = void 0;
  6. var _path = _interopRequireDefault(require("path"));
  7. var _page = require("./page");
  8. var _utils = require("../utils");
  9. var _artifact = require("./artifact");
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. /**
  12. * Copyright (c) Microsoft Corporation.
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License");
  15. * you may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. class Download {
  27. constructor(page, downloadsPath, uuid, url, suggestedFilename) {
  28. this.artifact = void 0;
  29. this.url = void 0;
  30. this._page = void 0;
  31. this._suggestedFilename = void 0;
  32. const unaccessibleErrorMessage = page._browserContext._options.acceptDownloads === 'deny' ? 'Pass { acceptDownloads: true } when you are creating your browser context.' : undefined;
  33. this.artifact = new _artifact.Artifact(page, _path.default.join(downloadsPath, uuid), unaccessibleErrorMessage, () => {
  34. return this._page._browserContext.cancelDownload(uuid);
  35. });
  36. this._page = page;
  37. this.url = url;
  38. this._suggestedFilename = suggestedFilename;
  39. page._browserContext._downloads.add(this);
  40. if (suggestedFilename !== undefined) this._page.emit(_page.Page.Events.Download, this);
  41. }
  42. _filenameSuggested(suggestedFilename) {
  43. (0, _utils.assert)(this._suggestedFilename === undefined);
  44. this._suggestedFilename = suggestedFilename;
  45. this._page.emit(_page.Page.Events.Download, this);
  46. }
  47. suggestedFilename() {
  48. return this._suggestedFilename;
  49. }
  50. }
  51. exports.Download = Download;