From ac9a4b816ef776f96c9fb3b47f64768aa3221285 Mon Sep 17 00:00:00 2001 From: Alessandro Pellizzari Date: Tue, 23 Nov 2021 16:42:31 +0100 Subject: [PATCH] release v1.1.23 --- dist/js-file-downloader.js | 8 ++++---- dist/js-file-downloader.js.map | 2 +- dist/js-file-downloader.min.js | 4 ++-- dist/js-file-downloader.min.js.map | 2 +- package.json | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dist/js-file-downloader.js b/dist/js-file-downloader.js index a170a8d..56112df 100644 --- a/dist/js-file-downloader.js +++ b/dist/js-file-downloader.js @@ -169,7 +169,7 @@ var downloadException = DownloadException; __webpack_require__.r(__webpack_exports__); /* harmony import */ var _exception__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./exception */ "./src/exception.js"); /*! - * JS File Downloader v 1.1.22 + * JS File Downloader v 1.1.23 * https://github.com/AleeeKoi/js-file-downloader * * Copyright Alessandro Pellizzari @@ -229,12 +229,12 @@ var JsFileDownloader = /*#__PURE__*/function () { var _this = this; return new Promise(function (resolve, reject) { - _this.initDonwload(resolve, reject); + _this.initDownload(resolve, reject); }); } }, { - key: "initDonwload", - value: function initDonwload(resolve, reject) { + key: "initDownload", + value: function initDownload(resolve, reject) { var _this2 = this; var fallback = function fallback() { diff --git a/dist/js-file-downloader.js.map b/dist/js-file-downloader.js.map index eea9976..69d21ed 100644 --- a/dist/js-file-downloader.js.map +++ b/dist/js-file-downloader.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://jsFileDownloader/webpack/universalModuleDefinition","webpack://jsFileDownloader/webpack/bootstrap","webpack://jsFileDownloader/./src/exception.js","webpack://jsFileDownloader/./src/index.js"],"names":["DownloadException","message","request","name","Error","downloadException","DEFAULT_PARAMS","timeout","headers","forceDesktopMode","autoStart","withCredentials","method","nameCallback","contentType","body","nativeFallbackOnError","JsFileDownloader","customParams","params","Object","assign","link","createLink","downloadFile","Promise","resolve","reject","initDonwload","fallback","target","href","url","clickLink","isMobile","createRequest","onload","parseInt","status","startDownload","ontimeout","onerror","send","test","navigator","userAgent","XMLHttpRequest","open","setRequestHeader","forEach","header","value","responseType","process","addEventListener","onloadstart","includeCredentials","filename","content","getResponseHeader","contentParts","replace","match","extractedName","length","split","pop","document","createElement","style","display","event","MouseEvent","e","createEvent","initMouseEvent","window","dispatchEvent","response","fileName","file","options","type","File","Blob","lastModifiedDate","Date","getFileName","getFile","msSaveOrOpenBlob","objectUrl","URL","createObjectURL","download","setTimeout","webkitURL","revokeObjectURL"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClFO,IAAMA,iBAAb;AAAA;;AAAA;;AACE,6BAAaC,OAAb,EAAsBC,OAAtB,EAA+B;AAAA;;AAAA;;AAC7B,0DAA2BD,OAA3B;AACA,UAAKC,OAAL,GAAeA,OAAf;AACA,UAAKC,IAAL,GAAY,mBAAZ;AAH6B;AAI9B;;AALH;AAAA,iCAAuCC,KAAvC;AAMC;AAED;AACA;AACA;;AACO,IAAMC,iBAAiB,GAAGL,iBA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CAA2DN,SAA3D;AACD,OAFS,EAEP,OAAO,EAFA,CAAV;AAIA,aAAO,IAAP;AACD;;;;;;AAGYzE,+EAAf,E","file":"js-file-downloader.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"jsFileDownloader\"] = factory();\n\telse\n\t\troot[\"jsFileDownloader\"] = factory();\n})(this, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/index.js\");\n","export class DownloadException extends Error {\n constructor (message, request) {\n super(`Downloader error: ${message}`);\n this.request = request;\n this.name = 'DownloadException';\n }\n};\n\n/**\n * @deprecated use DownloadException instead, it will be removed in next releases!\n */\nexport const downloadException = DownloadException;\n","/*!\n * JS File Downloader v ##package_version##\n * https://github.com/AleeeKoi/js-file-downloader\n *\n * Copyright Alessandro Pellizzari\n * Released under the MIT license\n * http://opensource.org/licenses/MIT\n */\n\n'use strict';\n\nimport { DownloadException } from './exception';\n\nconst DEFAULT_PARAMS = {\n timeout: 40000,\n headers: [],\n forceDesktopMode: false,\n autoStart: true,\n withCredentials: false,\n method: 'GET',\n nameCallback: name => name,\n contentType: 'application/x-www-form-urlencoded',\n body: null,\n nativeFallbackOnError: false\n};\n\nclass JsFileDownloader {\n\n /**\n * Create a new JsFileDownloader instance\n * You need to define a {String} \"url\" params and other\n * @param {Object} customParams\n */\n constructor (customParams = {}) {\n this.params = Object.assign({}, DEFAULT_PARAMS, customParams);\n this.link = this.createLink();\n this.request = null;\n\n if (this.params.autoStart) return this.downloadFile();\n\n return this;\n }\n\n start () {\n return this.downloadFile();\n }\n\n downloadFile () {\n return new Promise((resolve, reject) => {\n this.initDonwload(resolve, reject);\n });\n }\n\n initDonwload (resolve, reject) {\n\n const fallback = () => {\n this.link.target = '_blank';\n this.link.href = this.params.url;\n this.clickLink();\n };\n\n // fallback for old browsers\n if (!('download' in this.link) || this.isMobile()) {\n fallback();\n return resolve();\n }\n\n this.request = this.createRequest();\n\n if (!this.params.url) {\n return reject(new DownloadException('url param not defined!', this.request));\n }\n\n this.request.onload = () => {\n if (parseInt(this.request.status, 10) !== 200) {\n return reject(new DownloadException(`status code [${this.request.status}]`, this.request));\n }\n this.startDownload();\n return resolve(this);\n };\n\n this.request.ontimeout = () => {\n reject(new DownloadException('request timeout', this.request));\n };\n\n this.request.onerror = () => {\n if (this.params.nativeFallbackOnError) {\n fallback();\n resolve(this);\n } else {\n reject(new DownloadException('network error', this.request));\n }\n };\n\n this.request.send(this.params.body);\n\n return this;\n }\n\n isMobile () {\n return !this.params.forceDesktopMode &&\n /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n }\n\n createRequest () {\n let request = new XMLHttpRequest();\n\n request.open(this.params.method, this.params.url, true);\n if (this.params.contentType !== false) {\n request.setRequestHeader('Content-type', this.params.contentType);\n }\n this.params.headers.forEach(header => {\n request.setRequestHeader(header.name, header.value);\n });\n request.responseType = 'arraybuffer';\n if (this.params.process && typeof this.params.process === 'function') {\n request.addEventListener('progress', this.params.process);\n }\n if (this.params.onloadstart && typeof this.params.onloadstart === 'function') {\n request.onloadstart = this.params.onloadstart;\n }\n request.timeout = this.params.timeout;\n request.withCredentials = !!this.params.withCredentials || !!this.params.includeCredentials;\n return request;\n }\n\n getFileName () {\n // Forcing file name\n if (typeof this.params.filename === 'string') {\n return this.params.filename;\n }\n // Trying to get file name from response header\n let content = this.request.getResponseHeader('Content-Disposition');\n let contentParts = [];\n\n if (content) {\n contentParts = content.replace(/[\"']/g, '').match(/filename\\*?=([^;]+)/);\n }\n\n const extractedName = contentParts && contentParts.length >= 1 ?\n contentParts[1] :\n this.params.url.split('/').pop().split('?')[0];\n\n return this.params.nameCallback(extractedName);\n }\n\n createLink () {\n let link = document.createElement('a');\n\n link.style.display = 'none';\n return link;\n }\n\n clickLink () {\n let event;\n\n try {\n event = new MouseEvent('click');\n } catch (e) {\n event = document.createEvent('MouseEvent');\n event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n }\n\n this.link.dispatchEvent(event);\n }\n\n getFile (response, fileName) {\n let file = null;\n let options = { type: 'application/octet-stream' };\n\n try {\n file = new File([response], fileName, options);\n } catch (e) {\n file = new Blob([response], options);\n file.name = fileName;\n file.lastModifiedDate = new Date();\n }\n return file;\n }\n\n startDownload () {\n let fileName = this.getFileName();\n let file = this.getFile(this.request.response, fileName);\n\n // native IE\n if ('msSaveOrOpenBlob' in window.navigator) {\n return window.navigator.msSaveOrOpenBlob(file, fileName);\n }\n\n let objectUrl = window.URL.createObjectURL(file);\n\n this.link.href = objectUrl;\n this.link.download = fileName;\n this.clickLink();\n\n setTimeout(() => {\n (window.URL || window.webkitURL || window).revokeObjectURL(objectUrl);\n }, 1000 * 40);\n\n return this;\n }\n}\n\nexport default JsFileDownloader;\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://jsFileDownloader/webpack/universalModuleDefinition","webpack://jsFileDownloader/webpack/bootstrap","webpack://jsFileDownloader/./src/exception.js","webpack://jsFileDownloader/./src/index.js"],"names":["DownloadException","message","request","name","Error","downloadException","DEFAULT_PARAMS","timeout","headers","forceDesktopMode","autoStart","withCredentials","method","nameCallback","contentType","body","nativeFallbackOnError","JsFileDownloader","customParams","params","Object","assign","link","createLink","downloadFile","Promise","resolve","reject","initDownload","fallback","target","href","url","clickLink","isMobile","createRequest","onload","parseInt","status","startDownload","ontimeout","onerror","send","test","navigator","userAgent","XMLHttpRequest","open","setRequestHeader","forEach","header","value","responseType","process","addEventListener","onloadstart","includeCredentials","filename","content","getResponseHeader","contentParts","replace","match","extractedName","length","split","pop","document","createElement","style","display","event","MouseEvent","e","createEvent","initMouseEvent","window","dispatchEvent","response","fileName","file","options","type","File","Blob","lastModifiedDate","Date","getFileName","getFile","msSaveOrOpenBlob","objectUrl","URL","createObjectURL","download","setTimeout","webkitURL","revokeObjectURL"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClFO,IAAMA,iBAAb;AAAA;;AAAA;;AACE,6BAAaC,OAAb,EAAsBC,OAAtB,EAA+B;AAAA;;AAAA;;AAC7B,0DAA2BD,OAA3B;AACA,UAAKC,OAAL,GAAeA,OAAf;AACA,UAAKC,IAAL,GAAY,mBAAZ;AAH6B;AAI9B;;AALH;AAAA,iCAAuCC,KAAvC;AAMC;AAED;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B,SAArB,IAAkCnB,MAAnC,EAA2CoB,eAA3C,CAA2DN,SAA3D;AACD,OAFS,EAEP,OAAO,EAFA,CAAV;AAIA,aAAO,IAAP;AACD;;;;;;AAGYzE,+EAAf,E","file":"js-file-downloader.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"jsFileDownloader\"] = factory();\n\telse\n\t\troot[\"jsFileDownloader\"] = factory();\n})(this, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/index.js\");\n","export class DownloadException extends Error {\n constructor (message, request) {\n super(`Downloader error: ${message}`);\n this.request = request;\n this.name = 'DownloadException';\n }\n};\n\n/**\n * @deprecated use DownloadException instead, it will be removed in next releases!\n */\nexport const downloadException = DownloadException;\n","/*!\n * JS File Downloader v ##package_version##\n * https://github.com/AleeeKoi/js-file-downloader\n *\n * Copyright Alessandro Pellizzari\n * Released under the MIT license\n * http://opensource.org/licenses/MIT\n */\n\n'use strict';\n\nimport { DownloadException } from './exception';\n\nconst DEFAULT_PARAMS = {\n timeout: 40000,\n headers: [],\n forceDesktopMode: false,\n autoStart: true,\n withCredentials: false,\n method: 'GET',\n nameCallback: name => name,\n contentType: 'application/x-www-form-urlencoded',\n body: null,\n nativeFallbackOnError: false\n};\n\nclass JsFileDownloader {\n\n /**\n * Create a new JsFileDownloader instance\n * You need to define a {String} \"url\" params and other\n * @param {Object} customParams\n */\n constructor (customParams = {}) {\n this.params = Object.assign({}, DEFAULT_PARAMS, customParams);\n this.link = this.createLink();\n this.request = null;\n\n if (this.params.autoStart) return this.downloadFile();\n\n return this;\n }\n\n start () {\n return this.downloadFile();\n }\n\n downloadFile () {\n return new Promise((resolve, reject) => {\n this.initDownload(resolve, reject);\n });\n }\n\n initDownload (resolve, reject) {\n\n const fallback = () => {\n this.link.target = '_blank';\n this.link.href = this.params.url;\n this.clickLink();\n };\n\n // fallback for old browsers\n if (!('download' in this.link) || this.isMobile()) {\n fallback();\n return resolve();\n }\n\n this.request = this.createRequest();\n\n if (!this.params.url) {\n return reject(new DownloadException('url param not defined!', this.request));\n }\n\n this.request.onload = () => {\n if (parseInt(this.request.status, 10) !== 200) {\n return reject(new DownloadException(`status code [${this.request.status}]`, this.request));\n }\n this.startDownload();\n return resolve(this);\n };\n\n this.request.ontimeout = () => {\n reject(new DownloadException('request timeout', this.request));\n };\n\n this.request.onerror = () => {\n if (this.params.nativeFallbackOnError) {\n fallback();\n resolve(this);\n } else {\n reject(new DownloadException('network error', this.request));\n }\n };\n\n this.request.send(this.params.body);\n\n return this;\n }\n\n isMobile () {\n return !this.params.forceDesktopMode &&\n /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n }\n\n createRequest () {\n let request = new XMLHttpRequest();\n\n request.open(this.params.method, this.params.url, true);\n if (this.params.contentType !== false) {\n request.setRequestHeader('Content-type', this.params.contentType);\n }\n this.params.headers.forEach(header => {\n request.setRequestHeader(header.name, header.value);\n });\n request.responseType = 'arraybuffer';\n if (this.params.process && typeof this.params.process === 'function') {\n request.addEventListener('progress', this.params.process);\n }\n if (this.params.onloadstart && typeof this.params.onloadstart === 'function') {\n request.onloadstart = this.params.onloadstart;\n }\n request.timeout = this.params.timeout;\n request.withCredentials = !!this.params.withCredentials || !!this.params.includeCredentials;\n return request;\n }\n\n getFileName () {\n // Forcing file name\n if (typeof this.params.filename === 'string') {\n return this.params.filename;\n }\n // Trying to get file name from response header\n let content = this.request.getResponseHeader('Content-Disposition');\n let contentParts = [];\n\n if (content) {\n contentParts = content.replace(/[\"']/g, '').match(/filename\\*?=([^;]+)/);\n }\n\n const extractedName = contentParts && contentParts.length >= 1 ?\n contentParts[1] :\n this.params.url.split('/').pop().split('?')[0];\n\n return this.params.nameCallback(extractedName);\n }\n\n createLink () {\n let link = document.createElement('a');\n\n link.style.display = 'none';\n return link;\n }\n\n clickLink () {\n let event;\n\n try {\n event = new MouseEvent('click');\n } catch (e) {\n event = document.createEvent('MouseEvent');\n event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n }\n\n this.link.dispatchEvent(event);\n }\n\n getFile (response, fileName) {\n let file = null;\n let options = { type: 'application/octet-stream' };\n\n try {\n file = new File([response], fileName, options);\n } catch (e) {\n file = new Blob([response], options);\n file.name = fileName;\n file.lastModifiedDate = new Date();\n }\n return file;\n }\n\n startDownload () {\n let fileName = this.getFileName();\n let file = this.getFile(this.request.response, fileName);\n\n // native IE\n if ('msSaveOrOpenBlob' in window.navigator) {\n return window.navigator.msSaveOrOpenBlob(file, fileName);\n }\n\n let objectUrl = window.URL.createObjectURL(file);\n\n this.link.href = objectUrl;\n this.link.download = fileName;\n this.clickLink();\n\n setTimeout(() => {\n (window.URL || window.webkitURL || window).revokeObjectURL(objectUrl);\n }, 1000 * 40);\n\n return this;\n }\n}\n\nexport default JsFileDownloader;\n"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/js-file-downloader.min.js b/dist/js-file-downloader.min.js index 904364d..ab0867c 100644 --- a/dist/js-file-downloader.min.js +++ b/dist/js-file-downloader.min.js @@ -1,11 +1,11 @@ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.jsFileDownloader=t():e.jsFileDownloader=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return a(e,arguments,c(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,e)})(e)}function a(e,t,n){return(a=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&s(o,n.prototype),o}).apply(null,arguments)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}n.r(t);var l=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}(i,e);var t,n,r=(t=i,n=u(),function(){var e,r=c(t);if(n){var i=c(this).constructor;e=Reflect.construct(r,arguments,i)}else e=r.apply(this,arguments);return o(this,e)});function i(e,t){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,i),(n=r.call(this,"Downloader error: ".concat(e))).request=t,n.name="DownloadException",n}return i}(i(Error)); /*! - * JS File Downloader v 1.1.22 + * JS File Downloader v 1.1.23 * https://github.com/AleeeKoi/js-file-downloader * * Copyright Alessandro Pellizzari * Released under the MIT license * http://opensource.org/licenses/MIT */ -function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{};return f(this,e),this.params=Object.assign({},d,t),this.link=this.createLink(),this.request=null,this.params.autoStart?this.downloadFile():this}var t,n,r;return t=e,(n=[{key:"start",value:function(){return this.downloadFile()}},{key:"downloadFile",value:function(){var e=this;return new Promise((function(t,n){e.initDonwload(t,n)}))}},{key:"initDonwload",value:function(e,t){var n=this,r=function(){n.link.target="_blank",n.link.href=n.params.url,n.clickLink()};return!("download"in this.link)||this.isMobile()?(r(),e()):(this.request=this.createRequest(),this.params.url?(this.request.onload=function(){return 200!==parseInt(n.request.status,10)?t(new l("status code [".concat(n.request.status,"]"),n.request)):(n.startDownload(),e(n))},this.request.ontimeout=function(){t(new l("request timeout",n.request))},this.request.onerror=function(){n.params.nativeFallbackOnError?(r(),e(n)):t(new l("network error",n.request))},this.request.send(this.params.body),this):t(new l("url param not defined!",this.request)))}},{key:"isMobile",value:function(){return!this.params.forceDesktopMode&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}},{key:"createRequest",value:function(){var e=new XMLHttpRequest;return e.open(this.params.method,this.params.url,!0),!1!==this.params.contentType&&e.setRequestHeader("Content-type",this.params.contentType),this.params.headers.forEach((function(t){e.setRequestHeader(t.name,t.value)})),e.responseType="arraybuffer",this.params.process&&"function"==typeof this.params.process&&e.addEventListener("progress",this.params.process),this.params.onloadstart&&"function"==typeof this.params.onloadstart&&(e.onloadstart=this.params.onloadstart),e.timeout=this.params.timeout,e.withCredentials=!!this.params.withCredentials||!!this.params.includeCredentials,e}},{key:"getFileName",value:function(){if("string"==typeof this.params.filename)return this.params.filename;var e=this.request.getResponseHeader("Content-Disposition"),t=[];e&&(t=e.replace(/["']/g,"").match(/filename\*?=([^;]+)/));var n=t&&t.length>=1?t[1]:this.params.url.split("/").pop().split("?")[0];return this.params.nameCallback(n)}},{key:"createLink",value:function(){var e=document.createElement("a");return e.style.display="none",e}},{key:"clickLink",value:function(){var e;try{e=new MouseEvent("click")}catch(t){(e=document.createEvent("MouseEvent")).initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)}this.link.dispatchEvent(e)}},{key:"getFile",value:function(e,t){var n=null,r={type:"application/octet-stream"};try{n=new File([e],t,r)}catch(o){(n=new Blob([e],r)).name=t,n.lastModifiedDate=new Date}return n}},{key:"startDownload",value:function(){var e=this.getFileName(),t=this.getFile(this.request.response,e);if("msSaveOrOpenBlob"in window.navigator)return window.navigator.msSaveOrOpenBlob(t,e);var n=window.URL.createObjectURL(t);return this.link.href=n,this.link.download=e,this.clickLink(),setTimeout((function(){(window.URL||window.webkitURL||window).revokeObjectURL(n)}),4e4),this}}])&&p(t.prototype,n),r&&p(t,r),e}();t.default=h}]).default})); +function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{};return f(this,e),this.params=Object.assign({},d,t),this.link=this.createLink(),this.request=null,this.params.autoStart?this.downloadFile():this}var t,n,r;return t=e,(n=[{key:"start",value:function(){return this.downloadFile()}},{key:"downloadFile",value:function(){var e=this;return new Promise((function(t,n){e.initDownload(t,n)}))}},{key:"initDownload",value:function(e,t){var n=this,r=function(){n.link.target="_blank",n.link.href=n.params.url,n.clickLink()};return!("download"in this.link)||this.isMobile()?(r(),e()):(this.request=this.createRequest(),this.params.url?(this.request.onload=function(){return 200!==parseInt(n.request.status,10)?t(new l("status code [".concat(n.request.status,"]"),n.request)):(n.startDownload(),e(n))},this.request.ontimeout=function(){t(new l("request timeout",n.request))},this.request.onerror=function(){n.params.nativeFallbackOnError?(r(),e(n)):t(new l("network error",n.request))},this.request.send(this.params.body),this):t(new l("url param not defined!",this.request)))}},{key:"isMobile",value:function(){return!this.params.forceDesktopMode&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}},{key:"createRequest",value:function(){var e=new XMLHttpRequest;return e.open(this.params.method,this.params.url,!0),!1!==this.params.contentType&&e.setRequestHeader("Content-type",this.params.contentType),this.params.headers.forEach((function(t){e.setRequestHeader(t.name,t.value)})),e.responseType="arraybuffer",this.params.process&&"function"==typeof this.params.process&&e.addEventListener("progress",this.params.process),this.params.onloadstart&&"function"==typeof this.params.onloadstart&&(e.onloadstart=this.params.onloadstart),e.timeout=this.params.timeout,e.withCredentials=!!this.params.withCredentials||!!this.params.includeCredentials,e}},{key:"getFileName",value:function(){if("string"==typeof this.params.filename)return this.params.filename;var e=this.request.getResponseHeader("Content-Disposition"),t=[];e&&(t=e.replace(/["']/g,"").match(/filename\*?=([^;]+)/));var n=t&&t.length>=1?t[1]:this.params.url.split("/").pop().split("?")[0];return this.params.nameCallback(n)}},{key:"createLink",value:function(){var e=document.createElement("a");return e.style.display="none",e}},{key:"clickLink",value:function(){var e;try{e=new MouseEvent("click")}catch(t){(e=document.createEvent("MouseEvent")).initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)}this.link.dispatchEvent(e)}},{key:"getFile",value:function(e,t){var n=null,r={type:"application/octet-stream"};try{n=new File([e],t,r)}catch(o){(n=new Blob([e],r)).name=t,n.lastModifiedDate=new Date}return n}},{key:"startDownload",value:function(){var e=this.getFileName(),t=this.getFile(this.request.response,e);if("msSaveOrOpenBlob"in window.navigator)return window.navigator.msSaveOrOpenBlob(t,e);var n=window.URL.createObjectURL(t);return this.link.href=n,this.link.download=e,this.clickLink(),setTimeout((function(){(window.URL||window.webkitURL||window).revokeObjectURL(n)}),4e4),this}}])&&p(t.prototype,n),r&&p(t,r),e}();t.default=h}]).default})); //# sourceMappingURL=js-file-downloader.min.js.map \ No newline at end of file diff --git a/dist/js-file-downloader.min.js.map b/dist/js-file-downloader.min.js.map index 2a27a02..7130b85 100644 --- a/dist/js-file-downloader.min.js.map +++ b/dist/js-file-downloader.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://jsFileDownloader/webpack/universalModuleDefinition","webpack://jsFileDownloader/webpack/bootstrap","webpack://jsFileDownloader/./src/exception.js","webpack://jsFileDownloader/./src/index.js"],"names":["root","factory","exports","module","define","amd","this","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","DownloadException","message","request","Error","DEFAULT_PARAMS","timeout","headers","forceDesktopMode","autoStart","withCredentials","method","nameCallback","contentType","body","nativeFallbackOnError","JsFileDownloader","customParams","params","assign","link","createLink","downloadFile","Promise","resolve","reject","initDonwload","fallback","target","href","url","clickLink","isMobile","createRequest","onload","parseInt","status","startDownload","ontimeout","onerror","send","test","navigator","userAgent","XMLHttpRequest","open","setRequestHeader","forEach","header","responseType","process","addEventListener","onloadstart","includeCredentials","filename","content","getResponseHeader","contentParts","replace","match","extractedName","length","split","pop","document","createElement","style","display","event","MouseEvent","e","createEvent","initMouseEvent","window","dispatchEvent","response","fileName","file","options","type","File","Blob","lastModifiedDate","Date","getFileName","getFile","msSaveOrOpenBlob","objectUrl","URL","createObjectURL","download","setTimeout","webkitURL","revokeObjectURL"],"mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAA0B,iBAAID,IAE9BD,EAAuB,iBAAIC,IAR7B,CASGK,MAAM,WACT,O,YCTE,IAAIC,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUP,QAGnC,IAAIC,EAASI,EAAiBE,GAAY,CACzCC,EAAGD,EACHE,GAAG,EACHT,QAAS,IAUV,OANAU,EAAQH,GAAUI,KAAKV,EAAOD,QAASC,EAAQA,EAAOD,QAASM,GAG/DL,EAAOQ,GAAI,EAGJR,EAAOD,QA0Df,OArDAM,EAAoBM,EAAIF,EAGxBJ,EAAoBO,EAAIR,EAGxBC,EAAoBQ,EAAI,SAASd,EAASe,EAAMC,GAC3CV,EAAoBW,EAAEjB,EAASe,IAClCG,OAAOC,eAAenB,EAASe,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEV,EAAoBgB,EAAI,SAAStB,GACX,oBAAXuB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAenB,EAASuB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAenB,EAAS,aAAc,CAAEyB,OAAO,KAQvDnB,EAAoBoB,EAAI,SA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,KAAK,CAACL,GAAWC,EAAUE,GACtC,MAAOR,IACPO,EAAO,IAAII,KAAK,CAACN,GAAWG,IACvBtG,KAAOoG,EACZC,EAAKK,iBAAmB,IAAIC,KAE9B,OAAON,I,2BAGT,WACE,IAAID,EAAW/G,KAAKuH,cAChBP,EAAOhH,KAAKwH,QAAQxH,KAAKsC,QAAQwE,SAAUC,GAG/C,GAAI,qBAAsBH,OAAO/B,UAC/B,OAAO+B,OAAO/B,UAAU4C,iBAAiBT,EAAMD,GAGjD,IAAIW,EAAYd,OAAOe,IAAIC,gBAAgBZ,GAU3C,OARAhH,KAAKuD,KAAKS,KAAO0D,EACjB1H,KAAKuD,KAAKsE,SAAWd,EACrB/G,KAAKkE,YAEL4D,YAAW,YACRlB,OAAOe,KAAOf,OAAOmB,WAAanB,QAAQoB,gBAAgBN,KAC1D,KAEI1H,U,gCAIImD,e","file":"js-file-downloader.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"jsFileDownloader\"] = factory();\n\telse\n\t\troot[\"jsFileDownloader\"] = factory();\n})(this, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","export class DownloadException extends Error {\n constructor (message, request) {\n super(`Downloader error: ${message}`);\n this.request = request;\n this.name = 'DownloadException';\n }\n};\n\n/**\n * @deprecated use DownloadException instead, it will be removed in next releases!\n */\nexport const downloadException = DownloadException;\n","/*!\n * JS File Downloader v ##package_version##\n * https://github.com/AleeeKoi/js-file-downloader\n *\n * Copyright Alessandro Pellizzari\n * Released under the MIT license\n * http://opensource.org/licenses/MIT\n */\n\n'use strict';\n\nimport { DownloadException } from './exception';\n\nconst DEFAULT_PARAMS = {\n timeout: 40000,\n headers: [],\n forceDesktopMode: false,\n autoStart: true,\n withCredentials: false,\n method: 'GET',\n nameCallback: name => name,\n contentType: 'application/x-www-form-urlencoded',\n body: null,\n nativeFallbackOnError: false\n};\n\nclass JsFileDownloader {\n\n /**\n * Create a new JsFileDownloader instance\n * You need to define a {String} \"url\" params and other\n * @param {Object} customParams\n */\n constructor (customParams = {}) {\n this.params = Object.assign({}, DEFAULT_PARAMS, customParams);\n this.link = this.createLink();\n this.request = null;\n\n if (this.params.autoStart) return this.downloadFile();\n\n return this;\n }\n\n start () {\n return this.downloadFile();\n }\n\n downloadFile () {\n return new Promise((resolve, reject) => {\n this.initDonwload(resolve, reject);\n });\n }\n\n initDonwload (resolve, reject) {\n\n const fallback = () => {\n this.link.target = '_blank';\n this.link.href = this.params.url;\n this.clickLink();\n };\n\n // fallback for old browsers\n if (!('download' in this.link) || this.isMobile()) {\n fallback();\n return resolve();\n }\n\n this.request = this.createRequest();\n\n if (!this.params.url) {\n return reject(new DownloadException('url param not defined!', this.request));\n }\n\n this.request.onload = () => {\n if (parseInt(this.request.status, 10) !== 200) {\n return reject(new DownloadException(`status code [${this.request.status}]`, this.request));\n }\n this.startDownload();\n return resolve(this);\n };\n\n this.request.ontimeout = () => {\n reject(new DownloadException('request timeout', this.request));\n };\n\n this.request.onerror = () => {\n if (this.params.nativeFallbackOnError) {\n fallback();\n resolve(this);\n } else {\n reject(new DownloadException('network error', this.request));\n }\n };\n\n this.request.send(this.params.body);\n\n return this;\n }\n\n isMobile () {\n return !this.params.forceDesktopMode &&\n /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n }\n\n createRequest () {\n let request = new XMLHttpRequest();\n\n request.open(this.params.method, this.params.url, true);\n if (this.params.contentType !== false) {\n request.setRequestHeader('Content-type', this.params.contentType);\n }\n this.params.headers.forEach(header => {\n request.setRequestHeader(header.name, header.value);\n });\n request.responseType = 'arraybuffer';\n if (this.params.process && typeof this.params.process === 'function') {\n request.addEventListener('progress', this.params.process);\n }\n if (this.params.onloadstart && typeof this.params.onloadstart === 'function') {\n request.onloadstart = this.params.onloadstart;\n }\n request.timeout = this.params.timeout;\n request.withCredentials = !!this.params.withCredentials || !!this.params.includeCredentials;\n return request;\n }\n\n getFileName () {\n // Forcing file name\n if (typeof this.params.filename === 'string') {\n return this.params.filename;\n }\n // Trying to get file name from response header\n let content = this.request.getResponseHeader('Content-Disposition');\n let contentParts = [];\n\n if (content) {\n contentParts = content.replace(/[\"']/g, '').match(/filename\\*?=([^;]+)/);\n }\n\n const extractedName = contentParts && contentParts.length >= 1 ?\n contentParts[1] :\n this.params.url.split('/').pop().split('?')[0];\n\n return this.params.nameCallback(extractedName);\n }\n\n createLink () {\n let link = document.createElement('a');\n\n link.style.display = 'none';\n return link;\n }\n\n clickLink () {\n let event;\n\n try {\n event = new MouseEvent('click');\n } catch (e) {\n event = document.createEvent('MouseEvent');\n event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n }\n\n this.link.dispatchEvent(event);\n }\n\n getFile (response, fileName) {\n let file = null;\n let options = { type: 'application/octet-stream' };\n\n try {\n file = new File([response], fileName, options);\n } catch (e) {\n file = new Blob([response], options);\n file.name = fileName;\n file.lastModifiedDate = new Date();\n }\n return file;\n }\n\n startDownload () {\n let fileName = this.getFileName();\n let file = this.getFile(this.request.response, fileName);\n\n // native IE\n if ('msSaveOrOpenBlob' in window.navigator) {\n return window.navigator.msSaveOrOpenBlob(file, fileName);\n }\n\n let objectUrl = window.URL.createObjectURL(file);\n\n this.link.href = objectUrl;\n this.link.download = fileName;\n this.clickLink();\n\n setTimeout(() => {\n (window.URL || window.webkitURL || window).revokeObjectURL(objectUrl);\n }, 1000 * 40);\n\n return this;\n }\n}\n\nexport default JsFileDownloader;\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://jsFileDownloader/webpack/universalModuleDefinition","webpack://jsFileDownloader/webpack/bootstrap","webpack://jsFileDownloader/./src/exception.js","webpack://jsFileDownloader/./src/index.js"],"names":["root","factory","exports","module","define","amd","this","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","DownloadException","message","request","Error","DEFAULT_PARAMS","timeout","headers","forceDesktopMode","autoStart","withCredentials","method","nameCallback","contentType","body","nativeFallbackOnError","JsFileDownloader","customParams","params","assign","link","createLink","downloadFile","Promise","resolve","reject","initDownload","fallback","target","href","url","clickLink","isMobile","createRequest","onload","parseInt","status","startDownload","ontimeout","onerror","send","test","navigator","userAgent","XMLHttpRequest","open","setRequestHeader","forEach","header","responseType","process","addEventListener","onloadstart","includeCredentials","filename","content","getResponseHeader","contentParts","replace","match","extractedName","length","split","pop","document","createElement","style","display","event","MouseEvent","e","createEvent","initMouseEvent","window","dispatchEvent","response","fileName","file","options","type","File","Blob","lastModifiedDate","Date","getFileName","getFile","msSaveOrOpenBlob","objectUrl","URL","createObjectURL","download","setTimeout","webkitURL","revokeObjectURL"],"mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAA0B,iBAAID,IAE9BD,EAAuB,iBAAIC,IAR7B,CASGK,MAAM,WACT,O,YCTE,IAAIC,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiB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,QAAS,IAAIC,MAAM,wBAGpD,IAAMC,EAAgBH,GAAgBA,EAAaI,QAAU,EAC3DJ,EAAa,GACb5F,KAAKqD,OAAOY,IAAIgC,MAAM,KAAKC,MAAMD,MAAM,KAAK,GAE9C,OAAOjG,KAAKqD,OAAON,aAAagD,K,wBAGlC,WACE,IAAIxC,EAAO4C,SAASC,cAAc,KAGlC,OADA7C,EAAK8C,MAAMC,QAAU,OACd/C,I,uBAGT,WACE,IAAIgD,EAEJ,IACEA,EAAQ,IAAIC,WAAW,SACvB,MAAOC,IACPF,EAAQJ,SAASO,YAAY,eACvBC,eAAe,SAAS,GAAM,EAAMC,OAAQ,EAAG,EAAG,EAAG,EAAG,GAAG,GAAO,GAAO,GAAO,EAAO,EAAG,MAGlG5G,KAAKuD,KAAKsD,cAAcN,K,qBAG1B,SAASO,EAAUC,GACjB,IAAIC,EAAO,KACPC,EAAU,CAAEC,KAAM,4BAEtB,IACEF,EAAO,IAAIG,KAAK,CAACL,GAAWC,EAAUE,GACtC,MAAOR,IACPO,EAAO,IAAII,KAAK,CAACN,GAAWG,IACvBtG,KAAOoG,EACZC,EAAKK,iBAAmB,IAAIC,KAE9B,OAAON,I,2BAGT,WACE,IAAID,EAAW/G,KAAKuH,cAChBP,EAAOhH,KAAKwH,QAAQxH,KAAKsC,QAAQwE,SAAUC,GAG/C,GAAI,qBAAsBH,OAAO/B,UAC/B,OAAO+B,OAAO/B,UAAU4C,iBAAiBT,EAAMD,GAGjD,IAAIW,EAAYd,OAAOe,IAAIC,gBAAgBZ,GAU3C,OARAhH,KAAKuD,KAAKS,KAAO0D,EACjB1H,KAAKuD,KAAKsE,SAAWd,EACrB/G,KAAKkE,YAEL4D,YAAW,YACRlB,OAAOe,KAAOf,OAAOmB,WAAanB,QAAQoB,gBAAgBN,KAC1D,KAEI1H,U,gCAIImD,e","file":"js-file-downloader.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"jsFileDownloader\"] = factory();\n\telse\n\t\troot[\"jsFileDownloader\"] = factory();\n})(this, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","export class DownloadException extends Error {\n constructor (message, request) {\n super(`Downloader error: ${message}`);\n this.request = request;\n this.name = 'DownloadException';\n }\n};\n\n/**\n * @deprecated use DownloadException instead, it will be removed in next releases!\n */\nexport const downloadException = DownloadException;\n","/*!\n * JS File Downloader v ##package_version##\n * https://github.com/AleeeKoi/js-file-downloader\n *\n * Copyright Alessandro Pellizzari\n * Released under the MIT license\n * http://opensource.org/licenses/MIT\n */\n\n'use strict';\n\nimport { DownloadException } from './exception';\n\nconst DEFAULT_PARAMS = {\n timeout: 40000,\n headers: [],\n forceDesktopMode: false,\n autoStart: true,\n withCredentials: false,\n method: 'GET',\n nameCallback: name => name,\n contentType: 'application/x-www-form-urlencoded',\n body: null,\n nativeFallbackOnError: false\n};\n\nclass JsFileDownloader {\n\n /**\n * Create a new JsFileDownloader instance\n * You need to define a {String} \"url\" params and other\n * @param {Object} customParams\n */\n constructor (customParams = {}) {\n this.params = Object.assign({}, DEFAULT_PARAMS, customParams);\n this.link = this.createLink();\n this.request = null;\n\n if (this.params.autoStart) return this.downloadFile();\n\n return this;\n }\n\n start () {\n return this.downloadFile();\n }\n\n downloadFile () {\n return new Promise((resolve, reject) => {\n this.initDownload(resolve, reject);\n });\n }\n\n initDownload (resolve, reject) {\n\n const fallback = () => {\n this.link.target = '_blank';\n this.link.href = this.params.url;\n this.clickLink();\n };\n\n // fallback for old browsers\n if (!('download' in this.link) || this.isMobile()) {\n fallback();\n return resolve();\n }\n\n this.request = this.createRequest();\n\n if (!this.params.url) {\n return reject(new DownloadException('url param not defined!', this.request));\n }\n\n this.request.onload = () => {\n if (parseInt(this.request.status, 10) !== 200) {\n return reject(new DownloadException(`status code [${this.request.status}]`, this.request));\n }\n this.startDownload();\n return resolve(this);\n };\n\n this.request.ontimeout = () => {\n reject(new DownloadException('request timeout', this.request));\n };\n\n this.request.onerror = () => {\n if (this.params.nativeFallbackOnError) {\n fallback();\n resolve(this);\n } else {\n reject(new DownloadException('network error', this.request));\n }\n };\n\n this.request.send(this.params.body);\n\n return this;\n }\n\n isMobile () {\n return !this.params.forceDesktopMode &&\n /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n }\n\n createRequest () {\n let request = new XMLHttpRequest();\n\n request.open(this.params.method, this.params.url, true);\n if (this.params.contentType !== false) {\n request.setRequestHeader('Content-type', this.params.contentType);\n }\n this.params.headers.forEach(header => {\n request.setRequestHeader(header.name, header.value);\n });\n request.responseType = 'arraybuffer';\n if (this.params.process && typeof this.params.process === 'function') {\n request.addEventListener('progress', this.params.process);\n }\n if (this.params.onloadstart && typeof this.params.onloadstart === 'function') {\n request.onloadstart = this.params.onloadstart;\n }\n request.timeout = this.params.timeout;\n request.withCredentials = !!this.params.withCredentials || !!this.params.includeCredentials;\n return request;\n }\n\n getFileName () {\n // Forcing file name\n if (typeof this.params.filename === 'string') {\n return this.params.filename;\n }\n // Trying to get file name from response header\n let content = this.request.getResponseHeader('Content-Disposition');\n let contentParts = [];\n\n if (content) {\n contentParts = content.replace(/[\"']/g, '').match(/filename\\*?=([^;]+)/);\n }\n\n const extractedName = contentParts && contentParts.length >= 1 ?\n contentParts[1] :\n this.params.url.split('/').pop().split('?')[0];\n\n return this.params.nameCallback(extractedName);\n }\n\n createLink () {\n let link = document.createElement('a');\n\n link.style.display = 'none';\n return link;\n }\n\n clickLink () {\n let event;\n\n try {\n event = new MouseEvent('click');\n } catch (e) {\n event = document.createEvent('MouseEvent');\n event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n }\n\n this.link.dispatchEvent(event);\n }\n\n getFile (response, fileName) {\n let file = null;\n let options = { type: 'application/octet-stream' };\n\n try {\n file = new File([response], fileName, options);\n } catch (e) {\n file = new Blob([response], options);\n file.name = fileName;\n file.lastModifiedDate = new Date();\n }\n return file;\n }\n\n startDownload () {\n let fileName = this.getFileName();\n let file = this.getFile(this.request.response, fileName);\n\n // native IE\n if ('msSaveOrOpenBlob' in window.navigator) {\n return window.navigator.msSaveOrOpenBlob(file, fileName);\n }\n\n let objectUrl = window.URL.createObjectURL(file);\n\n this.link.href = objectUrl;\n this.link.download = fileName;\n this.clickLink();\n\n setTimeout(() => {\n (window.URL || window.webkitURL || window).revokeObjectURL(objectUrl);\n }, 1000 * 40);\n\n return this;\n }\n}\n\nexport default JsFileDownloader;\n"],"sourceRoot":""} \ No newline at end of file diff --git a/package.json b/package.json index 9cf1280..747c9db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-file-downloader", - "version": "1.1.22", + "version": "1.1.23", "description": "Small lib for a cool download experience", "main": "dist/js-file-downloader.js", "types": "index.d.ts",