add response downloading

This commit is contained in:
buzz-lightsnack-2007 2024-03-28 11:27:16 +08:00
parent 3930e06f2b
commit 7631d344e5

19
scripts/net.js Normal file
View file

@ -0,0 +1,19 @@
/* net.js
This script provides network utilities.
*/
export async function download(URL, type) {
let connect = await fetch(URL),
data;
if (connect.ok) {
if (type ? type.includes(`json`) || type.includes(`dictionary`) : false) {
data = connect.json();
} else {
data = connect.text();
}
}
// Return the filter.
return data;
}