Image download handler

This commit is contained in:
Natsumi
2022-12-13 21:48:34 +13:00
parent 2fd992edf7
commit c630c97c06
6 changed files with 126 additions and 34 deletions

View File

@@ -23807,6 +23807,42 @@ speechSynthesis.getVoices();
);
};
$app.methods.downloadAndSaveImage = async function (url) {
if (!url) {
return;
}
try {
var response = await webApiService.execute({
url,
method: 'GET'
});
if (
response.status !== 200 ||
!response.data.startsWith('data:image/png')
) {
throw new Error(`Error: ${response.data}`);
}
var link = document.createElement('a');
link.href = response.data;
var fileName = `${extractFileId(url)}.png`;
if (!fileName) {
fileName = `${url.split('/').pop()}.png`;
}
if (!fileName) {
fileName = 'image.png';
}
link.setAttribute('download', fileName);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch {
new Noty({
type: 'error',
text: escapeTag(`Failed to download image. ${url}`)
}).show();
}
};
$app = new Vue($app);
window.$app = $app;
})();