From 971c40f00cdd908a1e3a09cfca627e4d17e46f9f Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sat, 5 Jul 2025 04:14:09 -0400 Subject: [PATCH 1/2] Don't increment the attempt counter if the attempt was ratelimited --- assets/js/challenges.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/js/challenges.js b/assets/js/challenges.js index 161d98f..9fcfe0e 100644 --- a/assets/js/challenges.js +++ b/assets/js/challenges.js @@ -184,7 +184,11 @@ Alpine.data("Challenge", () => ({ } // Increment attempts counter - if (this.max_attempts > 0 && this.response.data.status != "already_solved") { + if ( + this.max_attempts > 0 && + this.response.data.status != "already_solved" && + this.response.data.status != "ratelimited" + ) { this.attempts += 1; } From e534816bb87d30870edb234f565e6d90b7960657 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sat, 5 Jul 2025 08:18:58 +0000 Subject: [PATCH 2/2] Run yarn build --- static/assets/challenges.554fe8bb.js | 1 + static/assets/challenges.fe685e10.js | 1 - static/manifest.json | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 static/assets/challenges.554fe8bb.js delete mode 100644 static/assets/challenges.fe685e10.js diff --git a/static/assets/challenges.554fe8bb.js b/static/assets/challenges.554fe8bb.js new file mode 100644 index 0000000..67db48c --- /dev/null +++ b/static/assets/challenges.554fe8bb.js @@ -0,0 +1 @@ +import{m as l,C as s,h as r,T as h,d as g,M as c,a as u}from"./index.8a9f494f.js";function o(e){let a=new DOMParser().parseFromString(e,"text/html");return a.querySelectorAll('a[href*="://"]').forEach(i=>{i.setAttribute("target","_blank")}),a.documentElement.outerHTML}window.Alpine=l;l.store("challenge",{data:{view:""}});l.data("Hint",()=>({id:null,html:null,async showHint(e){if(e.target.open){let t=await s.pages.challenge.loadHint(this.id);if(t.errors){e.target.open=!1,s._functions.challenge.displayUnlockError(t);return}let a=t.data;if(a.content)this.html=o(a.html);else if(await s.pages.challenge.displayUnlock(this.id)){let i=await s.pages.challenge.loadUnlock(this.id);if(i.success){let d=(await s.pages.challenge.loadHint(this.id)).data;this.html=o(d.html)}else e.target.open=!1,s._functions.challenge.displayUnlockError(i)}else e.target.open=!1}}}));l.data("Challenge",()=>({id:null,next_id:null,submission:"",tab:null,solves:[],response:null,share_url:null,max_attempts:0,attempts:0,async init(){r()},getStyles(){let e={"modal-dialog":!0};try{switch(s.config.themeSettings.challenge_window_size){case"sm":e["modal-sm"]=!0;break;case"lg":e["modal-lg"]=!0;break;case"xl":e["modal-xl"]=!0;break;default:break}}catch(t){console.log("Error processing challenge_window_size"),console.log(t)}return e},async init(){r()},async showChallenge(){new h(this.$el).show()},async showSolves(){this.solves=await s.pages.challenge.loadSolves(this.id),this.solves.forEach(e=>(e.date=g(e.date).format("MMMM Do, h:mm:ss A"),e)),new h(this.$el).show()},getNextId(){return l.store("challenge").data.next_id},async nextChallenge(){let e=c.getOrCreateInstance("[x-ref='challengeWindow']");e._element.addEventListener("hidden.bs.modal",t=>{l.nextTick(()=>{this.$dispatch("load-challenge",this.getNextId())})},{once:!0}),e.hide()},async getShareUrl(){let e={type:"solve",challenge_id:this.id};const n=(await(await s.fetch("/api/v1/shares",{method:"POST",body:JSON.stringify(e)})).json()).data.url;this.share_url=n},copyShareUrl(){navigator.clipboard.writeText(this.share_url);let e=u.getOrCreateInstance(this.$el);e.enable(),e.show(),setTimeout(()=>{e.hide(),e.disable()},2e3)},async submitChallenge(){this.response=await s.pages.challenge.submitChallenge(this.id,this.submission),await this.renderSubmissionResponse()},async renderSubmissionResponse(){this.response.data.status==="correct"&&(this.submission=""),this.max_attempts>0&&this.response.data.status!="already_solved"&&this.response.data.status!="ratelimited"&&(this.attempts+=1),this.$dispatch("load-challenges")}}));l.data("ChallengeBoard",()=>({loaded:!1,challenges:[],challenge:null,async init(){if(this.challenges=await s.pages.challenges.getChallenges(),this.loaded=!0,window.location.hash){let e=decodeURIComponent(window.location.hash.substring(1)),t=e.lastIndexOf("-");if(t>=0){let n=[e.slice(0,t),e.slice(t+1)][1];await this.loadChallenge(n)}}},getCategories(){const e=[];this.challenges.forEach(t=>{const{category:a}=t;e.includes(a)||e.push(a)});try{const t=s.config.themeSettings.challenge_category_order;if(t){const a=new Function(`return (${t})`);e.sort(a())}}catch(t){console.log("Error running challenge_category_order function"),console.log(t)}return e},getChallenges(e){let t=this.challenges;e!==null&&(t=this.challenges.filter(a=>a.category===e));try{const a=s.config.themeSettings.challenge_order;if(a){const n=new Function(`return (${a})`);t.sort(n())}}catch(a){console.log("Error running challenge_order function"),console.log(a)}return t},async loadChallenges(){this.challenges=await s.pages.challenges.getChallenges()},async loadChallenge(e){await s.pages.challenge.displayChallenge(e,t=>{t.data.view=o(t.data.view),l.store("challenge").data=t.data,l.nextTick(()=>{let a=c.getOrCreateInstance("[x-ref='challengeWindow']");a._element.addEventListener("hidden.bs.modal",n=>{history.replaceState(null,null," ")},{once:!0}),a.show(),history.replaceState(null,null,`#${t.data.name}-${e}`)})})}}));l.start(); diff --git a/static/assets/challenges.fe685e10.js b/static/assets/challenges.fe685e10.js deleted file mode 100644 index d4a373e..0000000 --- a/static/assets/challenges.fe685e10.js +++ /dev/null @@ -1 +0,0 @@ -import{m as s,C as l,h as r,T as h,d as g,M as c,a as u}from"./index.8a9f494f.js";function o(e){let a=new DOMParser().parseFromString(e,"text/html");return a.querySelectorAll('a[href*="://"]').forEach(i=>{i.setAttribute("target","_blank")}),a.documentElement.outerHTML}window.Alpine=s;s.store("challenge",{data:{view:""}});s.data("Hint",()=>({id:null,html:null,async showHint(e){if(e.target.open){let t=await l.pages.challenge.loadHint(this.id);if(t.errors){e.target.open=!1,l._functions.challenge.displayUnlockError(t);return}let a=t.data;if(a.content)this.html=o(a.html);else if(await l.pages.challenge.displayUnlock(this.id)){let i=await l.pages.challenge.loadUnlock(this.id);if(i.success){let d=(await l.pages.challenge.loadHint(this.id)).data;this.html=o(d.html)}else e.target.open=!1,l._functions.challenge.displayUnlockError(i)}else e.target.open=!1}}}));s.data("Challenge",()=>({id:null,next_id:null,submission:"",tab:null,solves:[],response:null,share_url:null,max_attempts:0,attempts:0,async init(){r()},getStyles(){let e={"modal-dialog":!0};try{switch(l.config.themeSettings.challenge_window_size){case"sm":e["modal-sm"]=!0;break;case"lg":e["modal-lg"]=!0;break;case"xl":e["modal-xl"]=!0;break;default:break}}catch(t){console.log("Error processing challenge_window_size"),console.log(t)}return e},async init(){r()},async showChallenge(){new h(this.$el).show()},async showSolves(){this.solves=await l.pages.challenge.loadSolves(this.id),this.solves.forEach(e=>(e.date=g(e.date).format("MMMM Do, h:mm:ss A"),e)),new h(this.$el).show()},getNextId(){return s.store("challenge").data.next_id},async nextChallenge(){let e=c.getOrCreateInstance("[x-ref='challengeWindow']");e._element.addEventListener("hidden.bs.modal",t=>{s.nextTick(()=>{this.$dispatch("load-challenge",this.getNextId())})},{once:!0}),e.hide()},async getShareUrl(){let e={type:"solve",challenge_id:this.id};const n=(await(await l.fetch("/api/v1/shares",{method:"POST",body:JSON.stringify(e)})).json()).data.url;this.share_url=n},copyShareUrl(){navigator.clipboard.writeText(this.share_url);let e=u.getOrCreateInstance(this.$el);e.enable(),e.show(),setTimeout(()=>{e.hide(),e.disable()},2e3)},async submitChallenge(){this.response=await l.pages.challenge.submitChallenge(this.id,this.submission),await this.renderSubmissionResponse()},async renderSubmissionResponse(){this.response.data.status==="correct"&&(this.submission=""),this.max_attempts>0&&this.response.data.status!="already_solved"&&(this.attempts+=1),this.$dispatch("load-challenges")}}));s.data("ChallengeBoard",()=>({loaded:!1,challenges:[],challenge:null,async init(){if(this.challenges=await l.pages.challenges.getChallenges(),this.loaded=!0,window.location.hash){let e=decodeURIComponent(window.location.hash.substring(1)),t=e.lastIndexOf("-");if(t>=0){let n=[e.slice(0,t),e.slice(t+1)][1];await this.loadChallenge(n)}}},getCategories(){const e=[];this.challenges.forEach(t=>{const{category:a}=t;e.includes(a)||e.push(a)});try{const t=l.config.themeSettings.challenge_category_order;if(t){const a=new Function(`return (${t})`);e.sort(a())}}catch(t){console.log("Error running challenge_category_order function"),console.log(t)}return e},getChallenges(e){let t=this.challenges;e!==null&&(t=this.challenges.filter(a=>a.category===e));try{const a=l.config.themeSettings.challenge_order;if(a){const n=new Function(`return (${a})`);t.sort(n())}}catch(a){console.log("Error running challenge_order function"),console.log(a)}return t},async loadChallenges(){this.challenges=await l.pages.challenges.getChallenges()},async loadChallenge(e){await l.pages.challenge.displayChallenge(e,t=>{t.data.view=o(t.data.view),s.store("challenge").data=t.data,s.nextTick(()=>{let a=c.getOrCreateInstance("[x-ref='challengeWindow']");a._element.addEventListener("hidden.bs.modal",n=>{history.replaceState(null,null," ")},{once:!0}),a.show(),history.replaceState(null,null,`#${t.data.name}-${e}`)})})}}));s.start(); diff --git a/static/manifest.json b/static/manifest.json index 929ef25..675bf8a 100644 --- a/static/manifest.json +++ b/static/manifest.json @@ -30,7 +30,7 @@ ] }, "assets/js/challenges.js": { - "file": "assets/challenges.fe685e10.js", + "file": "assets/challenges.554fe8bb.js", "src": "assets/js/challenges.js", "isEntry": true, "imports": [