vue-files-preview-inno
Version:
A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.
48 lines (47 loc) • 2.07 kB
JavaScript
import { defer as v, isXml as u, parse as n } from "./core.mjs";
import x from "./path.mjs";
function R(a, e, l, f) {
var p = typeof window < "u" ? window.URL : !1, m = p ? "blob" : "arraybuffer", r = new v(), s = new XMLHttpRequest(), h = XMLHttpRequest.prototype, o;
"overrideMimeType" in h || Object.defineProperty(h, "overrideMimeType", {
value: function() {
}
}), l && (s.withCredentials = !0), s.onreadystatechange = c, s.onerror = d, s.open("GET", a, !0);
for (o in f)
s.setRequestHeader(o, f[o]);
e == "json" && s.setRequestHeader("Accept", "application/json"), e || (e = new x(a).extension), e == "blob" && (s.responseType = m), u(e) && s.overrideMimeType("text/xml"), e == "binary" && (s.responseType = "arraybuffer"), s.send();
function d(i) {
r.reject(i);
}
function c() {
if (this.readyState === XMLHttpRequest.DONE) {
var i = !1;
if ((this.responseType === "" || this.responseType === "document") && (i = this.responseXML), this.status === 200 || this.status === 0 || i) {
var t;
if (!this.response && !i)
return r.reject({
status: this.status,
message: "Empty Response",
stack: new Error().stack
}), r.promise;
if (this.status === 403)
return r.reject({
status: this.status,
response: this.response,
message: "Forbidden",
stack: new Error().stack
}), r.promise;
i ? t = this.responseXML : u(e) ? t = n(this.response, "text/xml") : e == "xhtml" ? t = n(this.response, "application/xhtml+xml") : e == "html" || e == "htm" ? t = n(this.response, "text/html") : e == "json" ? t = JSON.parse(this.response) : e == "blob" ? p ? t = this.response : t = new Blob([this.response]) : t = this.response, r.resolve(t);
} else
r.reject({
status: this.status,
message: this.response,
stack: new Error().stack
});
}
}
return r.promise;
}
export {
R as default
};
//# sourceMappingURL=request.mjs.map