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:
buzzcode2007 2024-04-01 14:59:06 +08:00
parent 493abd746a
commit 65e8b9686b

View file

@ -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;
} }