qr-fileshare
Version:
Quickly transfer files to a different device via a web interface
2 lines • 14.4 kB
JavaScript
(window.webpackJsonp=window.webpackJsonp||[]).push([[0],{202:function(e,t,n){e.exports=n(451)},207:function(e,t,n){},208:function(e,t,n){},404:function(e,t,n){},419:function(e,t,n){},446:function(e,t){},451:function(e,t,n){"use strict";n.r(t);var a=n(0),i=n.n(a),r=n(21),o=n.n(r),c=(n(207),n(17)),l=n(18),s=n(20),u=n(19),f=n(6),d=(n(208),n(22)),h=n.n(d),m=n(51),p=n.n(m),v=n(196),y=n.n(v);function g(e){return function(){var t,n=Object(f.a)(e);if(function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()){var a=Object(f.a)(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return Object(u.a)(this,t)}}var b=function(e){Object(s.a)(n,e);var t=g(n);function n(){var e;return Object(c.a)(this,n),(e=t.call(this)).handleOpen=function(){e.setState({modalIsOpen:!0})},e.handleClose=function(){e.setState({modalIsOpen:!1})},e.state={modalIsOpen:!1},e}return Object(l.a)(n,[{key:"render",value:function(){return i.a.createElement("div",{id:"topBar",style:{background:p.a.main}},i.a.createElement(h.a,{id:"topBarHead",variant:"display2"},"Transfer Files"),i.a.createElement(h.a,{id:"topBarQrLink",onClick:this.handleOpen},"Display QR Code"),i.a.createElement(y.a,{"aria-labelledby":"simple-modal-title","aria-describedby":"simple-modal-description",open:this.state.modalIsOpen,onClose:this.handleClose},i.a.createElement("div",null,i.a.createElement("img",{id:"qrCode",src:"/generated_qr.svg",alt:"QR Code"}))))}}]),n}(i.a.Component),O=n(64),E=n.n(O),w=n(83),j=n.n(w),k=n(197),R=n.n(k),D=n(198),I=n.n(D);function F(e){return function(){var t,n=Object(f.a)(e);if(function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()){var a=Object(f.a)(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return Object(u.a)(this,t)}}var C=function(e){Object(s.a)(n,e);var t=F(n);function n(e){var a;return Object(c.a)(this,n),(a=t.call(this,e)).handleClick=function(){a.setState({open:!0})},a.handleClose=function(e,t){"clickaway"!==t&&a.setState({open:!1})},a.state={open:!1},a.message=e.message,a.identity=e.identity,a}return Object(l.a)(n,[{key:"render",value:function(){return i.a.createElement("div",null,i.a.createElement("button",{onClick:this.handleClick,style:{display:"none"},id:"".concat(this.identity,"SnackbarShowButton")}),i.a.createElement(R.a,{anchorOrigin:{vertical:"bottom",horizontal:"center"},open:this.state.open,autoHideDuration:3e3,onClose:this.handleClose,SnackbarContentProps:{"aria-describedby":"message-id"},message:i.a.createElement("span",{id:"message-id"},this.props.message),action:[i.a.createElement(I.a,{key:"close","aria-label":"Close",color:"inherit",onClick:this.handleClose},i.a.createElement(j.a,{style:{fontSize:"16px",lineHeight:"100%"}},"close"))]}))}}]),n}(i.a.Component),S=n(199);function B(e){return function(){var t,n=Object(f.a)(e);if(function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()){var a=Object(f.a)(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return Object(u.a)(this,t)}}var x={position:"fixed",bottom:"16px",right:"16px"},P=function(e){Object(s.a)(n,e);var t=B(n);function n(){var e;return Object(c.a)(this,n),(e=t.call(this)).fileInputChange=function(){var t=e.state.uploadingFiles;t.push(!0),e.setState({uploadingFiles:t});var n=document.getElementById("fileUploadForm"),a=new FormData(n);fetch("/api/files",{method:"post",body:a}).then(function(t){document.getElementById("uploadedSnackbarShowButton").click(),document.getElementById("fileHiddenInput").value="";var n=e.state.uploadingFiles;n.splice(0,1),e.setState({uploadingFiles:n})})},e.state={uploadingFiles:[]},e}return Object(l.a)(n,[{key:"render",value:function(){return i.a.createElement("div",null,i.a.createElement(E.a,{variant:"fab",color:"secondary","aria-label":"add",style:x,onClick:N},0!==this.state.uploadingFiles.length?i.a.createElement(S.CircularProgress,{variant:"indeterminate",style:{color:"#FFF"},size:30,thickness:5}):i.a.createElement(j.a,null,"add")),i.a.createElement("form",{action:"#",id:"fileUploadForm"},i.a.createElement("input",{type:"file",id:"fileHiddenInput",name:"file",hidden:!0,multiple:!0,onChange:this.fileInputChange})),i.a.createElement(C,{message:"File Uploaded",identity:"uploaded"}))}}]),n}(a.Component),N=function(){document.getElementById("fileHiddenInput").click()},M=P,L=n(41),T=n.n(L),W=n(63),z=n.n(W),U=n(65),H=n.n(U),Q=(n(404),n(200)),A=n.n(Q);var G=function(e){for(var t,n="",a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=new Uint8Array(e),r=i.byteLength,o=r%3,c=r-o,l=0;l<c;l+=3)n+=a[(16515072&(t=i[l]<<16|i[l+1]<<8|i[l+2]))>>18]+a[(258048&t)>>12]+a[(4032&t)>>6]+a[63&t];return 1===o?n+=a[(252&(t=i[c]))>>2]+a[(3&t)<<4]+"==":2===o&&(n+=a[(64512&(t=i[c]<<8|i[c+1]))>>10]+a[(1008&t)>>4]+a[(15&t)<<2]+"="),n};function J(e){return function(){var t,n=Object(f.a)(e);if(function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()){var a=Object(f.a)(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return Object(u.a)(this,t)}}var q=function(e){Object(s.a)(n,e);var t=J(n);function n(e){var a;return Object(c.a)(this,n),(a=t.call(this,e)).generateDataURI=function(){return"data:".concat(a.mimeType,";base64,").concat(G(a.data))},a.onMouseOver=function(){a.setState({shadow:3})},a.onMouseOut=function(){a.setState({shadow:1})},a.formatBytes=function(e,t){if(0===e)return"0 Bytes";var n=t||2,a=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,a)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][a]},a.downloadFile=function(){a.setDownloadFileId(a.file.id,function(){document.getElementById("fileDownloadLink").click()})},a.deleteFile=function(e){e.stopPropagation();fetch("/api/file/".concat(a.file.id),{method:"delete"}).then(function(e){document.getElementById("deletedSnackbarShowButton").click()})},a.file=e.file,a.fileName=e.file.originalname,a.size=e.file.size,a.isPreviewable=!0,e.file.buffer?a.data=e.file.buffer.data:a.isPreviewable=!1,a.mimeType=e.file.mimetype,a.setDownloadFileId=e.setDownloadFileId,a.state={shadow:1},a}return Object(l.a)(n,[{key:"render",value:function(){return i.a.createElement("div",null,i.a.createElement(A.a,{title:this.fileName},i.a.createElement(H.a,{onMouseOver:this.onMouseOver,onMouseOut:this.onMouseOut,onClick:this.downloadFile,className:"fileCard "+(!this.isPreviewable&&"noImage"),elevation:this.state.shadow},i.a.createElement(T.a,{container:!0,spacing:0},i.a.createElement(T.a,{item:!0,className:"details",xs:7},i.a.createElement(U.CardContent,{className:"fileCardContent "+(this.isPreviewable?"":"noImage")},i.a.createElement(h.a,{className:"fileName",variant:"subheading",color:"inherit",noWrap:!0,style:{maxWidth:"calc(100% - 32px)"}},i.a.createElement("span",{className:"fileNameText"},this.fileName)),i.a.createElement("div",{className:"fileDetails"},i.a.createElement(h.a,{variant:"body1",color:"textSecondary"},this.formatBytes(this.size)))),i.a.createElement(U.CardActions,null,i.a.createElement(E.a,{size:"small",color:"secondary",onClick:this.deleteFile},"Delete"))),i.a.createElement(T.a,{item:!0,className:"details",xs:5},this.isPreviewable&&i.a.createElement(U.CardMedia,{image:this.generateDataURI(this.file),className:"fileCardImage"}))))))}}]),n}(a.Component);n(419);function Y(e){return function(){var t,n=Object(f.a)(e);if(function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()){var a=Object(f.a)(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return Object(u.a)(this,t)}}var K=function(e){Object(s.a)(n,e);var t=Y(n);function n(e){var a;return Object(c.a)(this,n),(a=t.call(this,e)).files=e.files,a.fetchingFiles=e.fetchingFiles,a.setDownloadFileId=e.setDownloadFileId,a}return Object(l.a)(n,[{key:"componentWillReceiveProps",value:function(e){this.files=e.files,this.fetchingFiles=e.fetchingFiles}},{key:"render",value:function(){var e=this;if(this.fetchingFiles)return i.a.createElement(z.a,{elevation:4,className:"fileListPaper"},i.a.createElement(h.a,{color:"textSecondary"},"Loading..."));var t=this.files.map(function(t){return i.a.createElement(T.a,{item:!0,key:t.id,className:"fileListGridItem",xs:12,md:6},i.a.createElement(q,{file:t,setDownloadFileId:e.setDownloadFileId}))});return t.length?i.a.createElement("div",null,i.a.createElement("div",{id:"fileListTopBackground",style:{background:p.a.main}}),i.a.createElement(T.a,{id:"fileListGrid",container:!0,justify:"flex-start",spacing:8,alignItems:"center"},t)):i.a.createElement(z.a,{elevation:4,className:"fileListPaper"},i.a.createElement(h.a,null,"You have no files uploaded yet. Start by uploading one."))}}]),n}(a.Component);function Z(e){return function(){var t,n=Object(f.a)(e);if(function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()){var a=Object(f.a)(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return Object(u.a)(this,t)}}var V=function(e){Object(s.a)(n,e);var t=Z(n);function n(e){var a;return Object(c.a)(this,n),(a=t.call(this,e)).fileId=e.fileId,a}return Object(l.a)(n,[{key:"componentWillUpdate",value:function(e){this.fileId=e.fileId}},{key:"render",value:function(){var e="/api/file/".concat(this.fileId);return i.a.createElement("a",{href:e,download:!0,id:"fileDownloadLink"})}}]),n}(a.Component),X=n(127),$=n(201),_=n.n($);function ee(e){return function(){var t,n=Object(f.a)(e);if(function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()){var a=Object(f.a)(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return Object(u.a)(this,t)}}var te=function(e){Object(s.a)(n,e);var t=ee(n);function n(){var e;return Object(c.a)(this,n),(e=t.call(this)).onDrop=function(e){e.preventDefault(),document.getElementById("fileHiddenInput").files=e.dataTransfer.files},e.onDragOver=function(e){e.preventDefault()},e.state={files:[]},e.style={position:"fixed",top:0,left:0,height:"100vh",width:"100%",visibility:"visible",zIndex:-1},e}return Object(l.a)(n,[{key:"render",value:function(){return i.a.createElement("div",{style:this.style,onDrop:this.onDrop,onDragOver:this.onDragOver})}}]),n}(a.Component);function ne(e){return function(){var t,n=Object(f.a)(e);if(function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()){var a=Object(f.a)(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return Object(u.a)(this,t)}}var ae=Object(X.createMuiTheme)({palette:{primary:p.a}}),ie=function(e){Object(s.a)(n,e);var t=ne(n);function n(){var e;return Object(c.a)(this,n),(e=t.call(this)).state={updateToggle:!1,files:[],fetchingFiles:!0,downloadFileId:null},e}return Object(l.a)(n,[{key:"componentDidMount",value:function(){var e=this;this.socket=_.a.connect("/"),this.socket.on("file list update",function(t){t=JSON.parse(t),e.setState({files:t})}),re().then(function(t){e.setState({files:t,fetchingFiles:!1})})}},{key:"setDownloadFileId",value:function(e,t){this.setState({downloadFileId:e},t),this.setState({})}},{key:"render",value:function(){return i.a.createElement(X.MuiThemeProvider,{theme:ae},i.a.createElement(te,null),i.a.createElement(b,null),i.a.createElement(K,{files:this.state.files,fetchingFiles:this.state.fetchingFiles,setDownloadFileId:this.setDownloadFileId.bind(this)}),i.a.createElement(M,null),i.a.createElement(C,{message:"File Deleted",identity:"deleted"}),i.a.createElement(V,{fileId:this.state.downloadFileId}))}}]),n}(a.Component),re=function(){return fetch("/api/files/").then(function(e){return e.json()})},oe=ie,ce=Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));function le(e){navigator.serviceWorker.register(e).then(function(e){e.onupdatefound=function(){var t=e.installing;t.onstatechange=function(){"installed"===t.state&&(navigator.serviceWorker.controller?console.log("New content is available; please refresh."):console.log("Content is cached for offline use."))}}}).catch(function(e){console.error("Error during service worker registration:",e)})}o.a.render(i.a.createElement(oe,null),document.getElementById("root")),function(){if("serviceWorker"in navigator){if(new URL("",window.location).origin!==window.location.origin)return;window.addEventListener("load",function(){var e="".concat("","/service-worker.js");ce?(function(e){fetch(e).then(function(t){404===t.status||-1===t.headers.get("content-type").indexOf("javascript")?navigator.serviceWorker.ready.then(function(e){e.unregister().then(function(){window.location.reload()})}):le(e)}).catch(function(){console.log("No internet connection found. App is running in offline mode.")})}(e),navigator.serviceWorker.ready.then(function(){console.log("This web app is being served cache-first by a service worker. To learn more, visit https://goo.gl/SC7cgQ")})):le(e)})}}()}},[[202,1,2]]]);
//# sourceMappingURL=main.e6e5a6c5.chunk.js.map