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> => {
 | 
			
		||||
      const _url = await normalizeUrlInput(url)
 | 
			
		||||
      const r = await fetch(_url)
 | 
			
		||||
      const blob = await r.blob()
 | 
			
		||||
      saveAs(blob, filename)
 | 
			
		||||
      const a = document.createElement('a')
 | 
			
		||||
      a.href = _url
 | 
			
		||||
      a.dispatchEvent(new MouseEvent('click'))
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,13 +42,13 @@ const main = (): void => {
 | 
			
		|||
  btnList.add({
 | 
			
		||||
    name: 'Download MIDI',
 | 
			
		||||
    action: BtnAction.deprecate(
 | 
			
		||||
      BtnAction.download(() => getFileUrl('midi'), `${filename}.mid`),
 | 
			
		||||
      BtnAction.download(() => getFileUrl('midi')),
 | 
			
		||||
    ),
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  btnList.add({
 | 
			
		||||
    name: 'Download MP3',
 | 
			
		||||
    action: BtnAction.download(() => getFileUrl('mp3'), `${filename}.mp3`),
 | 
			
		||||
    action: BtnAction.download(() => getFileUrl('mp3')),
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  btnList.add({
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue