the fallback is always text
This commit is contained in:
		
							parent
							
								
									62ad4d58bf
								
							
						
					
					
						commit
						76bf6cefaa
					
				
					 1 changed files with 20 additions and 6 deletions
				
			
		|  | @ -2,7 +2,7 @@ | |||
|   This script provides network utilities. | ||||
| */ | ||||
| 
 | ||||
| /*  | ||||
| /* | ||||
| Download a file from the network or locally. | ||||
| 
 | ||||
| @param {string} URL the URL to download | ||||
|  | @ -11,17 +11,31 @@ Download a file from the network or locally. | |||
| @returns {Promise} the downloaded file | ||||
| */ | ||||
| export async function download(URL, type, verify_only = false) { | ||||
|   const alert = await import(chrome.runtime.getURL(`gui/scripts/alerts.js`)) | ||||
|     .default; | ||||
|   const texts = (await import(chrome.runtime.getURL(`gui/scripts/read.js`))) | ||||
|     .default; | ||||
| 
 | ||||
|   let connect = await fetch(URL), | ||||
|     data; | ||||
| 
 | ||||
|   if (connect.ok && !verify_only) { | ||||
|     if (type ? type.includes(`json`) || type.includes(`dictionary`) : false) { | ||||
|       data = connect.json(); | ||||
|     } else { | ||||
|       data = connect.text(); | ||||
|     data = await connect.text(); | ||||
| 
 | ||||
|     try { | ||||
|     } catch (err) { | ||||
|       if ( | ||||
|         type | ||||
|           ? type.toLowerCase().includes(`json`) || | ||||
|             type.toLowerCase().includes(`dictionary`) | ||||
|           : false | ||||
|       ) { | ||||
|         data = JSON.parse(data); | ||||
|       } | ||||
|       alert.error(texts.localized(`error_msg_notJSON`, false)); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   // Return the filter.
 | ||||
|   return (verify_only) ? connect.ok : data; | ||||
|   return verify_only ? connect.ok : data; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue