Skip to content

Commit

Permalink
cmd/anubis: disable video test for now
Browse files Browse the repository at this point in the history
Signed-off-by: Xe Iaso <[email protected]>
  • Loading branch information
Xe committed Jan 26, 2025
1 parent 5f95aee commit 52e5727
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions cmd/anubis/js/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ const imageURL = (mood) => {
const image = document.getElementById('image');
const title = document.getElementById('title');
const spinner = document.getElementById('spinner');
const testarea = document.getElementById('testarea');
// const testarea = document.getElementById('testarea');

const videoWorks = await testVideo(testarea);
// const videoWorks = await testVideo(testarea);
// console.log(`videoWorks: ${videoWorks}`);

if (!videoWorks) {
title.innerHTML = "Oh no!";
status.innerHTML = "Checks failed. Please check your browser's settings and try again.";
image.src = imageURL("sad");
spinner.innerHTML = "";
spinner.style.display = "none";
return;
}
// if (!videoWorks) {
// title.innerHTML = "Oh no!";
// status.innerHTML = "Checks failed. Please check your browser's settings and try again.";
// image.src = imageURL("sad");
// spinner.innerHTML = "";
// spinner.style.display = "none";
// return;
// }

status.innerHTML = 'Calculating...';

Expand Down
2 changes: 1 addition & 1 deletion cmd/anubis/static/js/main.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(()=>{function w(e,i=5){return new Promise((n,t)=>{let o=URL.createObjectURL(new Blob(["(",y(),")()"],{type:"application/javascript"})),s=new Worker(o);s.onmessage=r=>{s.terminate(),n(r.data)},s.onerror=r=>{s.terminate(),t()},s.postMessage({data:e,difficulty:i}),URL.revokeObjectURL(o)})}function y(){return function(){let e=i=>{let n=new TextEncoder().encode(i);return crypto.subtle.digest("SHA-256",n.buffer).then(t=>Array.from(new Uint8Array(t)).map(o=>o.toString(16).padStart(2,"0")).join(""))};addEventListener("message",async i=>{let n=i.data.data,t=i.data.difficulty,o,s=0;do o=await e(n+s++);while(o.substring(0,t)!==Array(t+1).join("0"));s-=1,postMessage({hash:o,data:n,difficulty:t,nonce:s})})}.toString()}var g='<video id="videotest" width="0" height="0" src="/.within.website/x/cmd/anubis/static/testdata/black.mp4"></video>',h=async e=>(e.innerHTML=g,await new Promise(i=>{let n=document.getElementById("videotest");n.oncanplay=()=>{e.style.display="none",i(!0)},n.onerror=t=>{e.style.display="none",i(!1)}}));var f=(e="",i={})=>{let n=new URL(e,window.location.href);return Object.entries(i).forEach(t=>{let[o,s]=t;n.searchParams.set(o,s)}),n.toString()},d=e=>`/.within.website/x/cmd/anubis/static/img/${e}.webp`;(async()=>{let e=document.getElementById("status"),i=document.getElementById("image"),n=document.getElementById("title"),t=document.getElementById("spinner"),o=document.getElementById("testarea");if(!await h(o)){n.innerHTML="Oh no!",e.innerHTML="Checks failed. Please check your browser's settings and try again.",i.src=d("sad"),t.innerHTML="",t.style.display="none";return}e.innerHTML="Calculating...";let{challenge:r,difficulty:c}=await fetch("/.within.website/x/cmd/anubis/api/make-challenge",{method:"POST"}).then(a=>{if(!a.ok)throw new Error("Failed to fetch config");return a.json()}).catch(a=>{throw n.innerHTML="Oh no!",e.innerHTML=`Failed to fetch config: ${a.message}`,i.src=d("sad"),t.innerHTML="",t.style.display="none",a});e.innerHTML=`Calculating...<br/>Difficulty: ${c}`;let l=Date.now(),{hash:p,nonce:m}=await w(r,c),u=Date.now();n.innerHTML="Success!",e.innerHTML=`Done! Took ${u-l}ms, ${m} iterations`,i.src=d("happy"),t.innerHTML="",t.style.display="none",setTimeout(()=>{let a=window.location.href;window.location.href=f("/.within.website/x/cmd/anubis/api/pass-challenge",{response:p,nonce:m,redir:a,elapsedTime:u-l,difficulty:c})},2e3)})();})();
(()=>{function l(n,s=5){return new Promise((i,t)=>{let o=URL.createObjectURL(new Blob(["(",w(),")()"],{type:"application/javascript"})),e=new Worker(o);e.onmessage=r=>{e.terminate(),i(r.data)},e.onerror=r=>{e.terminate(),t()},e.postMessage({data:n,difficulty:s}),URL.revokeObjectURL(o)})}function w(){return function(){let n=s=>{let i=new TextEncoder().encode(s);return crypto.subtle.digest("SHA-256",i.buffer).then(t=>Array.from(new Uint8Array(t)).map(o=>o.toString(16).padStart(2,"0")).join(""))};addEventListener("message",async s=>{let i=s.data.data,t=s.data.difficulty,o,e=0;do o=await n(i+e++);while(o.substring(0,t)!==Array(t+1).join("0"));e-=1,postMessage({hash:o,data:i,difficulty:t,nonce:e})})}.toString()}var h=(n="",s={})=>{let i=new URL(n,window.location.href);return Object.entries(s).forEach(t=>{let[o,e]=t;i.searchParams.set(o,e)}),i.toString()},m=n=>`/.within.website/x/cmd/anubis/static/img/${n}.webp`;(async()=>{let n=document.getElementById("status"),s=document.getElementById("image"),i=document.getElementById("title"),t=document.getElementById("spinner");n.innerHTML="Calculating...";let{challenge:o,difficulty:e}=await fetch("/.within.website/x/cmd/anubis/api/make-challenge",{method:"POST"}).then(a=>{if(!a.ok)throw new Error("Failed to fetch config");return a.json()}).catch(a=>{throw i.innerHTML="Oh no!",n.innerHTML=`Failed to fetch config: ${a.message}`,s.src=m("sad"),t.innerHTML="",t.style.display="none",a});n.innerHTML=`Calculating...<br/>Difficulty: ${e}`;let r=Date.now(),{hash:u,nonce:c}=await l(o,e),d=Date.now();i.innerHTML="Success!",n.innerHTML=`Done! Took ${d-r}ms, ${c} iterations`,s.src=m("happy"),t.innerHTML="",t.style.display="none",setTimeout(()=>{let a=window.location.href;window.location.href=h("/.within.website/x/cmd/anubis/api/pass-challenge",{response:u,nonce:c,redir:a,elapsedTime:d-r,difficulty:e})},2e3)})();})();
Binary file modified cmd/anubis/static/js/main.mjs.br
Binary file not shown.
Binary file modified cmd/anubis/static/js/main.mjs.gz
Binary file not shown.
Binary file modified cmd/anubis/static/js/main.mjs.zst
Binary file not shown.

0 comments on commit 52e5727

Please sign in to comment.