diff --git a/amd/build/chunkupload.min.js b/amd/build/chunkupload.min.js index 3eebdf6..e1570aa 100644 --- a/amd/build/chunkupload.min.js +++ b/amd/build/chunkupload.min.js @@ -1,2 +1,2 @@ -define ("local_chunkupload/chunkupload",["exports","jquery","core/str","core/notification"],function(a,b,c,d){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=f;b=e(b);d=e(d);function e(a){return a&&a.__esModule?a:{default:a}}function f(a,e,f,g,h,i){var o,p,q,r,s,t,u,v;q=(0,b.default)("#"+a+"_file");v=(0,b.default)("#"+a).val();var w=q.next();r=w.find(".chunkupload-filename");s=w.find(".chunkupload-progress");t=w.find(".chunkupload-icon");u=w.next();o=g;p=h;q.change(function(){l();var a=q.get(0).files[0],b=".";if(-1!==a.name.indexOf(".")){var c=a.name.split(".");b="."+c[c.length-1]}if(!("*"===e||e instanceof Array&&(-1!==e.indexOf(b)||-1!==e.indexOf("*")))){q.val(null);n({key:"invalidfiletype",component:"core_repository",param:b});return}else if(-1!==f&&a.size>f){q.val(null);n({key:"errorpostmaxsize",component:"core_repository"});return}r.text(a.name);j(a)});u.on("click",function(a){l();var c={id:v},d=new XMLHttpRequest;d.open("post",o+"/local/chunkupload/deleteupload_ajax.php?"+b.default.param(c));d.send(null);r.text(i);q.val(null);a.stopPropagation()});function j(a){var c=pf){q.val(null);n({key:"errorpostmaxsize",component:"core_repository"});return}r.text(a.name);j(a)});u.on("click",function(a){l();var c={id:v},d=new XMLHttpRequest;d.open("post",o+"/local/chunkupload/deleteupload_ajax.php?"+b.default.param(c));d.send(null);r.text(i);q.val(null);a.stopPropagation()});function j(a){var c=p.\n\n/**\n * Manage the upload in chunks.\n *\n * @package local_chunkupload\n * @copyright 2020 Justus Dieckmann WWU\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport $ from 'jquery';\nimport {get_strings as getStrings} from 'core/str';\nimport notification from 'core/notification';\n\n/**\n * Init\n * @param {String} elementid string The id of the input element\n * @param {String|String[]} acceptedTypes The accepted Types\n * @param {int} maxBytes The maximal allowed amount of bytes\n * @param {string} wwwroot The wwwroot\n * @param {int} chunksize The chunksize in bytes\n * @param {string} browsetext Text to display when no file is uploaded.\n */\nexport function init(elementid, acceptedTypes, maxBytes, wwwroot, chunksize, browsetext) {\n let wwwRoot,\n chunkSize;\n\n let fileinput, filename, progress, progressicon, deleteicon;\n\n let token;\n\n fileinput = $('#' + elementid + \"_file\");\n token = $('#' + elementid).val();\n let parentelem = fileinput.next();\n filename = parentelem.find('.chunkupload-filename');\n progress = parentelem.find('.chunkupload-progress');\n progressicon = parentelem.find('.chunkupload-icon');\n deleteicon = parentelem.next();\n wwwRoot = wwwroot;\n chunkSize = chunksize;\n fileinput.change(() => {\n reset();\n let file = fileinput.get(0).files[0];\n let fileextension = \".\";\n if (file.name.indexOf(\".\") !== -1) {\n let splits = file.name.split(\".\");\n fileextension = \".\" + splits[splits.length - 1];\n }\n if (!(acceptedTypes === '*' ||\n acceptedTypes instanceof Array && (acceptedTypes.indexOf(fileextension) !== -1 || acceptedTypes.indexOf('*') !== -1))) {\n fileinput.val(null);\n notifyError({key: 'invalidfiletype', component: 'core_repository', param: fileextension});\n return;\n } else if (maxBytes !== -1 && file.size > maxBytes) {\n fileinput.val(null);\n notifyError({key: 'errorpostmaxsize', component: 'core_repository'});\n return;\n }\n filename.text(file.name);\n startUpload(file);\n });\n\n deleteicon.on('click', (event) => {\n reset();\n let params = {\n id: token\n };\n let xhr = new XMLHttpRequest();\n xhr.open('post', wwwRoot + \"/local/chunkupload/deleteupload_ajax.php?\" + $.param(params));\n xhr.send(null);\n filename.text(browsetext);\n fileinput.val(null);\n event.stopPropagation();\n });\n\n /**\n * Start the Upload\n * @param {File} file The File to upload.\n */\n function startUpload(file) {\n let end = chunkSize < file.size ? chunkSize : file.size;\n let params = {\n start: 0,\n end: end,\n length: file.size,\n filename: file.name,\n id: token\n };\n let slice = file.slice(0, end);\n let xhr = new XMLHttpRequest();\n xhr.open('post', wwwRoot + \"/local/chunkupload/startupload_ajax.php?\" + $.param(params));\n xhr.upload.onprogress = (e) => {\n setProgress(e.loaded, file.size);\n };\n xhr.onreadystatechange = () => {\n if (xhr.readyState === 4) {\n if (xhr.status === 200) {\n let response = JSON.parse(xhr.responseText);\n if (response.error !== undefined) {\n notifyError(response.error);\n } else {\n if (end < file.size) {\n proceedUpload(file, chunkSize);\n }\n }\n }\n }\n };\n xhr.setRequestHeader('Content-Type', 'application/octet-stream');\n xhr.send(slice);\n }\n\n /**\n * Proceed the upload\n * @param {File} file\n * @param {int} start from where to proceed the upload.\n */\n function proceedUpload(file, start) {\n let end = start + chunkSize < file.size ? start + chunkSize : file.size;\n let params = {\n start: start,\n end: end,\n id: token\n };\n let slice = file.slice(start, end);\n let xhr = new XMLHttpRequest();\n xhr.open('post', wwwRoot + \"/local/chunkupload/proceedupload_ajax.php?\" + $.param(params));\n xhr.upload.onprogress = (e) => {\n setProgress(e.loaded + start, file.size);\n };\n xhr.onreadystatechange = () => {\n if (xhr.readyState === 4) {\n if (xhr.status === 200) {\n let response = JSON.parse(xhr.responseText);\n if (response.error !== undefined) {\n notifyError(response.error);\n } else {\n if (end < file.size) {\n proceedUpload(file, end);\n }\n }\n }\n }\n };\n xhr.onerror = () => {\n reset();\n // Doesn't make sense to try to fetch strings when having internet problems.\n notification.alert(\"Error\", \"Failure while uploading!\", \"Ok\");\n };\n xhr.setRequestHeader('Content-Type', 'application/octet-stream');\n xhr.send(slice);\n }\n\n /**\n * Resets the Progress and the Filepicker name.\n */\n function reset() {\n setProgress(0, 1);\n filename.text(\"\");\n }\n\n /**\n * Sets the progressbar\n * @param {int} loaded\n * @param {int} total\n */\n function setProgress(loaded, total) {\n if (loaded === total) {\n // Hide progressbar on finish.\n progress.css('width', '0');\n } else {\n progress.css('width', loaded * 100 / total + \"%\");\n }\n progressicon.prop('hidden', loaded !== total);\n deleteicon.prop('hidden', loaded !== total);\n }\n\n /**\n * Notify error\n * @param {object|string} errorstring Either Object as accepted by getString, or a string, to describe the error.\n */\n function notifyError(errorstring) {\n reset();\n if (typeof errorstring === \"string\") {\n getStrings([\n {key: 'error'},\n {key: 'ok'},\n ]).done(function(s) {\n notification.alert(s[0], errorstring, s[1]);\n }\n ).fail(notification.exception);\n } else {\n getStrings([\n {key: 'error'},\n errorstring,\n {key: 'ok'},\n ]).done(function(s) {\n notification.alert(s[0], s[1], s[2]);\n }\n ).fail(notification.exception);\n }\n }\n}"],"file":"chunkupload.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/chunkupload.js"],"names":["init","elementid","acceptedTypes","maxBytes","wwwroot","chunksize","browsetext","wwwRoot","chunkSize","fileinput","filename","progress","progressicon","deleteicon","token","val","parentelem","next","find","change","reset","file","get","files","fileextension","name","indexOf","splits","split","length","toLowerCase","Array","notifyError","key","component","param","size","text","startUpload","on","event","params","id","xhr","XMLHttpRequest","open","$","send","stopPropagation","end","start","slice","upload","onprogress","e","setProgress","loaded","onreadystatechange","readyState","status","response","JSON","parse","responseText","error","proceedUpload","setRequestHeader","onerror","notification","alert","total","css","prop","errorstring","done","s","fail","exception"],"mappings":"qLAsBA,OAEA,O,mDAWO,QAASA,CAAAA,CAAT,CAAcC,CAAd,CAAyBC,CAAzB,CAAwCC,CAAxC,CAAkDC,CAAlD,CAA2DC,CAA3D,CAAsEC,CAAtE,CAAkF,IACjFC,CAAAA,CADiF,CAEjFC,CAFiF,CAIjFC,CAJiF,CAItEC,CAJsE,CAI5DC,CAJ4D,CAIlDC,CAJkD,CAIpCC,CAJoC,CAMjFC,CANiF,CAQrFL,CAAS,CAAG,cAAE,IAAMR,CAAN,CAAkB,OAApB,CAAZ,CACAa,CAAK,CAAG,cAAE,IAAMb,CAAR,EAAmBc,GAAnB,EAAR,CACA,GAAIC,CAAAA,CAAU,CAAGP,CAAS,CAACQ,IAAV,EAAjB,CACAP,CAAQ,CAAGM,CAAU,CAACE,IAAX,CAAgB,uBAAhB,CAAX,CACAP,CAAQ,CAAGK,CAAU,CAACE,IAAX,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AKc,CAAvC,EACAzD,CAAU,CAAC2D,IAAX,CAAgB,QAAhB,CAA0BhB,CAAM,GAAKc,CAArC,CACH,CAMD,QAAStC,CAAAA,CAAT,CAAqByC,CAArB,CAAkC,CAC9BrD,CAAK,GACL,GAA2B,QAAvB,QAAOqD,CAAAA,CAAX,CAAqC,CACjC,kBAAW,CACP,CAACxC,GAAG,CAAE,OAAN,CADO,CAEP,CAACA,GAAG,CAAE,IAAN,CAFO,CAAX,EAGGyC,IAHH,CAGQ,SAASC,CAAT,CAAY,CACZP,UAAaC,KAAb,CAAmBM,CAAC,CAAC,CAAD,CAApB,CAAyBF,CAAzB,CAAsCE,CAAC,CAAC,CAAD,CAAvC,CACH,CALL,EAMEC,IANF,CAMOR,UAAaS,SANpB,CAOH,CARD,IAQO,CACH,kBAAW,CACP,CAAC5C,GAAG,CAAE,OAAN,CADO,CAEPwC,CAFO,CAGP,CAACxC,GAAG,CAAE,IAAN,CAHO,CAAX,EAIGyC,IAJH,CAIQ,SAASC,CAAT,CAAY,CACZP,UAAaC,KAAb,CAAmBM,CAAC,CAAC,CAAD,CAApB,CAAyBA,CAAC,CAAC,CAAD,CAA1B,CAA+BA,CAAC,CAAC,CAAD,CAAhC,CACH,CANL,EAOEC,IAPF,CAOOR,UAAaS,SAPpB,CAQH,CACJ,CACJ,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Manage the upload in chunks.\n *\n * @module local_chunkupload\n * @copyright 2020 Justus Dieckmann WWU\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport $ from 'jquery';\nimport {get_strings as getStrings} from 'core/str';\nimport notification from 'core/notification';\n\n/**\n * Init\n * @param {String} elementid string The id of the input element\n * @param {String|String[]} acceptedTypes The accepted Types\n * @param {int} maxBytes The maximal allowed amount of bytes\n * @param {string} wwwroot The wwwroot\n * @param {int} chunksize The chunksize in bytes\n * @param {string} browsetext Text to display when no file is uploaded.\n */\nexport function init(elementid, acceptedTypes, maxBytes, wwwroot, chunksize, browsetext) {\n let wwwRoot,\n chunkSize;\n\n let fileinput, filename, progress, progressicon, deleteicon;\n\n let token;\n\n fileinput = $('#' + elementid + \"_file\");\n token = $('#' + elementid).val();\n let parentelem = fileinput.next();\n filename = parentelem.find('.chunkupload-filename');\n progress = parentelem.find('.chunkupload-progress');\n progressicon = parentelem.find('.chunkupload-icon');\n deleteicon = parentelem.next();\n wwwRoot = wwwroot;\n chunkSize = chunksize;\n fileinput.change(() => {\n reset();\n let file = fileinput.get(0).files[0];\n let fileextension = \".\";\n if (file.name.indexOf(\".\") !== -1) {\n let splits = file.name.split(\".\");\n fileextension = \".\" + splits[splits.length - 1].toLowerCase();\n }\n if (!(acceptedTypes === '*' ||\n acceptedTypes instanceof Array && (acceptedTypes.indexOf(fileextension) !== -1 || acceptedTypes.indexOf('*') !== -1))) {\n fileinput.val(null);\n notifyError({key: 'invalidfiletype', component: 'core_repository', param: fileextension});\n return;\n } else if (maxBytes !== -1 && file.size > maxBytes) {\n fileinput.val(null);\n notifyError({key: 'errorpostmaxsize', component: 'core_repository'});\n return;\n }\n filename.text(file.name);\n startUpload(file);\n });\n\n deleteicon.on('click', (event) => {\n reset();\n let params = {\n id: token\n };\n let xhr = new XMLHttpRequest();\n xhr.open('post', wwwRoot + \"/local/chunkupload/deleteupload_ajax.php?\" + $.param(params));\n xhr.send(null);\n filename.text(browsetext);\n fileinput.val(null);\n event.stopPropagation();\n });\n\n /**\n * Start the Upload\n * @param {File} file The File to upload.\n */\n function startUpload(file) {\n let end = chunkSize < file.size ? chunkSize : file.size;\n let params = {\n start: 0,\n end: end,\n length: file.size,\n filename: file.name,\n id: token\n };\n let slice = file.slice(0, end);\n let xhr = new XMLHttpRequest();\n xhr.open('post', wwwRoot + \"/local/chunkupload/startupload_ajax.php?\" + $.param(params));\n xhr.upload.onprogress = (e) => {\n setProgress(e.loaded, file.size);\n };\n xhr.onreadystatechange = () => {\n if (xhr.readyState === 4) {\n if (xhr.status === 200) {\n let response = JSON.parse(xhr.responseText);\n if (response.error !== undefined) {\n notifyError(response.error);\n } else {\n if (end < file.size) {\n proceedUpload(file, chunkSize);\n }\n }\n }\n }\n };\n xhr.setRequestHeader('Content-Type', 'application/octet-stream');\n xhr.send(slice);\n }\n\n /**\n * Proceed the upload\n * @param {File} file\n * @param {int} start from where to proceed the upload.\n */\n function proceedUpload(file, start) {\n let end = start + chunkSize < file.size ? start + chunkSize : file.size;\n let params = {\n start: start,\n end: end,\n id: token\n };\n let slice = file.slice(start, end);\n let xhr = new XMLHttpRequest();\n xhr.open('post', wwwRoot + \"/local/chunkupload/proceedupload_ajax.php?\" + $.param(params));\n xhr.upload.onprogress = (e) => {\n setProgress(e.loaded + start, file.size);\n };\n xhr.onreadystatechange = () => {\n if (xhr.readyState === 4) {\n if (xhr.status === 200) {\n let response = JSON.parse(xhr.responseText);\n if (response.error !== undefined) {\n notifyError(response.error);\n } else {\n if (end < file.size) {\n proceedUpload(file, end);\n }\n }\n }\n }\n };\n xhr.onerror = () => {\n reset();\n // Doesn't make sense to try to fetch strings when having internet problems.\n notification.alert(\"Error\", \"Failure while uploading!\", \"Ok\");\n };\n xhr.setRequestHeader('Content-Type', 'application/octet-stream');\n xhr.send(slice);\n }\n\n /**\n * Resets the Progress and the Filepicker name.\n */\n function reset() {\n setProgress(0, 1);\n filename.text(\"\");\n }\n\n /**\n * Sets the progressbar\n * @param {int} loaded\n * @param {int} total\n */\n function setProgress(loaded, total) {\n if (loaded === total) {\n // Hide progressbar on finish.\n progress.css('width', '0');\n } else {\n progress.css('width', loaded * 100 / total + \"%\");\n }\n progressicon.prop('hidden', loaded !== total);\n deleteicon.prop('hidden', loaded !== total);\n }\n\n /**\n * Notify error\n * @param {object|string} errorstring Either Object as accepted by getString, or a string, to describe the error.\n */\n function notifyError(errorstring) {\n reset();\n if (typeof errorstring === \"string\") {\n getStrings([\n {key: 'error'},\n {key: 'ok'},\n ]).done(function(s) {\n notification.alert(s[0], errorstring, s[1]);\n }\n ).fail(notification.exception);\n } else {\n getStrings([\n {key: 'error'},\n errorstring,\n {key: 'ok'},\n ]).done(function(s) {\n notification.alert(s[0], s[1], s[2]);\n }\n ).fail(notification.exception);\n }\n }\n}"],"file":"chunkupload.min.js"} \ No newline at end of file diff --git a/amd/src/chunkupload.js b/amd/src/chunkupload.js index 8a018a5..7de154d 100644 --- a/amd/src/chunkupload.js +++ b/amd/src/chunkupload.js @@ -16,7 +16,7 @@ /** * Manage the upload in chunks. * - * @package local_chunkupload + * @module local_chunkupload * @copyright 2020 Justus Dieckmann WWU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -56,7 +56,7 @@ export function init(elementid, acceptedTypes, maxBytes, wwwroot, chunksize, bro let fileextension = "."; if (file.name.indexOf(".") !== -1) { let splits = file.name.split("."); - fileextension = "." + splits[splits.length - 1]; + fileextension = "." + splits[splits.length - 1].toLowerCase(); } if (!(acceptedTypes === '*' || acceptedTypes instanceof Array && (acceptedTypes.indexOf(fileextension) !== -1 || acceptedTypes.indexOf('*') !== -1))) {