UNPKG

ayongui

Version:
32 lines (31 loc) 804 B
function z({ action: c, name: d, file: t, method: i, headers: u, data: o, withCredentials: l, progressCallback: p }) { return new Promise((h, f) => { const a = t.stream().getReader(), m = t.size; let r = !1, s = 0; const n = new FormData(); n.append(d, t); for (let e in o) n.append(e, o[e]); fetch(c, { method: i, credentials: l ? "include" : "omit", headers: u, body: n }).then((e) => { if (!e.ok) throw r = !0, new Error("Upload failed"); h(e); }).catch((e) => { r = !0, f(e); }), a.read().then(function e({ done: g, value: k }) { if (g || r) return; s += k.length; const w = s / m * 100; return p(w), a.read().then(e); }); }); } export { z as trackUploadProgress };