From 9b2db30a824ca593f2bff4ad5898fae1d9b78ff9 Mon Sep 17 00:00:00 2001 From: hex Date: Sat, 28 Dec 2024 21:51:06 +0100 Subject: [PATCH] :3 --- .gitignore | 3 ++- package-lock.json | 6 ++++++ public/assets/{index-Ccw9dgTj.js => index-CnOGj8CL.js} | 2 +- public/index.html | 2 +- src/gw.nim | 4 +--- web/src/pages/Home/index.tsx | 4 ++-- 6 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 package-lock.json rename public/assets/{index-Ccw9dgTj.js => index-CnOGj8CL.js} (85%) diff --git a/.gitignore b/.gitignore index 735ae63..ec6cbde 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.db gw gw.exe -gw_linkerArgs.txt \ No newline at end of file +gw_linkerArgs.txt +web/node_modules diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e66d228 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "gw", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/public/assets/index-Ccw9dgTj.js b/public/assets/index-CnOGj8CL.js similarity index 85% rename from public/assets/index-Ccw9dgTj.js rename to public/assets/index-CnOGj8CL.js index 8b570d7..0b4db9f 100644 --- a/public/assets/index-Ccw9dgTj.js +++ b/public/assets/index-CnOGj8CL.js @@ -1 +1 @@ -(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const _ of document.querySelectorAll('link[rel="modulepreload"]'))n(_);new MutationObserver(_=>{for(const o of _)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&n(c)}).observe(document,{childList:!0,subtree:!0});function r(_){const o={};return _.integrity&&(o.integrity=_.integrity),_.referrerPolicy&&(o.referrerPolicy=_.referrerPolicy),_.crossOrigin==="use-credentials"?o.credentials="include":_.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(_){if(_.ep)return;_.ep=!0;const o=r(_);fetch(_.href,o)}})();var j,m,De,U,me,Ue,oe,Re,ue,ie,ce,Me,W={},Ae=[],Ze=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,V=Array.isArray;function H(t,e){for(var r in e)t[r]=e[r];return t}function ae(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function R(t,e,r){var n,_,o,c={};for(o in e)o=="key"?n=e[o]:o=="ref"?_=e[o]:c[o]=e[o];if(arguments.length>2&&(c.children=arguments.length>3?j.call(arguments,2):r),typeof t=="function"&&t.defaultProps!=null)for(o in t.defaultProps)c[o]===void 0&&(c[o]=t.defaultProps[o]);return O(t,c,n,_,null)}function O(t,e,r,n,_){var o={type:t,props:e,key:r,ref:n,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:_??++De,__i:-1,__u:0};return _==null&&m.vnode!=null&&m.vnode(o),o}function ee(t){return t.children}function Z(t,e){this.props=t,this.context=e}function F(t,e){if(e==null)return t.__?F(t.__,t.__i+1):null;for(var r;ee&&U.sort(oe));Q.__r=0}function Ie(t,e,r,n,_,o,c,l,u,s,h){var i,a,f,g,w,y,p=n&&n.__k||Ae,v=e.length;for(u=Ye(r,e,p,u,v),i=0;i0?O(c.type,c.props,c.key,c.ref?c.ref:null,c.__v):c).__=t,c.__b=t.__b+1,l=null,(s=c.__i=Qe(c,r,u,i))!==-1&&(i--,(l=r[s])&&(l.__u|=2)),l==null||l.__v===null?(s==-1&&a--,typeof c.type!="function"&&(c.__u|=4)):s!=u&&(s==u-1?a--:s==u+1?a++:(s>u?a--:a++,c.__u|=4))):t.__k[o]=null;if(i)for(o=0;o(u!=null&&!(2&u.__u)?1:0))for(_=r-1,o=r+1;_>=0||o=0){if((u=e[_])&&!(2&u.__u)&&c==u.key&&l===u.type)return _;_--}if(o2&&(l.children=arguments.length>3?j.call(arguments,2):r),O(t.type,l,n||t.key,_||t.ref,null)}function qe(t,e){var r={__c:e="__cC"+Me++,__:t,Consumer:function(n,_){return n.children(_)},Provider:function(n){var _,o;return this.getChildContext||(_=new Set,(o={})[e]=this,this.getChildContext=function(){return o},this.componentWillUnmount=function(){_=null},this.shouldComponentUpdate=function(c){this.props.value!==c.value&&_.forEach(function(l){l.__e=!0,le(l)})},this.sub=function(c){_.add(c);var l=c.componentWillUnmount;c.componentWillUnmount=function(){_&&_.delete(c),l&&l.call(c)}}),n.children}};return r.Provider.__=r.Consumer.contextType=r}j=Ae.slice,m={__e:function(t,e,r,n){for(var _,o,c;e=e.__;)if((_=e.__c)&&!_.__)try{if((o=_.constructor)&&o.getDerivedStateFromError!=null&&(_.setState(o.getDerivedStateFromError(t)),c=_.__d),_.componentDidCatch!=null&&(_.componentDidCatch(t,n||{}),c=_.__d),c)return _.__E=_}catch(l){t=l}throw t}},De=0,Z.prototype.setState=function(t,e){var r;r=this.__s!=null&&this.__s!==this.state?this.__s:this.__s=H({},this.state),typeof t=="function"&&(t=t(H({},r),this.props)),t&&H(r,t),t!=null&&this.__v&&(e&&this._sb.push(e),le(this))},Z.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),le(this))},Z.prototype.render=ee,U=[],Ue=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,oe=function(t,e){return t.__v.__b-e.__v.__b},Q.__r=0,Re=/(PointerCapture)$|Capture$/i,ue=0,ie=ye(!1),ce=ye(!0),Me=0;var tt=0;function d(t,e,r,n,_,o){e||(e={});var c,l,u=e;if("ref"in u)for(l in u={},e)l=="ref"?c=e[l]:u[l]=e[l];var s={type:t,props:u,key:r,ref:c,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--tt,__i:-1,__u:0,__source:_,__self:o};if(typeof t=="function"&&(c=t.defaultProps))for(l in c)u[l]===void 0&&(u[l]=c[l]);return m.vnode&&m.vnode(s),s}var M,b,te,ke,X=0,Ke=[],k=m,xe=k.__b,we=k.__r,Ee=k.diffed,Ce=k.__c,Pe=k.unmount,Te=k.__;function q(t,e){k.__h&&k.__h(b,t,X||e),X=0;var r=b.__H||(b.__H={__:[],__h:[]});return t>=r.__.length&&r.__.push({}),r.__[t]}function re(t){return X=1,pe(Ge,t)}function pe(t,e,r){var n=q(M++,2);if(n.t=t,!n.__c&&(n.__=[Ge(void 0,e),function(l){var u=n.__N?n.__N[0]:n.__[0],s=n.t(u,l);u!==s&&(n.__N=[s,n.__[1]],n.__c.setState({}))}],n.__c=b,!b.u)){var _=function(l,u,s){if(!n.__c.__H)return!0;var h=n.__c.__H.__.filter(function(a){return!!a.__c});if(h.every(function(a){return!a.__N}))return!o||o.call(this,l,u,s);var i=n.__c.props!==l;return h.forEach(function(a){if(a.__N){var f=a.__[0];a.__=a.__N,a.__N=void 0,f!==a.__[0]&&(i=!0)}}),o&&o.call(this,l,u,s)||i};b.u=!0;var o=b.shouldComponentUpdate,c=b.componentWillUpdate;b.componentWillUpdate=function(l,u,s){if(this.__e){var h=o;o=void 0,_(l,u,s),o=h}c&&c.call(this,l,u,s)},b.shouldComponentUpdate=_}return n.__N||n.__}function $e(t,e){var r=q(M++,3);!k.__s&&ve(r.__H,e)&&(r.__=t,r.i=e,b.__H.__h.push(r))}function ze(t,e){var r=q(M++,4);!k.__s&&ve(r.__H,e)&&(r.__=t,r.i=e,b.__h.push(r))}function $(t){return X=5,de(function(){return{current:t}},[])}function de(t,e){var r=q(M++,7);return ve(r.__H,e)&&(r.__=t(),r.__H=e,r.__h=t),r.__}function Be(t){var e=b.context[t.__c],r=q(M++,9);return r.c=t,e?(r.__==null&&(r.__=!0,e.sub(b)),e.props.value):t.__}function rt(){for(var t;t=Ke.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(Y),t.__H.__h.forEach(se),t.__H.__h=[]}catch(e){t.__H.__h=[],k.__e(e,t.__v)}}k.__b=function(t){b=null,xe&&xe(t)},k.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Te&&Te(t,e)},k.__r=function(t){we&&we(t),M=0;var e=(b=t.__c).__H;e&&(te===b?(e.__h=[],b.__h=[],e.__.forEach(function(r){r.__N&&(r.__=r.__N),r.i=r.__N=void 0})):(e.__h.forEach(Y),e.__h.forEach(se),e.__h=[],M=0)),te=b},k.diffed=function(t){Ee&&Ee(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Ke.push(e)!==1&&ke===k.requestAnimationFrame||((ke=k.requestAnimationFrame)||nt)(rt)),e.__H.__.forEach(function(r){r.i&&(r.__H=r.i),r.i=void 0})),te=b=null},k.__c=function(t,e){e.some(function(r){try{r.__h.forEach(Y),r.__h=r.__h.filter(function(n){return!n.__||se(n)})}catch(n){e.some(function(_){_.__h&&(_.__h=[])}),e=[],k.__e(n,r.__v)}}),Ce&&Ce(t,e)},k.unmount=function(t){Pe&&Pe(t);var e,r=t.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{Y(n)}catch(_){e=_}}),r.__H=void 0,e&&k.__e(e,r.__v))};var He=typeof requestAnimationFrame=="function";function nt(t){var e,r=function(){clearTimeout(n),He&&cancelAnimationFrame(e),setTimeout(t)},n=setTimeout(r,100);He&&(e=requestAnimationFrame(r))}function Y(t){var e=b,r=t.__c;typeof r=="function"&&(t.__c=void 0,r()),b=e}function se(t){var e=b;t.__c=t.__(),b=e}function ve(t,e){return!t||t.length!==e.length||e.some(function(r,n){return r!==t[n]})}function Ge(t,e){return typeof e=="function"?e(t):e}let D,N;const _t=(t,e)=>{if(D=void 0,e&&e.type==="click"){if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.button!==0)return t;const r=e.target.closest("a[href]"),n=r&&r.getAttribute("href");if(!r||r.origin!=location.origin||/^#/.test(n)||!/^(_?self)?$/i.test(r.target)||N&&(typeof N=="string"?!n.startsWith(N):!N.test(n)))return t;D=!0,e.preventDefault(),e=r.href.replace(location.origin,"")}else typeof e=="string"?D=!0:e&&e.url?(D=!e.replace,e=e.url):e=location.pathname+location.search;return D===!0?history.pushState(null,"",e):D===!1&&history.replaceState(null,"",e),e},ot=(t,e,r)=>{t=t.split("/").filter(Boolean),e=(e||"").split("/").filter(Boolean);for(let n=0,_,o;n{const o=new URL(e,location.origin),c=o.pathname.replace(/\/+$/g,"")||"/";return{url:e,path:c,query:Object.fromEntries(o.searchParams),route:(l,u)=>r({url:l,replace:u}),wasPush:n}},[e]);return ze(()=>(addEventListener("click",r),addEventListener("popstate",r),()=>{removeEventListener("click",r),removeEventListener("popstate",r)}),[]),R(K.ctx.Provider,{value:_},t.children)}const it=Promise.resolve();function Je(t){const[e,r]=pe(x=>x+1,0),{url:n,query:_,wasPush:o,path:c}=ct(),{rest:l=c,params:u={}}=Be(Se),s=$(!1),h=$(c),i=$(0),a=$(),f=$(),g=$(),w=$(!1),y=$();y.current=!1;const p=$(!1);let v,S,E;Oe(t.children).some(x=>{if(ot(l,x.props.path,E={...x.props,path:l,query:_,params:u,rest:""}))return v=be(x,E);x.props.default&&(S=be(x,E))});let P=v||S;de(()=>{f.current=a.current;const x=f.current&&f.current.props.children;!x||!P||P.type!==x.type||P.props.component!==x.props.component?(this.__v&&this.__v.__k&&this.__v.__k.reverse(),i.current++,p.current=!0):p.current=!1},[n]);const L=a.current&&a.current.__u&G&&a.current.__u&J,z=a.current&&a.current.__h;a.current=R(Se.Provider,{value:E},P),L?(a.current.__u|=G,a.current.__u|=J):z&&(a.current.__h=!0);const A=f.current;return f.current=null,this.__c=(x,T)=>{y.current=!0,f.current=A,t.onLoadStart&&t.onLoadStart(n),s.current=!0;let C=i.current;x.then(()=>{C===i.current&&(f.current=null,a.current&&(T.__h&&(a.current.__h=T.__h),T.__u&J&&(a.current.__u|=J),T.__u&G&&(a.current.__u|=G)),it.then(r))})},ze(()=>{const x=this.__v&&this.__v.__e;if(y.current){!w.current&&!g.current&&(g.current=x);return}!w.current&&g.current&&(g.current!==x&&g.current.remove(),g.current=null),w.current=!0,h.current!==c&&(o&&scrollTo(0,0),t.onRouteChange&&t.onRouteChange(n),h.current=c),t.onLoadEnd&&s.current&&t.onLoadEnd(n),s.current=!1},[c,o,e]),p.current?[R(ne,{r:a}),R(ne,{r:f})]:R(ne,{r:a})}const G=32,J=128,ne=({r:t})=>t.current;Je.Provider=K;K.ctx=qe({});const Se=qe({}),_e=t=>R(t.component,t),ct=()=>Be(K.ctx),Le=m.__e;m.__e=(t,e,r)=>{if(t&&t.then){let n=e;for(;n=n.__;)if(n.__c&&n.__c.__c)return e.__e==null&&(e.__e=r.__e,e.__k=r.__k),e.__k||(e.__k=[]),n.__c.__c(t,e)}Le&&Le(t,e,r)};function lt(){return d("section",{children:[d("h1",{children:"404: Not Found"}),d("p",{children:"It's gone :("})]})}const st=()=>d("div",{class:"flex w-full h-full justify-center items-center",children:d("h1",{class:"font-bold text-red-500 text-2xl",children:"nice try."})}),ut=()=>{const[t,e]=re(""),[r,n]=re({err:!0,referral:"",key:""}),[_,o]=re("...");$e(()=>{console.log("Referral:",t)},[t]);const c=async()=>{let h=await fetch("http://localhost:8080/entry",{method:"GET",headers:{referral:t}});if(!h.ok){console.error("Error:",h.status);return}let i=await h.json();if(i.err){console.error("Error:",i.referral),window.location.href="/error";return}console.log("Entry:",i),n(i),e("")},l=new Date("2025-01-01T00:00:00Z"),u=new Intl.DateTimeFormat(void 0,{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit",timeZoneName:"short"}).format(l),s=h=>{const i=new Date,a=h.getTime()-i.getTime(),f=Math.floor(a/(1e3*60*60*24)),g=Math.floor(a/(1e3*60*60)%24),w=Math.floor(a/(1e3*60)%60),y=Math.floor(a/1e3%60);let p="";return f>0&&(p+=f+"d "),g>0&&(p+=g+"h "),w>0&&(p+=w+"m "),y>0&&(p+=y+"s"),p===""?p="the time is upon us.":p+=" remaining.",p};return $e(()=>{const h=setInterval(()=>{o(s(l))},1e3);return()=>clearInterval(h)},[]),d("div",{class:"flex flex-col gap-6 w-full h-full justify-center items-center",children:[d("h1",{class:"text-6xl font-bold animate-pulse",children:"???"}),d("p",{children:_}),d("span",{children:[d("p",{class:"opacity-100 hover:opacity-75 transition-opacity",children:"Referral:"}),d("div",{class:"flex gap-2",children:[d("input",{type:"text",value:t,onInput:h=>e(h.currentTarget.value),class:"bg-black text-green-500 border-green-500 border-2 px-2 hover:bg-green-500 hover:text-black active:bg-green-500 active:text-black transition-colors"}),d("button",{onClick:async()=>await c(),class:"bg-green-500 text-black hover:bg-black hover:text-green-500 transition-colors px-4",children:"Submit"})]})]}),r.err?d("div",{class:"w-2/3 text-center flex flex-col gap-2",children:[d("div",{children:[d("b",{children:"What is this?"}),d("p",{children:["At exactly ",u," (00:00 CET on 1 Jan), the system will choose a random entry. Their referral key shall be publicly displayed on this page. The person associated with this referral key shall contact us with their private key. They shall win a little prize. To have one's entry weigh more than the rest, one shall have to spread their referral key amongst people. Every referral shall increase their chance of getting selected."]})]}),d("div",{children:[d("b",{children:"How does one enter?"}),d("p",{children:"One needs a referral key to enter."})]})]}):d("div",{class:"flex flex-col gap-1.5 mt-3 justify-center items-center",children:[d("p",{class:"text-green-700",children:"tip: click to copy."}),d("h2",{onClick:()=>navigator.clipboard.writeText(r==null?void 0:r.key),children:["Key: ",d("code",{class:"cursor-pointer bg-green-800 hover:bg-green-900 active:bg-green-700 transition-colors py-1 px-2 rounded-lg text-white",children:r==null?void 0:r.key})]}),d("h2",{onClick:()=>navigator.clipboard.writeText(r==null?void 0:r.referral),children:["Referral: ",d("code",{class:"cursor-pointer bg-green-800 hover:bg-green-900 active:bg-green-700 transition-colors py-1 px-2 rounded-lg text-white",children:r==null?void 0:r.referral})]}),d("p",{class:"text-green-700",children:"good luck. keep note of these, if you lose them, you can't reroll."})]})]})};function at(){return d(K,{children:d("div",{class:"bg-black text-green-500 h-screen p-4",children:d(Je,{children:[d(_e,{path:"/",component:ut}),d(_e,{default:!0,component:lt}),d(_e,{path:"/error",component:st})]})})})}et(d(at,{}),document.getElementById("app")); +(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const _ of document.querySelectorAll('link[rel="modulepreload"]'))n(_);new MutationObserver(_=>{for(const o of _)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&n(c)}).observe(document,{childList:!0,subtree:!0});function r(_){const o={};return _.integrity&&(o.integrity=_.integrity),_.referrerPolicy&&(o.referrerPolicy=_.referrerPolicy),_.crossOrigin==="use-credentials"?o.credentials="include":_.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(_){if(_.ep)return;_.ep=!0;const o=r(_);fetch(_.href,o)}})();var j,m,De,U,me,Ue,oe,Re,ue,ie,ce,Me,W={},Ae=[],Ze=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,V=Array.isArray;function H(t,e){for(var r in e)t[r]=e[r];return t}function ae(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function R(t,e,r){var n,_,o,c={};for(o in e)o=="key"?n=e[o]:o=="ref"?_=e[o]:c[o]=e[o];if(arguments.length>2&&(c.children=arguments.length>3?j.call(arguments,2):r),typeof t=="function"&&t.defaultProps!=null)for(o in t.defaultProps)c[o]===void 0&&(c[o]=t.defaultProps[o]);return O(t,c,n,_,null)}function O(t,e,r,n,_){var o={type:t,props:e,key:r,ref:n,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:_??++De,__i:-1,__u:0};return _==null&&m.vnode!=null&&m.vnode(o),o}function ee(t){return t.children}function Z(t,e){this.props=t,this.context=e}function F(t,e){if(e==null)return t.__?F(t.__,t.__i+1):null;for(var r;ee&&U.sort(oe));Q.__r=0}function Ie(t,e,r,n,_,o,c,l,u,s,h){var i,a,f,g,w,y,p=n&&n.__k||Ae,v=e.length;for(u=Ye(r,e,p,u,v),i=0;i0?O(c.type,c.props,c.key,c.ref?c.ref:null,c.__v):c).__=t,c.__b=t.__b+1,l=null,(s=c.__i=Qe(c,r,u,i))!==-1&&(i--,(l=r[s])&&(l.__u|=2)),l==null||l.__v===null?(s==-1&&a--,typeof c.type!="function"&&(c.__u|=4)):s!=u&&(s==u-1?a--:s==u+1?a++:(s>u?a--:a++,c.__u|=4))):t.__k[o]=null;if(i)for(o=0;o(u!=null&&!(2&u.__u)?1:0))for(_=r-1,o=r+1;_>=0||o=0){if((u=e[_])&&!(2&u.__u)&&c==u.key&&l===u.type)return _;_--}if(o2&&(l.children=arguments.length>3?j.call(arguments,2):r),O(t.type,l,n||t.key,_||t.ref,null)}function qe(t,e){var r={__c:e="__cC"+Me++,__:t,Consumer:function(n,_){return n.children(_)},Provider:function(n){var _,o;return this.getChildContext||(_=new Set,(o={})[e]=this,this.getChildContext=function(){return o},this.componentWillUnmount=function(){_=null},this.shouldComponentUpdate=function(c){this.props.value!==c.value&&_.forEach(function(l){l.__e=!0,le(l)})},this.sub=function(c){_.add(c);var l=c.componentWillUnmount;c.componentWillUnmount=function(){_&&_.delete(c),l&&l.call(c)}}),n.children}};return r.Provider.__=r.Consumer.contextType=r}j=Ae.slice,m={__e:function(t,e,r,n){for(var _,o,c;e=e.__;)if((_=e.__c)&&!_.__)try{if((o=_.constructor)&&o.getDerivedStateFromError!=null&&(_.setState(o.getDerivedStateFromError(t)),c=_.__d),_.componentDidCatch!=null&&(_.componentDidCatch(t,n||{}),c=_.__d),c)return _.__E=_}catch(l){t=l}throw t}},De=0,Z.prototype.setState=function(t,e){var r;r=this.__s!=null&&this.__s!==this.state?this.__s:this.__s=H({},this.state),typeof t=="function"&&(t=t(H({},r),this.props)),t&&H(r,t),t!=null&&this.__v&&(e&&this._sb.push(e),le(this))},Z.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),le(this))},Z.prototype.render=ee,U=[],Ue=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,oe=function(t,e){return t.__v.__b-e.__v.__b},Q.__r=0,Re=/(PointerCapture)$|Capture$/i,ue=0,ie=ye(!1),ce=ye(!0),Me=0;var tt=0;function d(t,e,r,n,_,o){e||(e={});var c,l,u=e;if("ref"in u)for(l in u={},e)l=="ref"?c=e[l]:u[l]=e[l];var s={type:t,props:u,key:r,ref:c,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--tt,__i:-1,__u:0,__source:_,__self:o};if(typeof t=="function"&&(c=t.defaultProps))for(l in c)u[l]===void 0&&(u[l]=c[l]);return m.vnode&&m.vnode(s),s}var M,b,te,ke,X=0,Ke=[],k=m,xe=k.__b,we=k.__r,Ee=k.diffed,Ce=k.__c,Pe=k.unmount,Te=k.__;function q(t,e){k.__h&&k.__h(b,t,X||e),X=0;var r=b.__H||(b.__H={__:[],__h:[]});return t>=r.__.length&&r.__.push({}),r.__[t]}function re(t){return X=1,pe(Ge,t)}function pe(t,e,r){var n=q(M++,2);if(n.t=t,!n.__c&&(n.__=[Ge(void 0,e),function(l){var u=n.__N?n.__N[0]:n.__[0],s=n.t(u,l);u!==s&&(n.__N=[s,n.__[1]],n.__c.setState({}))}],n.__c=b,!b.u)){var _=function(l,u,s){if(!n.__c.__H)return!0;var h=n.__c.__H.__.filter(function(a){return!!a.__c});if(h.every(function(a){return!a.__N}))return!o||o.call(this,l,u,s);var i=n.__c.props!==l;return h.forEach(function(a){if(a.__N){var f=a.__[0];a.__=a.__N,a.__N=void 0,f!==a.__[0]&&(i=!0)}}),o&&o.call(this,l,u,s)||i};b.u=!0;var o=b.shouldComponentUpdate,c=b.componentWillUpdate;b.componentWillUpdate=function(l,u,s){if(this.__e){var h=o;o=void 0,_(l,u,s),o=h}c&&c.call(this,l,u,s)},b.shouldComponentUpdate=_}return n.__N||n.__}function $e(t,e){var r=q(M++,3);!k.__s&&ve(r.__H,e)&&(r.__=t,r.i=e,b.__H.__h.push(r))}function ze(t,e){var r=q(M++,4);!k.__s&&ve(r.__H,e)&&(r.__=t,r.i=e,b.__h.push(r))}function $(t){return X=5,de(function(){return{current:t}},[])}function de(t,e){var r=q(M++,7);return ve(r.__H,e)&&(r.__=t(),r.__H=e,r.__h=t),r.__}function Be(t){var e=b.context[t.__c],r=q(M++,9);return r.c=t,e?(r.__==null&&(r.__=!0,e.sub(b)),e.props.value):t.__}function rt(){for(var t;t=Ke.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(Y),t.__H.__h.forEach(se),t.__H.__h=[]}catch(e){t.__H.__h=[],k.__e(e,t.__v)}}k.__b=function(t){b=null,xe&&xe(t)},k.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Te&&Te(t,e)},k.__r=function(t){we&&we(t),M=0;var e=(b=t.__c).__H;e&&(te===b?(e.__h=[],b.__h=[],e.__.forEach(function(r){r.__N&&(r.__=r.__N),r.i=r.__N=void 0})):(e.__h.forEach(Y),e.__h.forEach(se),e.__h=[],M=0)),te=b},k.diffed=function(t){Ee&&Ee(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Ke.push(e)!==1&&ke===k.requestAnimationFrame||((ke=k.requestAnimationFrame)||nt)(rt)),e.__H.__.forEach(function(r){r.i&&(r.__H=r.i),r.i=void 0})),te=b=null},k.__c=function(t,e){e.some(function(r){try{r.__h.forEach(Y),r.__h=r.__h.filter(function(n){return!n.__||se(n)})}catch(n){e.some(function(_){_.__h&&(_.__h=[])}),e=[],k.__e(n,r.__v)}}),Ce&&Ce(t,e)},k.unmount=function(t){Pe&&Pe(t);var e,r=t.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{Y(n)}catch(_){e=_}}),r.__H=void 0,e&&k.__e(e,r.__v))};var He=typeof requestAnimationFrame=="function";function nt(t){var e,r=function(){clearTimeout(n),He&&cancelAnimationFrame(e),setTimeout(t)},n=setTimeout(r,100);He&&(e=requestAnimationFrame(r))}function Y(t){var e=b,r=t.__c;typeof r=="function"&&(t.__c=void 0,r()),b=e}function se(t){var e=b;t.__c=t.__(),b=e}function ve(t,e){return!t||t.length!==e.length||e.some(function(r,n){return r!==t[n]})}function Ge(t,e){return typeof e=="function"?e(t):e}let D,N;const _t=(t,e)=>{if(D=void 0,e&&e.type==="click"){if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.button!==0)return t;const r=e.target.closest("a[href]"),n=r&&r.getAttribute("href");if(!r||r.origin!=location.origin||/^#/.test(n)||!/^(_?self)?$/i.test(r.target)||N&&(typeof N=="string"?!n.startsWith(N):!N.test(n)))return t;D=!0,e.preventDefault(),e=r.href.replace(location.origin,"")}else typeof e=="string"?D=!0:e&&e.url?(D=!e.replace,e=e.url):e=location.pathname+location.search;return D===!0?history.pushState(null,"",e):D===!1&&history.replaceState(null,"",e),e},ot=(t,e,r)=>{t=t.split("/").filter(Boolean),e=(e||"").split("/").filter(Boolean);for(let n=0,_,o;n{const o=new URL(e,location.origin),c=o.pathname.replace(/\/+$/g,"")||"/";return{url:e,path:c,query:Object.fromEntries(o.searchParams),route:(l,u)=>r({url:l,replace:u}),wasPush:n}},[e]);return ze(()=>(addEventListener("click",r),addEventListener("popstate",r),()=>{removeEventListener("click",r),removeEventListener("popstate",r)}),[]),R(K.ctx.Provider,{value:_},t.children)}const it=Promise.resolve();function Je(t){const[e,r]=pe(x=>x+1,0),{url:n,query:_,wasPush:o,path:c}=ct(),{rest:l=c,params:u={}}=Be(Se),s=$(!1),h=$(c),i=$(0),a=$(),f=$(),g=$(),w=$(!1),y=$();y.current=!1;const p=$(!1);let v,S,E;Oe(t.children).some(x=>{if(ot(l,x.props.path,E={...x.props,path:l,query:_,params:u,rest:""}))return v=be(x,E);x.props.default&&(S=be(x,E))});let P=v||S;de(()=>{f.current=a.current;const x=f.current&&f.current.props.children;!x||!P||P.type!==x.type||P.props.component!==x.props.component?(this.__v&&this.__v.__k&&this.__v.__k.reverse(),i.current++,p.current=!0):p.current=!1},[n]);const L=a.current&&a.current.__u&G&&a.current.__u&J,z=a.current&&a.current.__h;a.current=R(Se.Provider,{value:E},P),L?(a.current.__u|=G,a.current.__u|=J):z&&(a.current.__h=!0);const A=f.current;return f.current=null,this.__c=(x,T)=>{y.current=!0,f.current=A,t.onLoadStart&&t.onLoadStart(n),s.current=!0;let C=i.current;x.then(()=>{C===i.current&&(f.current=null,a.current&&(T.__h&&(a.current.__h=T.__h),T.__u&J&&(a.current.__u|=J),T.__u&G&&(a.current.__u|=G)),it.then(r))})},ze(()=>{const x=this.__v&&this.__v.__e;if(y.current){!w.current&&!g.current&&(g.current=x);return}!w.current&&g.current&&(g.current!==x&&g.current.remove(),g.current=null),w.current=!0,h.current!==c&&(o&&scrollTo(0,0),t.onRouteChange&&t.onRouteChange(n),h.current=c),t.onLoadEnd&&s.current&&t.onLoadEnd(n),s.current=!1},[c,o,e]),p.current?[R(ne,{r:a}),R(ne,{r:f})]:R(ne,{r:a})}const G=32,J=128,ne=({r:t})=>t.current;Je.Provider=K;K.ctx=qe({});const Se=qe({}),_e=t=>R(t.component,t),ct=()=>Be(K.ctx),Le=m.__e;m.__e=(t,e,r)=>{if(t&&t.then){let n=e;for(;n=n.__;)if(n.__c&&n.__c.__c)return e.__e==null&&(e.__e=r.__e,e.__k=r.__k),e.__k||(e.__k=[]),n.__c.__c(t,e)}Le&&Le(t,e,r)};function lt(){return d("section",{children:[d("h1",{children:"404: Not Found"}),d("p",{children:"It's gone :("})]})}const st=()=>d("div",{class:"flex w-full h-full justify-center items-center",children:d("h1",{class:"font-bold text-red-500 text-2xl",children:"nice try."})}),ut=()=>{const[t,e]=re(""),[r,n]=re({err:!0,referral:"",key:""}),[_,o]=re("...");$e(()=>{console.log("Referral:",t)},[t]);const c=async()=>{let h=await fetch("/entry",{method:"GET",headers:{referral:t}});if(!h.ok){console.error("Error:",h.status);return}let i=await h.json();if(i.err){console.error("Error:",i.referral),window.location.href="/error";return}console.log("Entry:",i),n(i),e("")},l=new Date("2025-01-01T00:00:00Z"),u=new Intl.DateTimeFormat(void 0,{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit",timeZoneName:"short"}).format(l),s=h=>{const i=new Date,a=h.getTime()-i.getTime(),f=Math.floor(a/(1e3*60*60*24)),g=Math.floor(a/(1e3*60*60)%24),w=Math.floor(a/(1e3*60)%60),y=Math.floor(a/1e3%60);let p="";return f>0&&(p+=f+"d "),g>0&&(p+=g+"h "),w>0&&(p+=w+"m "),y>0&&(p+=y+"s"),p===""?p="the time is upon us.":p+=" remaining.",p};return $e(()=>{const h=setInterval(()=>{o(s(l))},1e3);return()=>clearInterval(h)},[]),d("div",{class:"flex flex-col gap-6 w-full h-full justify-center items-center",children:[d("h1",{class:"text-6xl font-bold animate-pulse",children:"???"}),d("p",{children:_}),d("span",{children:[d("p",{class:"opacity-100 hover:opacity-75 transition-opacity",children:"Referral:"}),d("div",{class:"flex gap-2",children:[d("input",{type:"text",value:t,onInput:h=>e(h.currentTarget.value),class:"bg-black text-green-500 border-green-500 border-2 px-2 hover:bg-green-500 hover:text-black active:bg-green-500 active:text-black transition-colors"}),d("button",{onClick:async()=>await c(),class:"bg-green-500 text-black hover:bg-black hover:text-green-500 transition-colors px-4",children:"Submit"})]})]}),r.err?d("div",{class:"w-2/3 text-center flex flex-col gap-2",children:[d("div",{children:[d("b",{children:"What is this?"}),d("p",{children:["At exactly ",u," (00:00 CET on 1 Jan), the system will choose a random entry. Their referral key shall be publicly displayed on this page. The person associated with this referral key shall contact us with their private key. They shall win a little prize. To have one's entry weigh more than the rest, one shall have to spread their referral key amongst people. Every referral shall increase their chance of getting selected."]})]}),d("div",{children:[d("b",{children:"How does one enter?"}),d("p",{children:"One needs a referral key to enter."})]})]}):d("div",{class:"flex flex-col gap-1.5 mt-3 justify-center items-center",children:[d("p",{class:"text-green-700",children:"tip: click to copy."}),d("h2",{onClick:()=>navigator.clipboard.writeText(r==null?void 0:r.key),children:["Key: ",d("code",{class:"cursor-pointer bg-green-800 hover:bg-green-900 active:bg-green-700 transition-colors py-1 px-2 rounded-lg text-white",children:r==null?void 0:r.key})]}),d("h2",{onClick:()=>navigator.clipboard.writeText(r==null?void 0:r.referral),children:["Referral: ",d("code",{class:"cursor-pointer bg-green-800 hover:bg-green-900 active:bg-green-700 transition-colors py-1 px-2 rounded-lg text-white",children:r==null?void 0:r.referral})]}),d("p",{class:"text-green-700",children:"good luck. keep note of these, if you lose them, you can't reroll."})]})]})};function at(){return d(K,{children:d("div",{class:"bg-black text-green-500 h-screen p-4",children:d(Je,{children:[d(_e,{path:"/",component:ut}),d(_e,{default:!0,component:lt}),d(_e,{path:"/error",component:st})]})})})}et(d(at,{}),document.getElementById("app")); diff --git a/public/index.html b/public/index.html index 91bce6c..9e6d3f7 100644 --- a/public/index.html +++ b/public/index.html @@ -6,7 +6,7 @@ Vite + Preact - + diff --git a/src/gw.nim b/src/gw.nim index 29f72f2..6c8139c 100644 --- a/src/gw.nim +++ b/src/gw.nim @@ -15,8 +15,6 @@ sql"""CREATE TABLE IF NOT EXISTS keys( )""") proc index*(ctx: Context) {.async.} = - for x in db.fastRows(sql"SELECT * FROM keys"): - echo x await ctx.staticFileResponse("public/index.html", "") proc ip_exists*(ip: string): bool = @@ -46,7 +44,7 @@ proc gentry*(ctx: Context) {.async.} = ip_exists(ctx.request.hostName)) and not table_empty()) and not debug: err = true else: - generate_referral(key,referral, ctx.request.hostName, $ctx.request.getHeader("header")) + generate_referral(key,referral, ctx.request.hostName, $ctx.request.getHeader("referral")) err = false var info = %* diff --git a/web/src/pages/Home/index.tsx b/web/src/pages/Home/index.tsx index 4fa7fea..8ccb12d 100644 --- a/web/src/pages/Home/index.tsx +++ b/web/src/pages/Home/index.tsx @@ -21,7 +21,7 @@ export const Home = () => { }, [referral]); const entry = async () => { - let res = await fetch("http://localhost:8080/entry", { + let res = await fetch("/entry", { method: 'GET', headers: { referral } }) @@ -141,4 +141,4 @@ export const Home = () => { } ) -}; \ No newline at end of file +};