-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.min.js
1 lines (1 loc) · 11.8 KB
/
search.min.js
1
(()=>{function e(t){var a=n[t];if(void 0!==a)return a.exports;var s=n[t]={exports:{}};return r[t](s,s.exports,e),s.exports}var t,r={7836:(e,t,r)=>{function n(e){const t=Z[e.code];return null!=t?t:e.message}function a({image:e}){return e&&e.length>0?h().createElement(T.Z,{src:e,alt:(0,j.__)("Face to search","i8fjs"),fluid:!0,className:"mb-3"}):null}function s({progress:e}){return null==e?null:h().createElement("div",{className:"d-flex align-items-center mb-3"},(0,j.__)("Upload:","i8fjs"),h().createElement(w.Z,{now:-1===e?100:e,striped:-1===e,animated:!0,className:"flex-fill mx-1"}),-1!==e?h().createElement("span",null,e.toFixed(2),"%"):void 0)}function i({minSimilarity:e,maxSimilarity:t,face:r}){return h().createElement("div",{className:"d-flex flex-column position-sticky bg-white",style:{top:"2rem"}},h().createElement("h4",{className:"d-sm-none"},(0,j.__)("Recognized face","i8fjs")),h().createElement("img",{className:"img-fluid mt-3 rounded",src:`data:image/jpeg;base64,${r}`,alt:""}),h().createElement("p",{"aria-label":"Similarity",className:"text-center"},(0,j.sprintf)((0,j.__)("%1$d…%2$d%%","i8fjs"),e,t)))}function o(){return h().createElement(N.Z,null,h().createElement(N.Z.Header,null,(0,j.__)("Processing the request","i8fjs")),h().createElement(N.Z.Body,null,h().createElement(N.Z.Title,null,(0,j.__)("Please wait…","i8fjs")),h().createElement(w.Z,{now:100,striped:!0,animated:!0})))}function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l.apply(this,arguments)}function c(){const{guid:e}=(0,_.UO)();return h().createElement(I,{guid:e})}var m=r(7363),h=r.n(m),u=r(1533),d=r(754),p=r(1262),f=r(8662),_=r(4935),g=r(5783);const E=h().createContext({token:""});var b=r(2568),v=r(3738),k=r(7231),y=r(7137);const j=wp.i18n,S=wp.apiFetch;var x=r.n(S);const Z={AUTHORIZATION_FAILED:(0,j.__)("Authorization failed.","i8fjs"),AUTHORIZATION_REQUIRED:(0,j.__)("Not authorized to perform this action.","i8fjs"),BAD_GATEWAY:(0,j.__)("Error communicating with the server.","i8fjs"),COMM_ERROR:(0,j.__)("Error communicating with the server.","i8fjs"),UNKNOWN_ERROR:(0,j.__)("Unknown error.","i8fjs")};class F{static getApiToken(){return x()({path:"/identigraf/v2/token"}).then((e=>e.token)).catch((()=>{throw new Error((0,j.__)("Error getting the authentication token","i8fjs"))}))}static checkCompareStatus(e,t){return F.get(`/compare/${e}`,t)}static checkSearchStatus(e,t){return F.get(`/search/${e}`,t)}static getMatchedFaces(e,t,r){return F.get(`/search/${e}/matches/${t}/0/20`,r)}static get(e,t){return F.fetch(`${self.i8f.endpoint}${e}`,{headers:{Accept:"application/json",Authorization:`Bearer ${t}`}})}static fetch(e,t){return fetch(e,t).then((e=>e.json())).catch(F.error502)}static error502(){return{success:!1,status:502,code:"COMM_ERROR",message:(0,j.__)("Error communicating with the server","i8fjs")}}}var T=r(3169),w=r(6364);class O extends m.Component{constructor(...e){super(...e),this.state={image:"",uploadProgress:null,error:null,guid:null},this._onFileChange=({currentTarget:e})=>{this.setState({error:null});const{files:t}=e,r=null==t?void 0:t[0];if(null!=r&&r.type.startsWith("image/")){const e=new FileReader;e.addEventListener("load",(({target:e})=>{this.setState({image:e.result})})),e.readAsDataURL(r)}else this.setState({image:""})},this._onFormSubmit=e=>{e.preventDefault();const t=new FormData(e.currentTarget);this.setState({uploadProgress:0,error:null});const r=this.context.token,n=new XMLHttpRequest;n.upload.addEventListener("progress",this._onUploadProgress),n.addEventListener("error",this._onUploadFailed),n.addEventListener("abort",this._onUploadAborted),n.addEventListener("timeout",this._onUploadTimeout),n.addEventListener("load",this._onUploadSucceeded),n.open("POST",`${self.i8f.endpoint}/search`),n.setRequestHeader("Authorization",`Bearer ${r}`),n.send(t)},this._onUploadProgress=e=>{this.setState({uploadProgress:e.lengthComputable?e.loaded/e.total*100:-1})},this._onUploadFailed=()=>{this._setError((0,j.__)("Failed to upload the file","i8fjs"))},this._onUploadTimeout=()=>{this._setError((0,j.__)("Request has timed out","i8fjs"))},this._onUploadAborted=()=>{this._setError((0,j.__)("Upload aborted","i8fjs"))},this._onUploadSucceeded=e=>{this.setState({uploadProgress:100});const t=e.currentTarget;try{const e=JSON.parse(t.responseText);e.success?this.setState({guid:e.guid}):this._setError(401===t.status?(0,j.__)("Unexpected authentication error","i8fjs"):n(e))}catch(e){this._setError((0,j.__)("Unknown error while analyzing the server response","i8fjs"))}}}_setError(e){this.setState({uploadProgress:null,error:e})}render(){const{error:e,guid:t,image:r,uploadProgress:n}=this.state;return null!==t?h().createElement(_.Fg,{to:`/search/${t}`}):h().createElement(b.Z,{encType:"multipart/form-data",onSubmit:this._onFormSubmit},e&&h().createElement(p.Z,{variant:"danger"},e),h().createElement(b.Z.Group,{controlId:"photo",className:"mb-3"},h().createElement(b.Z.Label,null,(0,j.__)("Photo","i8fjs")),h().createElement(b.Z.Control,{name:"photo",type:"file",required:!0,accept:"image/png, image/jpeg",disabled:null!==n,onChange:this._onFileChange})),h().createElement(v.Z,null,h().createElement(k.Z,null,h().createElement(a,{image:r}))),h().createElement(s,{progress:n}),h().createElement(y.Z,{variant:"primary",type:"submit"},(0,j.__)("Submit","i8fjs")))}}O.contextType=E;var C=r(4007),N=r(1325),U=r(3272);class R extends m.Component{constructor(...e){super(...e),this._onLinkClicked=e=>{const{onClick:t}=this.props;t&&(e.preventDefault(),t(e.currentTarget.href))}}render(){const{country:e,face:t,link:r,matchedPhoto:n,name:a,primaryPhoto:s,similarity:i}=this.props;return h().createElement(h().Fragment,null,h().createElement("a",{href:r?r.replace("https://myrotvorets.center",self.i8f.baseurl):"#",target:"_blank",rel:"noopener noreferrer",className:"text-danger fw-bold text-decoration-none fs-3"},a||(0,j.__)("Unknown person","i8fjs")),h().createElement("img",{src:`data:image/jpeg;base64,${t}`,className:"img-fluid img-thumbnail d-block mb-2",alt:(0,j.__)("Face","i8fjs")}),e&&h().createElement("p",{className:"mb-1"},(0,j.sprintf)((0,j.__)("Country: %s","i8fjs"),e)),n&&h().createElement("p",{className:"mb-1"},h().createElement("a",{href:n,target:"_blank",rel:"noopener noreferrer",onClick:this._onLinkClicked},(0,j.__)("Matched photo","i8fjs"))),s&&h().createElement("p",{className:"mb-1"},h().createElement("a",{href:s,target:"_blank",rel:"noopener noreferrer",onClick:this._onLinkClicked},(0,j.__)("Primary photo","i8fjs"))),h().createElement("p",{className:"mb-1"},(0,j.sprintf)((0,j.__)("Similarity: %1$d%%","i8fjs"),i)))}}class I extends m.Component{constructor(...e){super(...e),this.state={state:"check",error:"",capturedFaces:[],matchedFaces:[],lightbox:null},this._timerId=0,this._onFaceLinkClicked=e=>{this.setState({lightbox:e})},this._onLightboxCloseRequest=()=>{this.setState({lightbox:null})},this._checkStatus=()=>{this._timerId=0;const{guid:e}=this.props;F.checkSearchStatus(e,this.context.token).then((e=>(e.success?"inprogress"===e.status?this._timerId=self.setTimeout(this._checkStatus,2e3):this.setState({capturedFaces:e.faces},(()=>this._getMatchedFaces())):this.setState({state:"done",error:n(e)}),null)))},this._renderMatchedFace=(e,t)=>h().createElement(C.Z.Item,{key:t},h().createElement(R,l({},e,{onClick:this._onFaceLinkClicked}))),this._renderCapturedFace=(e,t)=>h().createElement(C.Z.Item,{key:e.faceID},h().createElement(v.Z,null,h().createElement(k.Z,null,h().createElement("strong",{className:"fs-2"},(0,j.sprintf)((0,j.__)("Face %d","i8fjs"),t+1)))),h().createElement(v.Z,null,h().createElement(k.Z,{md:2,className:"position-sticky bg-white",style:{zIndex:1e3,top:0}},h().createElement(i,e)),h().createElement(k.Z,null,this._renderMatchedFaces(e.faceID,t))))}componentDidMount(){this._timerId=self.setTimeout(this._checkStatus,0)}componentWillUnmount(){0!==this._timerId&&self.clearTimeout(this._timerId)}_addMatches(e){this.setState((t=>({matchedFaces:[...t.matchedFaces,e]})))}_getMatchedFaces(){const{guid:e}=this.props,{capturedFaces:t}=this.state;Promise.all(t.map((({faceID:t})=>F.getMatchedFaces(e,t,this.context.token)))).then((e=>(e.forEach((e=>this._addMatches(e.success?e.matches:null))),this.setState({state:"done"})))).catch((e=>console.error(e)))}_renderMatchedFaces(e,t){const{matchedFaces:r}=this.state,n=r[t];return void 0===n?h().createElement(N.Z.Body,null,h().createElement(f.Z,{animation:"border",variant:"primary"},h().createElement("span",{className:"visually-hidden"},(0,j.__)("Loading…","i8fjs")))):null===n?h().createElement(N.Z.Body,null,h().createElement(p.Z,{variant:"danger"},(0,j.__)("Error loading captured faces","i8fjs")),";"):h().createElement(C.Z,{variant:"flush"},n.map(this._renderMatchedFace))}render(){const{capturedFaces:e,error:t,lightbox:r,state:n}=this.state;return"check"===n?h().createElement(o,null):t?h().createElement(p.Z,{variant:"danger"},t):h().createElement(h().Fragment,null,h().createElement(N.Z,null,h().createElement(N.Z.Header,{className:e.length?"bg-primary text-white":"bg-danger text-white"},(0,j.__)("Search Results","i8fjs")),e.length?h().createElement(C.Z,{variant:"flush"},e.map(this._renderCapturedFace)):h().createElement(N.Z.Body,null,h().createElement(N.Z.Text,null,(0,j.__)("Unfortunately, the system has failed to recognize any face on the photo.","i8fjs")))),r&&h().createElement(U.Z,{mainSrc:r,onCloseRequest:this._onLightboxCloseRequest}))}}I.contextType=E;class M extends m.Component{constructor(...e){super(...e),this.state={error:null,ctx:{token:""}},this._timerId=0,this.refreshToken=()=>{F.getApiToken().then((e=>{this.setState({ctx:{token:e},error:null}),this._timerId=self.setTimeout(this.refreshToken,3e5)})).catch((e=>{this.setState({error:e.message}),this._timerId=self.setTimeout(this.refreshToken,3e5)}))}}componentDidMount(){this.refreshToken()}componentWillUnmount(){this._timerId>0&&self.clearTimeout(this._timerId)}render(){const{ctx:e,error:t}=this.state;return h().createElement(d.Z,null,h().createElement(g.UT,null,h().createElement("h1",{className:"h2"},h().createElement(g.rU,{to:"/",className:"text-decoration-none"},self.i8f.title)),t&&h().createElement(p.Z,{variant:"danger"},t),e.token?h().createElement(E.Provider,{value:e},h().createElement(_.Z5,null,h().createElement(_.AW,{path:"/search/:guid",element:h().createElement(c,null)}),h().createElement(_.AW,{path:"/",element:h().createElement(O,null)}))):h().createElement(f.Z,{animation:"border",variant:"primary"})))}}(0,u.render)(h().createElement(h().StrictMode,null,h().createElement(M,null)),document.querySelector(".wrap"))},7363:e=>{e.exports=React},1533:e=>{e.exports=ReactDOM}},n={};e.m=r,t=[],e.O=(r,n,a,s)=>{if(!n){var i=1/0;for(m=0;m<t.length;m++){for(var[n,a,s]=t[m],o=!0,l=0;l<n.length;l++)(!1&s||i>=s)&&Object.keys(e.O).every((t=>e.O[t](n[l])))?n.splice(l--,1):(o=!1,s<i&&(i=s));if(o){t.splice(m--,1);var c=a();void 0!==c&&(r=c)}}return r}s=s||0;for(var m=t.length;m>0&&t[m-1][2]>s;m--)t[m]=t[m-1];t[m]=[n,a,s]},e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},e.j=464,(()=>{var t={464:0};e.O.j=e=>0===t[e];var r=(r,n)=>{var a,s,[i,o,l]=n,c=0;if(i.some((e=>0!==t[e]))){for(a in o)e.o(o,a)&&(e.m[a]=o[a]);if(l)var m=l(e)}for(r&&r(n);c<i.length;c++)e.o(t,s=i[c])&&t[s]&&t[s][0](),t[s]=0;return e.O(m)},n=self.webpackChunk=self.webpackChunk||[];n.forEach(r.bind(null,0)),n.push=r.bind(null,n.push.bind(n))})();var a=e.O(void 0,[251],(()=>e(7836)));a=e.O(a)})();