chore: create FileManager class for downloading files

This commit is contained in:
Shishkevich D.
2025-04-08 22:17:29 +07:00
committed by GitHub
parent 520f7a2d15
commit 8ef447a997
3 changed files with 22 additions and 15 deletions

View File

@@ -799,4 +799,24 @@ const MediaQueryMixin = {
beforeDestroy() {
window.removeEventListener('resize', this.updateDeviceType);
},
}
class FileManager {
static downloadTextFile(content, filename='file.txt', options = { type: "text/plain" }) {
let link = window.document.createElement('a');
link.download = filename;
link.style.border = '0';
link.style.padding = '0';
link.style.margin = '0';
link.style.position = 'absolute';
link.style.left = '-9999px';
link.style.top = `${window.pageYOffset || window.document.documentElement.scrollTop}px`;
link.href = URL.createObjectURL(new Blob([content], options));
link.click();
URL.revokeObjectURL(link.href);
link.remove();
}
}