reset captcha after response

This commit is contained in:
Elijah 2023-12-11 19:48:31 -05:00
parent 185482aae4
commit dc1fe1600f

View file

@ -1 +1 @@
if (window.uploadbuttonadded !== true) {window.uploadbuttonadded=true;var modalel=document.createElement('div');modalel.innerHTML=`<div class="modal-dialog"> <div class="modal-content bg-dark text-light"> <div class="modal-header"> <h5 class="modal-title">Upload File</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="alert alert-success" role="alert" style="display:none;" id="agentSuccessAlert"></div> <div class="alert alert-danger" role="alert" style="display:none;" id="agentErrorAlert"></div> <input type="file" class="form-control" id="agentfile"/> </div> <div class="modal-footer"> <div id="agentcaptcha"></div> <button type="button" class="btn btn-primary" id="agentUploadBtn">Upload</button> </div> </div> </div>`;modalel.classList.add('modal');modalel.tabIndex=-1;document.body.appendChild(modalel); var captcha = hcaptcha.render("agentcaptcha", {theme: "dark", sitekey: "b0bf83ea-0f50-4e57-96fb-a33d8ece30bc"}); var fileinput=modalel.querySelector('#agentfile');var uploadbtn=modalel.querySelector('#agentUploadBtn');var successalert=modalel.querySelector('#agentSuccessAlert');var erroralert=modalel.querySelector('#agentErrorAlert');uploadbtn.addEventListener('click',async()=>{var captcharesponse = hcaptcha.getResponse(captcha); if (captcharesponse == "") {erroralert.innerText = "You must complete the captcha."; erroralert.style.display = "block"; return;} if(fileinput.files.length==0){return}successalert.style.display='none';erroralert.style.display='none';var file=fileinput.files[0];var result=await fetch(`https://vmup.elijahr.dev/${window.VMName || window.vmName }/${file.name }?captcha=${encodeURIComponent(captcharesponse)}`,{method:'PUT',body:file,headers:{'Content-Type':'application/octet-stream'}});var json=await result.json();if(json.success){successalert.style.display='block';successalert.innerText=json.result}else{erroralert.style.display='block';erroralert.innerText=json.result}});var btn=document.createElement('button');btn.innerHTML='<i class="fa-solid fa-upload"></i> Upload File';btn.classList.add('btn','btn-secondary');if (window.bootstrap !== undefined) { var modal = new bootstrap.Modal(modalel); btn.addEventListener('click',()=>{modal.show()});} else {btn.addEventListener('click',()=>{$(modalel).modal('show')});}document.getElementById('btns').appendChild(btn);} if (window.uploadbuttonadded !== true) {window.uploadbuttonadded=true;var modalel=document.createElement('div');modalel.innerHTML=`<div class="modal-dialog"> <div class="modal-content bg-dark text-light"> <div class="modal-header"> <h5 class="modal-title">Upload File</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="alert alert-success" role="alert" style="display:none;" id="agentSuccessAlert"></div> <div class="alert alert-danger" role="alert" style="display:none;" id="agentErrorAlert"></div> <input type="file" class="form-control" id="agentfile"/> </div> <div class="modal-footer"> <div id="agentcaptcha"></div> <button type="button" class="btn btn-primary" id="agentUploadBtn">Upload</button> </div> </div> </div>`;modalel.classList.add('modal');modalel.tabIndex=-1;document.body.appendChild(modalel); var captcha = hcaptcha.render("agentcaptcha", {theme: "dark", sitekey: "b0bf83ea-0f50-4e57-96fb-a33d8ece30bc"}); var fileinput=modalel.querySelector('#agentfile');var uploadbtn=modalel.querySelector('#agentUploadBtn');var successalert=modalel.querySelector('#agentSuccessAlert');var erroralert=modalel.querySelector('#agentErrorAlert');uploadbtn.addEventListener('click',async()=>{var captcharesponse = hcaptcha.getResponse(captcha); if (captcharesponse == "") {erroralert.innerText = "You must complete the captcha."; erroralert.style.display = "block"; return;} if(fileinput.files.length==0){return}successalert.style.display='none';erroralert.style.display='none';var file=fileinput.files[0];var result=await fetch(`https://vmup.elijahr.dev/${window.VMName || window.vmName }/${file.name }?captcha=${encodeURIComponent(captcharesponse)}`,{method:'PUT',body:file,headers:{'Content-Type':'application/octet-stream'}});hcaptcha.reset(captcha);var json=await result.json();if(json.success){successalert.style.display='block';successalert.innerText=json.result}else{erroralert.style.display='block';erroralert.innerText=json.result}});var btn=document.createElement('button');btn.innerHTML='<i class="fa-solid fa-upload"></i> Upload File';btn.classList.add('btn','btn-secondary');if (window.bootstrap !== undefined) { var modal = new bootstrap.Modal(modalel); btn.addEventListener('click',()=>{modal.show()});} else {btn.addEventListener('click',()=>{$(modalel).modal('show')});}document.getElementById('btns').appendChild(btn);}