Add optional parameter to verify file only
Not all the time you'd actually want the file content, just the fact that it's over there and that I can open it again.
This commit is contained in:
		
							parent
							
								
									493abd746a
								
							
						
					
					
						commit
						65e8b9686b
					
				
					 1 changed files with 11 additions and 3 deletions
				
			
		|  | @ -2,11 +2,19 @@ | ||||||
|   This script provides network utilities. |   This script provides network utilities. | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
| export async function download(URL, type) { | /*  | ||||||
|  | Download a file from the network or locally. | ||||||
|  | 
 | ||||||
|  | @param {string} URL the URL to download | ||||||
|  | @param {string} type the expected type of file | ||||||
|  | @param {boolean} verify_only whether to verify the file only, not return its content | ||||||
|  | @returns {Promise} the downloaded file | ||||||
|  | */ | ||||||
|  | export async function download(URL, type, verify_only = false) { | ||||||
|   let connect = await fetch(URL), |   let connect = await fetch(URL), | ||||||
|     data; |     data; | ||||||
| 
 | 
 | ||||||
|   if (connect.ok) { |   if (connect.ok && !verify_only) { | ||||||
|     if (type ? type.includes(`json`) || type.includes(`dictionary`) : false) { |     if (type ? type.includes(`json`) || type.includes(`dictionary`) : false) { | ||||||
|       data = connect.json(); |       data = connect.json(); | ||||||
|     } else { |     } else { | ||||||
|  | @ -15,5 +23,5 @@ export async function download(URL, type) { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // Return the filter.
 |   // Return the filter.
 | ||||||
|   return data; |   return (verify_only) ? connect.ok : data; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue