From 65e8b9686b358047a9f54807ab9ad7778d2be550 Mon Sep 17 00:00:00 2001 From: buzzcode2007 <73412182+buzz_lightsnack_2007@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:59:06 +0800 Subject: [PATCH] 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. --- scripts/net.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/net.js b/scripts/net.js index 263d328..17348d2 100644 --- a/scripts/net.js +++ b/scripts/net.js @@ -2,11 +2,19 @@ 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), data; - if (connect.ok) { + if (connect.ok && !verify_only) { if (type ? type.includes(`json`) || type.includes(`dictionary`) : false) { data = connect.json(); } else { @@ -15,5 +23,5 @@ export async function download(URL, type) { } // Return the filter. - return data; + return (verify_only) ? connect.ok : data; }