UNPKG

vue-files-preview-inno

Version:

A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.

1 lines 5.97 kB
{"version":3,"file":"request.mjs","sources":["../../../../../../node_modules/epubjs/src/utils/request.js"],"sourcesContent":["import {defer, isXml, parse} from \"./core\";\nimport Path from \"./path\";\n\nfunction request(url, type, withCredentials, headers) {\n\tvar supportsURL = (typeof window != \"undefined\") ? window.URL : false; // TODO: fallback for url if window isn't defined\n\tvar BLOB_RESPONSE = supportsURL ? \"blob\" : \"arraybuffer\";\n\n\tvar deferred = new defer();\n\n\tvar xhr = new XMLHttpRequest();\n\n\t//-- Check from PDF.js:\n\t// https://github.com/mozilla/pdf.js/blob/master/web/compatibility.js\n\tvar xhrPrototype = XMLHttpRequest.prototype;\n\n\tvar header;\n\n\tif (!(\"overrideMimeType\" in xhrPrototype)) {\n\t\t// IE10 might have response, but not overrideMimeType\n\t\tObject.defineProperty(xhrPrototype, \"overrideMimeType\", {\n\t\t\tvalue: function xmlHttpRequestOverrideMimeType() {}\n\t\t});\n\t}\n\n\tif(withCredentials) {\n\t\txhr.withCredentials = true;\n\t}\n\n\txhr.onreadystatechange = handler;\n\txhr.onerror = err;\n\n\txhr.open(\"GET\", url, true);\n\n\tfor(header in headers) {\n\t\txhr.setRequestHeader(header, headers[header]);\n\t}\n\n\tif(type == \"json\") {\n\t\txhr.setRequestHeader(\"Accept\", \"application/json\");\n\t}\n\n\t// If type isn\"t set, determine it from the file extension\n\tif(!type) {\n\t\ttype = new Path(url).extension;\n\t}\n\n\tif(type == \"blob\"){\n\t\txhr.responseType = BLOB_RESPONSE;\n\t}\n\n\n\tif(isXml(type)) {\n\t\t// xhr.responseType = \"document\";\n\t\txhr.overrideMimeType(\"text/xml\"); // for OPF parsing\n\t}\n\n\tif(type == \"xhtml\") {\n\t\t// xhr.responseType = \"document\";\n\t}\n\n\tif(type == \"html\" || type == \"htm\") {\n\t\t// xhr.responseType = \"document\";\n\t}\n\n\tif(type == \"binary\") {\n\t\txhr.responseType = \"arraybuffer\";\n\t}\n\n\txhr.send();\n\n\tfunction err(e) {\n\t\tdeferred.reject(e);\n\t}\n\n\tfunction handler() {\n\t\tif (this.readyState === XMLHttpRequest.DONE) {\n\t\t\tvar responseXML = false;\n\n\t\t\tif(this.responseType === \"\" || this.responseType === \"document\") {\n\t\t\t\tresponseXML = this.responseXML;\n\t\t\t}\n\n\t\t\tif (this.status === 200 || this.status === 0 || responseXML) { //-- Firefox is reporting 0 for blob urls\n\t\t\t\tvar r;\n\n\t\t\t\tif (!this.response && !responseXML) {\n\t\t\t\t\tdeferred.reject({\n\t\t\t\t\t\tstatus: this.status,\n\t\t\t\t\t\tmessage : \"Empty Response\",\n\t\t\t\t\t\tstack : new Error().stack\n\t\t\t\t\t});\n\t\t\t\t\treturn deferred.promise;\n\t\t\t\t}\n\n\t\t\t\tif (this.status === 403) {\n\t\t\t\t\tdeferred.reject({\n\t\t\t\t\t\tstatus: this.status,\n\t\t\t\t\t\tresponse: this.response,\n\t\t\t\t\t\tmessage : \"Forbidden\",\n\t\t\t\t\t\tstack : new Error().stack\n\t\t\t\t\t});\n\t\t\t\t\treturn deferred.promise;\n\t\t\t\t}\n\t\t\t\tif(responseXML){\n\t\t\t\t\tr = this.responseXML;\n\t\t\t\t} else\n\t\t\t\tif(isXml(type)){\n\t\t\t\t\t// xhr.overrideMimeType(\"text/xml\"); // for OPF parsing\n\t\t\t\t\t// If this.responseXML wasn't set, try to parse using a DOMParser from text\n\t\t\t\t\tr = parse(this.response, \"text/xml\");\n\t\t\t\t}else\n\t\t\t\tif(type == \"xhtml\"){\n\t\t\t\t\tr = parse(this.response, \"application/xhtml+xml\");\n\t\t\t\t}else\n\t\t\t\tif(type == \"html\" || type == \"htm\"){\n\t\t\t\t\tr = parse(this.response, \"text/html\");\n\t\t\t\t}else\n\t\t\t\tif(type == \"json\"){\n\t\t\t\t\tr = JSON.parse(this.response);\n\t\t\t\t}else\n\t\t\t\tif(type == \"blob\"){\n\n\t\t\t\t\tif(supportsURL) {\n\t\t\t\t\t\tr = this.response;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t//-- Safari doesn't support responseType blob, so create a blob from arraybuffer\n\t\t\t\t\t\tr = new Blob([this.response]);\n\t\t\t\t\t}\n\n\t\t\t\t}else{\n\t\t\t\t\tr = this.response;\n\t\t\t\t}\n\n\t\t\t\tdeferred.resolve(r);\n\t\t\t} else {\n\n\t\t\t\tdeferred.reject({\n\t\t\t\t\tstatus: this.status,\n\t\t\t\t\tmessage : this.response,\n\t\t\t\t\tstack : new Error().stack\n\t\t\t\t});\n\n\t\t\t}\n\t\t}\n\t}\n\n\treturn deferred.promise;\n}\n\nexport default request;\n"],"names":["request","url","type","withCredentials","headers","supportsURL","BLOB_RESPONSE","deferred","defer","xhr","xhrPrototype","header","handler","err","Path","isXml","e","responseXML","r","parse"],"mappings":";;AAGA,SAASA,EAAQC,GAAKC,GAAMC,GAAiBC,GAAS;AACrD,MAAIC,IAAe,OAAO,SAAU,MAAe,OAAO,MAAM,IAC5DC,IAAgBD,IAAc,SAAS,eAEvCE,IAAW,IAAIC,EAAK,GAEpBC,IAAM,IAAI,eAAc,GAIxBC,IAAe,eAAe,WAE9BC;AAEJ,EAAM,sBAAsBD,KAE3B,OAAO,eAAeA,GAAc,oBAAoB;AAAA,IACvD,OAAO,WAA0C;AAAA,IAAC;AAAA,EACrD,CAAG,GAGCP,MACFM,EAAI,kBAAkB,KAGvBA,EAAI,qBAAqBG,GACzBH,EAAI,UAAUI,GAEdJ,EAAI,KAAK,OAAOR,GAAK,EAAI;AAEzB,OAAIU,KAAUP;AACb,IAAAK,EAAI,iBAAiBE,GAAQP,EAAQO,CAAM,CAAC;AAG7C,EAAGT,KAAQ,UACVO,EAAI,iBAAiB,UAAU,kBAAkB,GAI9CP,MACHA,IAAO,IAAIY,EAAKb,CAAG,EAAE,YAGnBC,KAAQ,WACVO,EAAI,eAAeH,IAIjBS,EAAMb,CAAI,KAEZO,EAAI,iBAAiB,UAAU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