diff --git a/source/streamio/amd/build/file_upload.min.js b/source/streamio/amd/build/file_upload.min.js index c5b93eb..505432d 100644 --- a/source/streamio/amd/build/file_upload.min.js +++ b/source/streamio/amd/build/file_upload.min.js @@ -1,3 +1,3 @@ -define("mediatimesrc_streamio/file_upload",["exports","mediatimesrc_streamio/tus","core/log","core/config"],(function(_exports,tus,_log,_config){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}var upload;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,tus=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(tus),_log=_interopRequireDefault(_log);const options={endpoint:(_config=_interopRequireDefault(_config)).default.wwwroot+"/api/v1/videos/tus",metadata:{},onError:_log.default.debug,onProgress:function(bytesUploaded,bytesTotal){document.querySelectorAll(".progress").forEach((indicator=>{indicator.style.width=bytesUploaded/bytesTotal*100+"%"}))},onSuccess:function(){document.getElementById("upload_resource_form").submit(),_log.default.debug(upload.url)}};var _default={init:function(token){options.metadata.uploadtoken=token,document.body.removeEventListener("click",this.handleClick),document.body.addEventListener("click",this.handleClick)},handleClick:function(e){if(e.target.closest('button[name="upload"]')){const file=document.querySelector('input[name="streamiofile"]').files[0];e.preventDefault(),options.metadata.filename=file.name,options.metadata.filetype=file.type,_log.default.debug(options),_log.default.debug(tus),(upload=new tus.Upload(file,options)).start()}}};return _exports.default=_default,_exports.default})); +define("mediatimesrc_streamio/file_upload",["exports","mediatimesrc_streamio/tus","core/log"],(function(_exports,tus,_log){var obj,upload;function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,tus=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(tus);const options={endpoint:"https://streamio.com/api/v1/videos/tus",metadata:{},onError:(_log=(obj=_log)&&obj.__esModule?obj:{default:obj}).default.debug,onProgress:function(bytesUploaded,bytesTotal){document.querySelectorAll(".progress").forEach((indicator=>{indicator.style.width=bytesUploaded/bytesTotal*100+"%"}))},onSuccess:function(){document.getElementById("upload_resource_form").submit(),_log.default.debug(upload.url)}};var _default={init:function(token){options.metadata.uploadtoken=token,document.body.removeEventListener("click",this.handleClick),document.body.addEventListener("click",this.handleClick)},handleClick:function(e){if(e.target.closest('button[name="upload"]')){const file=document.querySelector('input[name="streamiofile"]').files[0];e.preventDefault(),options.metadata.filename=file.name,options.metadata.filetype=file.type,_log.default.debug(options),_log.default.debug(tus),(upload=new tus.Upload(file,options)).start()}}};return _exports.default=_default,_exports.default})); //# sourceMappingURL=file_upload.min.js.map \ No newline at end of file diff --git a/source/streamio/amd/build/file_upload.min.js.map b/source/streamio/amd/build/file_upload.min.js.map index 6eb89d5..9da2b95 100644 --- a/source/streamio/amd/build/file_upload.min.js.map +++ b/source/streamio/amd/build/file_upload.min.js.map @@ -1 +1 @@ -{"version":3,"file":"file_upload.min.js","sources":["../src/file_upload.js"],"sourcesContent":["var upload;\n\nimport * as tus from 'mediatimesrc_streamio/tus';\nimport Log from 'core/log';\nimport cfg from 'core/config';\n\nconst options = {\n endpoint: cfg.wwwroot + '/api/v1/videos/tus',\n metadata: {},\n onError: Log.debug,\n onProgress: function(bytesUploaded, bytesTotal) {\n document.querySelectorAll('.progress').forEach(indicator => {\n indicator.style.width = (bytesUploaded / bytesTotal * 100) + '%';\n });\n },\n onSuccess: function() {\n document.getElementById('upload_resource_form').submit();\n Log.debug(upload.url);\n }\n};\n\nexport default {\n init: function(token) {\n options.metadata.uploadtoken = token;\n document.body.removeEventListener('click', this.handleClick);\n document.body.addEventListener('click', this.handleClick);\n },\n\n handleClick: function(e) {\n const button = e.target.closest('button[name=\"upload\"]');\n if (button) {\n const file = document.querySelector('input[name=\"streamiofile\"]').files[0];\n e.preventDefault();\n options.metadata.filename = file.name;\n options.metadata.filetype = file.type;\n Log.debug(options);\n Log.debug(tus);\n\n upload = new tus.Upload(file, options);\n upload.start();\n }\n }\n};\n"],"names":["upload","options","endpoint","wwwroot","metadata","onError","Log","debug","onProgress","bytesUploaded","bytesTotal","document","querySelectorAll","forEach","indicator","style","width","onSuccess","getElementById","submit","url","init","token","uploadtoken","body","removeEventListener","this","handleClick","addEventListener","e","target","closest","file","querySelector","files","preventDefault","filename","name","filetype","type","tus","Upload","start"],"mappings":"0fAAIA,qxBAMEC,QAAU,CACZC,2DAAcC,QAAU,qBACxBC,SAAU,GACVC,QAASC,aAAIC,MACbC,WAAY,SAASC,cAAeC,YAChCC,SAASC,iBAAiB,aAAaC,SAAQC,YAC3CA,UAAUC,MAAMC,MAASP,cAAgBC,WAAa,IAAO,QAGrEO,UAAW,WACPN,SAASO,eAAe,wBAAwBC,sBAC5CZ,MAAMP,OAAOoB,oBAIV,CACXC,KAAM,SAASC,OACXrB,QAAQG,SAASmB,YAAcD,MAC/BX,SAASa,KAAKC,oBAAoB,QAASC,KAAKC,aAChDhB,SAASa,KAAKI,iBAAiB,QAASF,KAAKC,cAGjDA,YAAa,SAASE,MACHA,EAAEC,OAAOC,QAAQ,yBACpB,OACFC,KAAOrB,SAASsB,cAAc,8BAA8BC,MAAM,GACxEL,EAAEM,iBACFlC,QAAQG,SAASgC,SAAWJ,KAAKK,KACjCpC,QAAQG,SAASkC,SAAWN,KAAKO,kBAC7BhC,MAAMN,sBACNM,MAAMiC,MAEVxC,OAAS,IAAIwC,IAAIC,OAAOT,KAAM/B,UACvByC"} \ No newline at end of file +{"version":3,"file":"file_upload.min.js","sources":["../src/file_upload.js"],"sourcesContent":["var upload;\n\nimport * as tus from 'mediatimesrc_streamio/tus';\nimport Log from 'core/log';\n\nconst options = {\n endpoint: 'https://streamio.com/api/v1/videos/tus',\n metadata: {},\n onError: Log.debug,\n onProgress: function(bytesUploaded, bytesTotal) {\n document.querySelectorAll('.progress').forEach(indicator => {\n indicator.style.width = (bytesUploaded / bytesTotal * 100) + '%';\n });\n },\n onSuccess: function() {\n document.getElementById('upload_resource_form').submit();\n Log.debug(upload.url);\n }\n};\n\nexport default {\n init: function(token) {\n options.metadata.uploadtoken = token;\n document.body.removeEventListener('click', this.handleClick);\n document.body.addEventListener('click', this.handleClick);\n },\n\n handleClick: function(e) {\n const button = e.target.closest('button[name=\"upload\"]');\n if (button) {\n const file = document.querySelector('input[name=\"streamiofile\"]').files[0];\n e.preventDefault();\n options.metadata.filename = file.name;\n options.metadata.filetype = file.type;\n Log.debug(options);\n Log.debug(tus);\n\n upload = new tus.Upload(file, options);\n upload.start();\n }\n }\n};\n"],"names":["upload","options","endpoint","metadata","onError","debug","onProgress","bytesUploaded","bytesTotal","document","querySelectorAll","forEach","indicator","style","width","onSuccess","getElementById","submit","url","init","token","uploadtoken","body","removeEventListener","this","handleClick","addEventListener","e","target","closest","file","querySelector","files","preventDefault","filename","name","filetype","type","tus","Upload","start"],"mappings":"mIAAIA,sgCAKEC,QAAU,CACZC,SAAU,yCACVC,SAAU,GACVC,oEAAaC,MACbC,WAAY,SAASC,cAAeC,YAChCC,SAASC,iBAAiB,aAAaC,SAAQC,YAC3CA,UAAUC,MAAMC,MAASP,cAAgBC,WAAa,IAAO,QAGrEO,UAAW,WACPN,SAASO,eAAe,wBAAwBC,sBAC5CZ,MAAML,OAAOkB,oBAIV,CACXC,KAAM,SAASC,OACXnB,QAAQE,SAASkB,YAAcD,MAC/BX,SAASa,KAAKC,oBAAoB,QAASC,KAAKC,aAChDhB,SAASa,KAAKI,iBAAiB,QAASF,KAAKC,cAGjDA,YAAa,SAASE,MACHA,EAAEC,OAAOC,QAAQ,yBACpB,OACFC,KAAOrB,SAASsB,cAAc,8BAA8BC,MAAM,GACxEL,EAAEM,iBACFhC,QAAQE,SAAS+B,SAAWJ,KAAKK,KACjClC,QAAQE,SAASiC,SAAWN,KAAKO,kBAC7BhC,MAAMJ,sBACNI,MAAMiC,MAEVtC,OAAS,IAAIsC,IAAIC,OAAOT,KAAM7B,UACvBuC"} \ No newline at end of file diff --git a/source/streamio/amd/src/file_upload.js b/source/streamio/amd/src/file_upload.js index 1784c14..1800f51 100644 --- a/source/streamio/amd/src/file_upload.js +++ b/source/streamio/amd/src/file_upload.js @@ -2,10 +2,9 @@ var upload; import * as tus from 'mediatimesrc_streamio/tus'; import Log from 'core/log'; -import cfg from 'core/config'; const options = { - endpoint: cfg.wwwroot + '/api/v1/videos/tus', + endpoint: 'https://streamio.com/api/v1/videos/tus', metadata: {}, onError: Log.debug, onProgress: function(bytesUploaded, bytesTotal) { diff --git a/source/streamio/classes/form/edit_resource.php b/source/streamio/classes/form/edit_resource.php index 3096008..b6d6c82 100644 --- a/source/streamio/classes/form/edit_resource.php +++ b/source/streamio/classes/form/edit_resource.php @@ -50,10 +50,7 @@ public function definition() { $mform->addElement('text', 'name', get_string('resourcename', 'tool_mediatime')); $mform->setType('name', PARAM_TEXT); $mform->addHelpButton('name', 'resourcename', 'tool_mediatime'); - - $mform->addElement('text', 'title', get_string('title', 'tool_mediatime')); - $mform->setType('title', PARAM_TEXT); - $mform->addHelpButton('title', 'title', 'tool_mediatime'); + $mform->addRule('name', get_string('required'), 'required', null, 'client'); $mform->addElement('hidden', 'edit'); $mform->setType('edit', PARAM_INT); @@ -66,8 +63,14 @@ public function definition() { $mform->setType('newfile', PARAM_INT); $mform->addHelpButton('filesource', 'videofile', 'mediatimesrc_streamio'); + $mform->addElement('text', 'title', get_string('title', 'tool_mediatime')); + $mform->setType('title', PARAM_TEXT); + $mform->addHelpButton('title', 'title', 'tool_mediatime'); + $mform->addElement('textarea', 'description', get_string('description')); $mform->setType('description', PARAM_TEXT); + $mform->disabledIf('description', 'newfile', 0); + $mform->disabledIf('title', 'newfile', 0); $this->tag_elements(); @@ -108,7 +111,7 @@ public function definition_after_data() { $mform->insertElementBefore( $mform->createElement('autocomplete', 'file', '', $options, [ ]), - 'description' + 'title' ); $mform->hideIf('file', 'newfile', 'eq', 1); $mform->setDefault('newfile', 1); @@ -120,6 +123,26 @@ public function definition_after_data() { 'description' ); } + if (!has_capability('mediatimesrc/streamio:upload', context_system::instance())) { + $mform->addRule('file', get_string('required'), 'required', null, 'client'); + } + } + } + /** + * Validate data + * + * @param array $data array of ("fieldname"=>value) of submitted data + * @param array $files array of uploaded files "element_name"=>tmp_file_path + * @return array of "element_name"=>"error_description" if there are errors, + * or an empty array if everything is OK (true allowed for backwards compatibility too). + */ + public function validation($data, $files) { + $errors = []; + + if (empty($data['newfile']) && empty($data['file'])) { + $errors['file'] = get_string('required'); } + + return $errors; } } diff --git a/source/streamio/classes/manager.php b/source/streamio/classes/manager.php index 34d09aa..261c3a1 100644 --- a/source/streamio/classes/manager.php +++ b/source/streamio/classes/manager.php @@ -67,6 +67,8 @@ public function __construct($record = null) { $upload = optional_param('upload', null, PARAM_INT); if (!empty($upload) && !optional_param('cancel', false, PARAM_BOOL)) { + require_sesskey(); + require_capability('mediatimesrc/streamio:upload', context_system::instance()); $video = $this->api->request("/videos", ['tags' => (string)$upload])[0]; $this->api->request("/videos/$video->id", [ 'tags' => implode(array_diff($video->tags, ["$upload", "mediatimeupload"])), @@ -110,20 +112,24 @@ public function __construct($record = null) { $redirect = new moodle_url('/admin/tool/mediatime/index.php'); redirect($redirect); } else if (($data = $this->form->get_data()) && empty($data->newfile)) { + require_sesskey(); $data->timemodified = time(); $data->usermodified = $USER->id; if (empty($data->edit)) { $video = $this->api->request("/videos/$data->file"); + $video->name = $data->name; $data->content = json_encode($video); $data->timecreated = $data->timemodified; $data->edit = $DB->insert_record('tool_mediatime', $data); } else { $data->id = $data->edit; - $this->api->request("/videos/" . $this->content->id, array_intersect_key((array)$data, [ - 'description' => true, - 'title' => true, - ]), 'PUT'); + if (has_capability('mediatimesrc/streamio:upload', context_system::instance())) { + $this->api->request("/videos/" . $this->content->id, array_intersect_key((array)$data, [ + 'description' => true, + 'title' => true, + ]), 'PUT'); + } $video = $this->api->request("/videos/" . $this->content->id); $video->name = $data->name; $data->content = json_encode($video); @@ -161,7 +167,11 @@ public function export_for_template(renderer_base $output) { 'resource' => $output->render($resource), ]; } else if (($data = $this->form->get_data()) && !empty($data->newfile)) { + require_sesskey(); + require_capability('mediatimesrc/streamio:upload', context_system::instance()); + $data->upload = file_get_unused_draft_itemid(); + $data->sesskey = sesskey(); $data->token = $this->api->create_token([ 'tags' => "mediatimeupload,$data->upload", @@ -171,7 +181,6 @@ public function export_for_template(renderer_base $output) { ]))->token; $data->tags = json_encode($data->tags); - require_capability('mediatimesrc/streamio:upload', context_system::instance()); return [ 'form' => $output->render_from_template('mediatimesrc_streamio/file_upload', $data), ]; diff --git a/source/streamio/templates/file_upload.mustache b/source/streamio/templates/file_upload.mustache index b128808..b71bdb3 100644 --- a/source/streamio/templates/file_upload.mustache +++ b/source/streamio/templates/file_upload.mustache @@ -29,21 +29,22 @@ }}
-
+ -
- -
-
-
-
-
- - -
+
+
+ +
+
+
+
+
+ + +
{{# js }} diff --git a/source/videotime/classes/form/edit_resource.php b/source/videotime/classes/form/edit_resource.php index 700ea79..cf21ba0 100644 --- a/source/videotime/classes/form/edit_resource.php +++ b/source/videotime/classes/form/edit_resource.php @@ -50,6 +50,7 @@ public function definition() { $mform->setDefault('source', 'videotime'); $mform->addElement('text', 'name', get_string('resourcename', 'tool_mediatime')); + $mform->addRule('name', get_string('required'), 'required', null, 'client'); $mform->setType('name', PARAM_TEXT); $mform->addHelpButton('name', 'resourcename', 'tool_mediatime'); @@ -79,6 +80,7 @@ public function definition() { ] ); $mform->addHelpButton('videofile', 'videofile', 'mediatimesrc_videotime'); + $mform->addRule('videofile', get_string('required'), 'required', null, 'client'); $mform->addElement( 'filemanager', diff --git a/source/videotime/classes/manager.php b/source/videotime/classes/manager.php index 21fddb1..853693e 100644 --- a/source/videotime/classes/manager.php +++ b/source/videotime/classes/manager.php @@ -69,12 +69,7 @@ public function __construct($record = null) { if ($edit = optional_param('edit', null, PARAM_INT)) { $draftitemid = file_get_submitted_draft_itemid('videofile'); file_prepare_draft_area( - // The $draftitemid is the target location. $draftitemid, - - // The combination of contextid / component / filearea / itemid - // form the virtual bucket that files are currently stored in - // and will be copied from. $context->id, 'mediatimesrc_videotime', 'videofile', @@ -88,12 +83,7 @@ public function __construct($record = null) { $draftitemid = file_get_submitted_draft_itemid('posterimage'); file_prepare_draft_area( - // The $draftitemid is the target location. $draftitemid, - - // The combination of contextid / component / filearea / itemid - // form the virtual bucket that files are currently stored in - // and will be copied from. $context->id, 'mediatimesrc_videotime', 'posterimage', @@ -115,6 +105,7 @@ public function __construct($record = null) { $redirect = new moodle_url('/admin/tool/mediatime/index.php'); redirect($redirect); } else if ($data = $this->form->get_data()) { + require_sesskey(); $data->timemodified = time(); $data->usermodified = $USER->id;