web/src/component/util.js

31 lines
811 B
JavaScript
Raw Normal View History

2020-02-06 08:01:35 +00:00
export function DownloadBlobMusic(data, format) {
const a = document.createElement('a');
a.href = data.file;
switch (format) {
2020-02-23 05:45:30 +00:00
default:
2020-02-06 08:01:35 +00:00
case "1":
2020-02-23 05:45:30 +00:00
a.download = data.artist + " - " + data.title + "." + data.ext;
2020-02-06 08:01:35 +00:00
break;
case "2":
2020-02-23 05:45:30 +00:00
a.download = data.title + "." + data.ext;
2020-02-06 08:01:35 +00:00
break;
case "3":
a.download = data.title + " - " + data.artist + "." + data.ext;
break;
2020-02-23 05:45:30 +00:00
case "4":
a.download = data.rawFilename + "." + data.ext;
break;
2020-02-06 08:01:35 +00:00
}
document.body.append(a);
a.click();
a.remove();
}
export function RemoveBlobMusic(data) {
URL.revokeObjectURL(data.file);
if (data.picture.startsWith("blob:")) {
URL.revokeObjectURL(data.picture);
}
2020-02-06 08:01:35 +00:00
}