perf: download files directly
less waiting time
This commit is contained in:
parent
4980852501
commit
ef6cd56f4f
2 changed files with 6 additions and 6 deletions
|
@ -105,12 +105,12 @@ export namespace BtnAction {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const download = (url: UrlInput, filename?: string): BtnAction => {
|
export const download = (url: UrlInput): BtnAction => {
|
||||||
return process(async (): Promise<any> => {
|
return process(async (): Promise<any> => {
|
||||||
const _url = await normalizeUrlInput(url)
|
const _url = await normalizeUrlInput(url)
|
||||||
const r = await fetch(_url)
|
const a = document.createElement('a')
|
||||||
const blob = await r.blob()
|
a.href = _url
|
||||||
saveAs(blob, filename)
|
a.dispatchEvent(new MouseEvent('click'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,13 +42,13 @@ const main = (): void => {
|
||||||
btnList.add({
|
btnList.add({
|
||||||
name: 'Download MIDI',
|
name: 'Download MIDI',
|
||||||
action: BtnAction.deprecate(
|
action: BtnAction.deprecate(
|
||||||
BtnAction.download(() => getFileUrl('midi'), `${filename}.mid`),
|
BtnAction.download(() => getFileUrl('midi')),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
btnList.add({
|
btnList.add({
|
||||||
name: 'Download MP3',
|
name: 'Download MP3',
|
||||||
action: BtnAction.download(() => getFileUrl('mp3'), `${filename}.mp3`),
|
action: BtnAction.download(() => getFileUrl('mp3')),
|
||||||
})
|
})
|
||||||
|
|
||||||
btnList.add({
|
btnList.add({
|
||||||
|
|
Loading…
Reference in a new issue