@codex-storage/marketplace-ui-components
Version:
Marketplace UI components for Codex decentralized storage network.
52 lines (51 loc) • 1.84 kB
JavaScript
var u = Object.defineProperty;
var h = (r, t, e) => t in r ? u(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
var a = (r, t, e) => h(r, typeof t != "symbol" ? t + "" : t, e);
var d = class extends Error {
constructor(t, { code: e, errors: s, sourceStack: o } = {}) {
super(t);
a(this, "code");
a(this, "errors");
a(this, "sourceStack");
this.code = e || null, this.errors = s || null, this.sourceStack = o || null;
}
}, m = class {
constructor(r, t, e) {
a(this, "file");
a(this, "onProgress");
a(this, "metadata");
a(this, "xhr");
this.file = r, this.onProgress = t, this.metadata = e;
}
upload(r, { auth: t }) {
const e = new XMLHttpRequest();
return this.xhr = e, new Promise((s) => {
var o, n;
e.upload.onprogress = (i) => {
var l;
i.lengthComputable && ((l = this.onProgress) == null || l.call(this, i.loaded, i.total));
}, e.open("POST", r, !0), (o = this.metadata) != null && o.filename && e.setRequestHeader(
"Content-Disposition",
'attachment; filename="' + this.metadata.filename + '"'
), t != null && t.basic && e.setRequestHeader("Authorization", "Basic " + t.basic), (n = this.metadata) != null && n.mimetype && e.setRequestHeader("Content-Type", this.metadata.mimetype), e.send(this.file), e.onload = function() {
e.status != 200 ? s({
error: !0,
data: new d(e.responseText, { code: e.status })
}) : s({ error: !1, data: e.response });
}, e.onerror = function() {
s({
error: !0,
data: new d("Something went wrong during the file upload.")
});
};
});
}
abort() {
var r;
(r = this.xhr) == null || r.abort();
}
};
export {
m as B
};
//# sourceMappingURL=browser-DTlYvKdE.js.map