mirror of
https://github.com/owncast/owncast.git
synced 2025-01-09 01:57:43 +03:00
1 line
No EOL
7.6 KiB
JavaScript
Vendored
1 line
No EOL
7.6 KiB
JavaScript
Vendored
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6356],{36356:function(e,t,n){n.r(t),n.d(t,{default:function(){return M}});var r=n(87462),o=n(15671),a=n(43144),i=n(32531),s=n(73568),c=n(67294),u=n(4942),l=n(45987),p=n(74165),f=n(71002),d=n(15861),h=n(74902),v=n(94184),y=n.n(v),b=n(64217);function m(e){var t=e.responseText||e.response;if(!t)return t;try{return JSON.parse(t)}catch(e){return t}}function k(e){var t=new XMLHttpRequest;e.onProgress&&t.upload&&(t.upload.onprogress=function(t){t.total>0&&(t.percent=t.loaded/t.total*100),e.onProgress(t)});var n=new FormData;e.data&&Object.keys(e.data).forEach(function(t){var r=e.data[t];if(Array.isArray(r)){r.forEach(function(e){n.append("".concat(t,"[]"),e)});return}n.append(t,r)}),e.file instanceof Blob?n.append(e.filename,e.file,e.file.name):n.append(e.filename,e.file),t.onerror=function(t){e.onError(t)},t.onload=function(){if(t.status<200||t.status>=300){var n;return e.onError(((n=Error("cannot ".concat(e.method," ").concat(e.action," ").concat(t.status,"'"))).status=t.status,n.method=e.method,n.url=e.action,n),m(t))}return e.onSuccess(m(t),t)},t.open(e.method,e.action,!0),e.withCredentials&&"withCredentials"in t&&(t.withCredentials=!0);var r=e.headers||{};return null!==r["X-Requested-With"]&&t.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(r).forEach(function(e){null!==r[e]&&t.setRequestHeader(e,r[e])}),t.send(n),{abort:function(){t.abort()}}}var w=+new Date,g=0;function C(){return"rc-upload-".concat(w,"-").concat(++g)}var E=n(80334),F=function(e,t){if(e&&t){var n=Array.isArray(t)?t:t.split(","),r=e.name||"",o=e.type||"",a=o.replace(/\/.*$/,"");return n.some(function(e){var t=e.trim();if(/^\*(\/\*)?$/.test(e))return!0;if("."===t.charAt(0)){var n=r.toLowerCase(),i=t.toLowerCase(),s=[i];return(".jpg"===i||".jpeg"===i)&&(s=[".jpg",".jpeg"]),s.some(function(e){return n.endsWith(e)})}return/\/\*$/.test(t)?a===t.replace(/\/.*$/,""):o===t||!!/^\w+$/.test(t)&&((0,E.ZP)(!1,"Upload takes an invalidate 'accept' type '".concat(t,"'.Skip for check.")),!0)})}return!0},Z=function(e,t,n){var r=function e(r,o){if(r.path=o||"",r.isFile)r.file(function(e){n(e)&&(r.fullPath&&!e.webkitRelativePath&&(Object.defineProperties(e,{webkitRelativePath:{writable:!0}}),e.webkitRelativePath=r.fullPath.replace(/^\//,""),Object.defineProperties(e,{webkitRelativePath:{writable:!1}})),t([e]))});else if(r.isDirectory){var a,i,s;a=function(t){t.forEach(function(t){e(t,"".concat(o).concat(r.name,"/"))})},i=r.createReader(),s=[],function e(){i.readEntries(function(t){var n=Array.prototype.slice.apply(t);s=s.concat(n),n.length?e():a(s)})}()}};e.forEach(function(e){r(e.webkitGetAsEntry())})},x=["component","prefixCls","className","disabled","id","style","multiple","accept","capture","children","directory","openFileDialogOnClick","onMouseEnter","onMouseLeave"],D=function(e){(0,i.Z)(n,e);var t=(0,s.Z)(n);function n(){(0,o.Z)(this,n);for(var e,r,a=arguments.length,i=Array(a),s=0;s<a;s++)i[s]=arguments[s];return(e=t.call.apply(t,[this].concat(i))).state={uid:C()},e.reqs={},e.fileInput=void 0,e._isMounted=void 0,e.onChange=function(t){var n=e.props,r=n.accept,o=n.directory,a=t.target.files,i=(0,h.Z)(a).filter(function(e){return!o||F(e,r)});e.uploadFiles(i),e.reset()},e.onClick=function(t){var n=e.fileInput;if(n){var r=e.props,o=r.children,a=r.onClick;if(o&&"button"===o.type){var i=n.parentNode;i.focus(),i.querySelector("button").blur()}n.click(),a&&a(t)}},e.onKeyDown=function(t){"Enter"===t.key&&e.onClick(t)},e.onFileDrop=function(t){var n=e.props.multiple;if(t.preventDefault(),"dragover"!==t.type){if(e.props.directory)Z(Array.prototype.slice.call(t.dataTransfer.items),e.uploadFiles,function(t){return F(t,e.props.accept)});else{var r=(0,h.Z)(t.dataTransfer.files).filter(function(t){return F(t,e.props.accept)});!1===n&&(r=r.slice(0,1)),e.uploadFiles(r)}}},e.uploadFiles=function(t){var n=(0,h.Z)(t);Promise.all(n.map(function(t){return t.uid=C(),e.processFile(t,n)})).then(function(t){var n=e.props.onBatchStart;null==n||n(t.map(function(e){return{file:e.origin,parsedFile:e.parsedFile}})),t.filter(function(e){return null!==e.parsedFile}).forEach(function(t){e.post(t)})})},e.processFile=(r=(0,d.Z)((0,p.Z)().mark(function t(n,r){var o,a,i,s,c,u,l,d;return(0,p.Z)().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(o=e.props.beforeUpload,a=n,!o){t.next=14;break}return t.prev=3,t.next=6,o(n,r);case 6:a=t.sent,t.next=12;break;case 9:t.prev=9,t.t0=t.catch(3),a=!1;case 12:if(!1!==a){t.next=14;break}return t.abrupt("return",{origin:n,parsedFile:null,action:null,data:null});case 14:if("function"!=typeof(i=e.props.action)){t.next=21;break}return t.next=18,i(n);case 18:s=t.sent,t.next=22;break;case 21:s=i;case 22:if("function"!=typeof(c=e.props.data)){t.next=29;break}return t.next=26,c(n);case 26:u=t.sent,t.next=30;break;case 29:u=c;case 30:return(d=(l=("object"===(0,f.Z)(a)||"string"==typeof a)&&a?a:n)instanceof File?l:new File([l],n.name,{type:n.type})).uid=n.uid,t.abrupt("return",{origin:n,data:u,parsedFile:d,action:s});case 35:case"end":return t.stop()}},t,null,[[3,9]])})),function(e,t){return r.apply(this,arguments)}),e.saveFileInput=function(t){e.fileInput=t},e}return(0,a.Z)(n,[{key:"componentDidMount",value:function(){this._isMounted=!0}},{key:"componentWillUnmount",value:function(){this._isMounted=!1,this.abort()}},{key:"post",value:function(e){var t=this,n=e.data,r=e.origin,o=e.action,a=e.parsedFile;if(this._isMounted){var i=this.props,s=i.onStart,c=i.customRequest,u=i.name,l=i.headers,p=i.withCredentials,f=i.method,d=r.uid;s(r),this.reqs[d]=(c||k)({action:o,filename:u,data:n,file:a,headers:l,withCredentials:p,method:f||"post",onProgress:function(e){var n=t.props.onProgress;null==n||n(e,a)},onSuccess:function(e,n){var r=t.props.onSuccess;null==r||r(e,a,n),delete t.reqs[d]},onError:function(e,n){var r=t.props.onError;null==r||r(e,n,a),delete t.reqs[d]}})}}},{key:"reset",value:function(){this.setState({uid:C()})}},{key:"abort",value:function(e){var t=this.reqs;if(e){var n=e.uid?e.uid:e;t[n]&&t[n].abort&&t[n].abort(),delete t[n]}else Object.keys(t).forEach(function(e){t[e]&&t[e].abort&&t[e].abort(),delete t[e]})}},{key:"render",value:function(){var e,t=this.props,n=t.component,o=t.prefixCls,a=t.className,i=t.disabled,s=t.id,p=t.style,f=t.multiple,d=t.accept,h=t.capture,v=t.children,m=t.directory,k=t.openFileDialogOnClick,w=t.onMouseEnter,g=t.onMouseLeave,C=(0,l.Z)(t,x),E=y()((e={},(0,u.Z)(e,o,!0),(0,u.Z)(e,"".concat(o,"-disabled"),i),(0,u.Z)(e,a,a),e)),F=i?{}:{onClick:k?this.onClick:function(){},onKeyDown:k?this.onKeyDown:function(){},onMouseEnter:w,onMouseLeave:g,onDrop:this.onFileDrop,onDragOver:this.onFileDrop,tabIndex:"0"};return c.createElement(n,(0,r.Z)({},F,{className:E,role:"button",style:p}),c.createElement("input",(0,r.Z)({},(0,b.Z)(C,{aria:!0,data:!0}),{id:s,type:"file",ref:this.saveFileInput,onClick:function(e){return e.stopPropagation()},key:this.state.uid,style:{display:"none"},accept:d},m?{directory:"directory",webkitdirectory:"webkitdirectory"}:{},{multiple:f,onChange:this.onChange},null!=h?{capture:h}:{})),v)}}]),n}(c.Component);function P(){}var q=function(e){(0,i.Z)(n,e);var t=(0,s.Z)(n);function n(){var e;(0,o.Z)(this,n);for(var r=arguments.length,a=Array(r),i=0;i<r;i++)a[i]=arguments[i];return(e=t.call.apply(t,[this].concat(a))).uploader=void 0,e.saveUploader=function(t){e.uploader=t},e}return(0,a.Z)(n,[{key:"abort",value:function(e){this.uploader.abort(e)}},{key:"render",value:function(){return c.createElement(D,(0,r.Z)({},this.props,{ref:this.saveUploader}))}}]),n}(c.Component);q.defaultProps={component:"span",prefixCls:"rc-upload",data:{},headers:{},name:"file",multipart:!1,onStart:P,onError:P,onSuccess:P,multiple:!1,beforeUpload:null,customRequest:null,withCredentials:!1,openFileDialogOnClick:!0};var M=q}}]); |