diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 12:11:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 12:11:27 +0300 |
commit | 31522c5182bf14886900131c12d17d004ce28534 (patch) | |
tree | 9878537b8db031e4525b1993c1d54f267b3d8fe0 /app/assets/javascripts/blob | |
parent | ad3b511ba360c7fc09fe519396c6d15f09845d66 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r-- | app/assets/javascripts/blob/sketch/index.js | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/app/assets/javascripts/blob/sketch/index.js b/app/assets/javascripts/blob/sketch/index.js index a92161bbc1b..bb29224cda2 100644 --- a/app/assets/javascripts/blob/sketch/index.js +++ b/app/assets/javascripts/blob/sketch/index.js @@ -1,5 +1,5 @@ import JSZip from 'jszip'; -import JSZipUtils from 'jszip-utils'; +import axios from '~/lib/utils/axios_utils'; import { __ } from '~/locale'; export default class SketchLoader { @@ -7,35 +7,28 @@ export default class SketchLoader { this.container = container; this.loadingIcon = this.container.querySelector('.js-loading-icon'); - this.load(); + this.load().catch(() => { + this.error(); + }); } - load() { - return this.getZipFile() - .then((data) => JSZip.loadAsync(data)) - .then((asyncResult) => asyncResult.files['previews/preview.png'].async('uint8array')) - .then((content) => { - const url = window.URL || window.webkitURL; - const blob = new Blob([new Uint8Array(content)], { - type: 'image/png', - }); - const previewUrl = url.createObjectURL(blob); + async load() { + const zipContents = await this.getZipContents(); + const previewContents = await zipContents.files['previews/preview.png'].async('uint8array'); + + const blob = new Blob([previewContents], { + type: 'image/png', + }); - this.render(previewUrl); - }) - .catch(this.error.bind(this)); + this.render(window.URL.createObjectURL(blob)); } - getZipFile() { - return new Promise((resolve, reject) => { - JSZipUtils.getBinaryContent(this.container.dataset.endpoint, (err, data) => { - if (err) { - reject(err); - } else { - resolve(data); - } - }); + async getZipContents() { + const { data } = await axios.get(this.container.dataset.endpoint, { + responseType: 'arraybuffer', }); + + return JSZip.loadAsync(data); } render(previewUrl) { |