owncast/static/web/_next/static/chunks/6356-6b90bc0d52a4f9c3.js
2024-02-07 19:05:09 +00:00

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 q}});var r=n(87462),a=n(15671),o=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(93967),y=n.n(v),m=n(61200);function b(e){var t=e.responseText||e.response;if(!t)return t;try{return JSON.parse(t)}catch(e){return t}}var k=+new Date,g=0;function w(){return"rc-upload-".concat(k,"-").concat(++g)}var C=n(5464),E=function(e,t){if(e&&t){var n=Array.isArray(t)?t:t.split(","),r=e.name||"",a=e.type||"",o=a.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)?o===t.replace(/\/.*$/,""):a===t||!!/^\w+$/.test(t)&&((0,C.ZP)(!1,"Upload takes an invalidate 'accept' type '".concat(t,"'.Skip for check.")),!0)})}return!0},F=function(e,t,n){var r=function e(r,a){if(r){if(r.path=a||"",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 o,i,s;o=function(t){t.forEach(function(t){e(t,"".concat(a).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():o(s)})}()}}};e.forEach(function(e){r(e.webkitGetAsEntry())})},Z=["component","prefixCls","className","disabled","id","style","multiple","accept","capture","children","directory","openFileDialogOnClick","onMouseEnter","onMouseLeave"],x=function(e){(0,i.Z)(n,e);var t=(0,s.Z)(n);function n(){(0,a.Z)(this,n);for(var e,r,o=arguments.length,i=Array(o),s=0;s<o;s++)i[s]=arguments[s];return(e=t.call.apply(t,[this].concat(i))).state={uid:w()},e.reqs={},e.fileInput=void 0,e._isMounted=void 0,e.onChange=function(t){var n=e.props,r=n.accept,a=n.directory,o=t.target.files,i=(0,h.Z)(o).filter(function(e){return!a||E(e,r)});e.uploadFiles(i),e.reset()},e.onClick=function(t){var n=e.fileInput;if(n){var r=t.target,a=e.props.onClick;r&&"BUTTON"===r.tagName&&(n.parentNode.focus(),r.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)F(Array.prototype.slice.call(t.dataTransfer.items),e.uploadFiles,function(t){return E(t,e.props.accept)});else{var r=(0,h.Z)(t.dataTransfer.files).filter(function(t){return E(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=w(),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 a,o,i,s,c,u,l,d;return(0,p.Z)().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(a=e.props.beforeUpload,o=n,!a){t.next=14;break}return t.prev=3,t.next=6,a(n,r);case 6:o=t.sent,t.next=12;break;case 9:t.prev=9,t.t0=t.catch(3),o=!1;case 12:if(!1!==o){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)(o)||"string"==typeof o)&&o?o: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,o.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,a=e.action,o=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||function(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),b(t))}return e.onSuccess(b(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()}}})({action:a,filename:u,data:n,file:o,headers:l,withCredentials:p,method:f||"post",onProgress:function(e){var n=t.props.onProgress;null==n||n(e,o)},onSuccess:function(e,n){var r=t.props.onSuccess;null==r||r(e,o,n),delete t.reqs[d]},onError:function(e,n){var r=t.props.onError;null==r||r(e,n,o),delete t.reqs[d]}})}}},{key:"reset",value:function(){this.setState({uid:w()})}},{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=this.props,t=e.component,n=e.prefixCls,a=e.className,o=e.disabled,i=e.id,s=e.style,p=e.multiple,f=e.accept,d=e.capture,h=e.children,v=e.directory,b=e.openFileDialogOnClick,k=e.onMouseEnter,g=e.onMouseLeave,w=(0,l.Z)(e,Z),C=y()((0,u.Z)((0,u.Z)((0,u.Z)({},n,!0),"".concat(n,"-disabled"),o),a,a)),E=o?{}:{onClick:b?this.onClick:function(){},onKeyDown:b?this.onKeyDown:function(){},onMouseEnter:k,onMouseLeave:g,onDrop:this.onFileDrop,onDragOver:this.onFileDrop,tabIndex:"0"};return c.createElement(t,(0,r.Z)({},E,{className:C,role:"button",style:s}),c.createElement("input",(0,r.Z)({},(0,m.Z)(w,{aria:!0,data:!0}),{id:i,disabled:o,type:"file",ref:this.saveFileInput,onClick:function(e){return e.stopPropagation()},key:this.state.uid,style:{display:"none"},accept:f},v?{directory:"directory",webkitdirectory:"webkitdirectory"}:{},{multiple:p,onChange:this.onChange},null!=d?{capture:d}:{})),h)}}]),n}(c.Component);function D(){}var P=function(e){(0,i.Z)(n,e);var t=(0,s.Z)(n);function n(){var e;(0,a.Z)(this,n);for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return(e=t.call.apply(t,[this].concat(o))).uploader=void 0,e.saveUploader=function(t){e.uploader=t},e}return(0,o.Z)(n,[{key:"abort",value:function(e){this.uploader.abort(e)}},{key:"render",value:function(){return c.createElement(x,(0,r.Z)({},this.props,{ref:this.saveUploader}))}}]),n}(c.Component);P.defaultProps={component:"span",prefixCls:"rc-upload",data:{},headers:{},name:"file",multipart:!1,onStart:D,onError:D,onSuccess:D,multiple:!1,beforeUpload:null,customRequest:null,withCredentials:!1,openFileDialogOnClick:!0};var q=P}}]);