UNPKG

naive-upload

Version:

<p align="left"> <a href="https://www.npmjs.org/package/naive-upload"> <img src="https://img.shields.io/npm/v/naive-upload.svg"> </a> <a href="https://bundlephobia.com/package/naive-upload@latest"> <img src="https://img.shields.io/bundl

71 lines (70 loc) 1.72 kB
const p = () => { let o; const r = (s, e, l) => { var d; const a = new XMLHttpRequest(); if (a.overrideMimeType("application/octet-stream"), e) for (const t of e.keys()) a.setRequestHeader(t, (d = e.get(t)) != null ? d : ""); a.upload.onprogress = (t) => { postMessage({ type: "UP_PROGRESS", data: { preLoaded: t.total, total: t.total, loaded: t.loaded } }); }, a.onabort = (t) => { postMessage({ type: "UP_CANCEL", data: { preLoaded: t.total, total: t.total, loaded: t.loaded } }); }, a.onreadystatechange = () => { a.readyState === 4 && a.status === 200 && postMessage({ type: "UP_COMPLETED", data: JSON.parse(a.response) }); }, a.onerror = (t) => { postMessage({ type: "UP_FAILED", data: { preLoaded: t.total, total: t.total, loaded: t.loaded } }); }, a.ontimeout = (t) => { postMessage({ type: "UP_TIMEOUT", data: { preLoaded: t.total, total: t.total, loaded: t.loaded } }); }, a.open("POST", s, !0), a.send(l), o = a; }; onmessage = (s) => { switch (s.data.type) { case "DOWN_UPLOAD": const e = s.data.data; r(e.url, e.headers, e.buffer); break; case "DOWN_CANCEL": o && o.readyState !== 4 && o.abort(); break; case "DOWN_CLOSE": close(); break; } }; }, c = new Blob([`(${p.toString()})()`]); export { c as UploadWorkerScript }; //# sourceMappingURL=UploadWorkerScript.js.map