Implemented download service

This commit is contained in:
2024-12-10 19:52:14 +01:00
parent 150a18cc0b
commit 75cefea4fa
4 changed files with 63 additions and 1 deletions

View File

@@ -44,5 +44,18 @@ window.moonlight = {
(document.head || document.documentElement).appendChild(scriptElement);
}
},
utils: {
download: async function (fileName, contentStreamReference) {
const arrayBuffer = await contentStreamReference.arrayBuffer();
const blob = new Blob([arrayBuffer]);
const url = URL.createObjectURL(blob);
const anchorElement = document.createElement('a');
anchorElement.href = url;
anchorElement.download = fileName ?? '';
anchorElement.click();
anchorElement.remove();
URL.revokeObjectURL(url);
}
}
};