1 line
2 KiB
JavaScript
1 line
2 KiB
JavaScript
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"> <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 fileinput=modalel.querySelector('#agentfile');var uploadbtn=modalel.querySelector('#agentUploadBtn');var successalert=modalel.querySelector('#agentSuccessAlert');var erroralert=modalel.querySelector('#agentErrorAlert');uploadbtn.addEventListener('click',async()=>{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 }`,{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);}
|