Skip to content

Commit

Permalink
Merge pull request #12675 from rtibbles/download_attributes
Browse files Browse the repository at this point in the history
Simplify saving to device
  • Loading branch information
marcellamaki authored Sep 24, 2024
2 parents b1dcd6c + ea0bd73 commit d935029
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

List of the most important changes for each release.

## 0.17.2

### Changed
- Make 'save to device' file downloads initiate immediately by @rtibbles in [#12675](https://github.com/learningequality/kolibri/pull/12675)


## 0.17.1

### Added
Expand Down
2 changes: 1 addition & 1 deletion kolibri/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#: This may not be the exact version as it's subject to modification with
#: get_version() - use ``kolibri.__version__`` for the exact version string.
VERSION = (0, 17, 1)
VERSION = (0, 17, 2)

__author__ = "Learning Equality"
__email__ = "[email protected]"
Expand Down
32 changes: 11 additions & 21 deletions kolibri/core/assets/src/views/ContentRenderer/DownloadButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@
fileOptions() {
const options = this.files.map(file => {
const label = getFilePresetString(file);
const fileId =
file.preset === 'video_subtitle' && file?.lang.lang_name
? file?.lang.lang_name
: file.checksum.slice(0, 6);
return {
label,
url: file.storage_url,
fileName: this.$tr('downloadFilename', {
resourceTitle: this.nodeTitle.length ? this.nodeTitle : file.checksum,
fileExtension: file.extension,
fileId: file.checksum.slice(0, 6),
fileId,
}),
};
});
Expand All @@ -68,26 +72,12 @@
},
methods: {
download(file) {
const req = new XMLHttpRequest();
req.open('GET', file.url, true);
req.responseType = 'blob';
req.onload = function () {
const blob = req.response;
const blobUrl = window.URL.createObjectURL(blob);
try {
const a = document.createElement('a');
a.download = file.fileName;
a.href = blobUrl;
document.body.appendChild(a);
a.click();
a.remove();
} catch (e) {
window.open(file.url, '_blank');
}
};
req.send();
const a = document.createElement('a');
a.download = file.fileName;
a.href = file.url;
document.body.appendChild(a);
a.click();
a.remove();
},
},
$trs: {
Expand Down

0 comments on commit d935029

Please sign in to comment.