<style> div.brdCmb, h1.pTtl { display: none; } #imagesattachments img { max-height: 64px } </style> <div class="ui container" style="width: 600px;"> <div class="ui message"> <h2 class='ui big black label'>Add New Version to the Database</h2> <br> <a class="ui button" href="https://storehaccounts.blogspot.com/p/mods-adder.html"> <i class="folder icon"></i> Add More Mods </a> <br><br> Select a Mod you are about to create an update <div id="mods_dropdown" class="ui fluid loading selection dropdown"> <input required id="inputMod" type="hidden" name="user" /> <i class="dropdown icon"></i> <div class="default text">Select Mod</div> <div id="mod_selection" class="menu"></div> </div> <div id="update_dropdown" class="ui fluid loading selection dropdown"> <input required id="inputVersion" type="hidden" name="user" /> <i class="dropdown icon"></i> <div class="default text">View Previous Vesions</div> <div id="update_selection" class="menu"></div> </div> </div> <br /> <form id="uploadForm" action='javascript:submitForm();' style='display: none;'> <span class="ui red label">App version <span class='ui blue label'>Format must be 14-3-2</span> Separated by hyphens.</span> <div class="ui focus fluid big input"> <input id='inputAppVersion' required type="text" placeholder="App version" /> </div> <br /> <span class="ui red label">App Update Logs</span> <div class="ui focus fluid big input"> <input id='inputAppUpdateLogs' required type="text" placeholder="Added or Fixed some bugs such as that.." /> </div> <br /> <span class="ui red label">App Update Link</span> <div class="ui focus fluid big input"> <input type='url' id='inputAppUpdateLink' required placeholder="App Update Link" /> </div> <br /> <span class="ui red label">Mediafire Link</span> <div class="ui focus big fluid input"> <input type='url' id='inputMediafireLink' required placeholder="Mediafire Link" /> </div> <br /> <span class="ui red label">Image Attachments</span> <div id='imagesattachments'> </div> <div class="ui left aligned container"> <input style="display: none;" id="file_attachments" type="file" accept="image/png, image/gif, image/jpeg, image/bmp" placeholder="Change Profile Picture" /> <button id="uploadBtn" type="button" class="ui white mini button"> <i class="upload blue icon"></i>Upload </button> <button id="clearBtn" type="button" class="ui white mini button"> <i class="delete red icon"></i>Clear </button> </div> <div class="ui section divider"></div> <button type='submit' id='submit' class="ui green button"> <i class="upload icon"></i>Upload Version </button> <button type='button' id='deleteVersion' class="ui red button"> <i class="delete icon"></i>Delete Version </button> <button type='button' id='clearFields' class="ui white button"> <i class="edit outline orange icon"></i>Clear Fields </button> </form> </div> <script type="module"> const allValues = document.querySelectorAll('form#uploadForm input'); window.submitForm = () => { } window.addEventListener('load', async () => { const db = 'https://ptc-database-default-rtdb.firebaseio.com/mods'; await initFunctions(['ImgurJS', 'jQuery', '$().dropdown()', 'FirebaseModule']); $('#mods_dropdown') .dropdown({ maxSelections: 6 }); let auth = await supabase.auth.getUser(); if (!auth.data || auth.error) { window.alert("Invalid authorization!"); return; } auth = auth.data.user.id; if (auth != await FirebaseModule.fetchJSON('https://ptc-database-default-rtdb.firebaseio.com/admins/uid.json')) { window.alert("Invalid Authorization!"); return; } document.getElementById('mods_dropdown').classList.remove('loading'); (async () => { // retrieve all the mods informations in the firebase database of all the apks! // and add to the mods_dropdown let data = await FirebaseModule.fetchJSON(`${db}/.json`); if (!data) return; let keys = Object.keys(data); keys.forEach((item) => { if (item == "auth") return; let div = document.createElement('div'); div.setAttribute('class', 'item') div.setAttribute('data-value', atob(item)); div.innerHTML = `<img class="ui mini avatar image" src="${data[item].icon}">${data[item].name}`; document.getElementById('mod_selection').appendChild(div); }) })(); document.getElementById('clearBtn').addEventListener('click', () => { let choice = window.confirm("Do you want to clear images?"); if (choice) { document.getElementById('imagesattachments').innerHTML = ''; } }, false); document.getElementById('clearFields').addEventListener('click', () => { let choice = window.confirm("Do you want to clear everything?"); if (choice) { document.getElementById('uploadForm').reset(); document.getElementById('imagesattachments').innerHTML = ''; $('#update_dropdown').dropdown('clear', '', ''); } }, false); // InputMods let you select different mods document.getElementById('inputMod').addEventListener('change', async () => { document.getElementById('update_dropdown').classList.add('loading'); document.getElementById('uploadForm').reset(); $('#update_dropdown').dropdown('clear', '', ''); let value = document.getElementById('inputMod').value; let data = await FirebaseModule.fetchJSON(`${db}/${btoa(value)}.json`); if (data.hasOwnProperty('versions')) { data = data.versions; let keys = Object.keys(data); keys = keys.reverse(); (async () => { // retrieve all the versions // and add to the update_dropdown document.getElementById('update_selection').innerHTML = ''; document.getElementById('imagesattachments').innerHTML = ''; keys.forEach((item) => { if (item == "auth") return; let update_data = data[item]; let div = document.createElement('div'); div.setAttribute('class', 'item') div.setAttribute('data-value', btoa(JSON.stringify(data[item]))); div.innerHTML = `<img class="ui mini avatar image" src="${update_data.imgs[0]}">${item}`; document.getElementById('update_selection').appendChild(div); }); document.getElementById('update_dropdown').classList.remove('loading'); })(); } else { document.querySelector('form#uploadForm').reset(); } document.getElementById('uploadForm').style.display = 'block'; }); // when mod is selected, versions will be loaded... document.getElementById('inputVersion').addEventListener('change', async () => { document.getElementById('imagesattachments').innerHTML = ''; let data = document.getElementById('inputVersion').value; if(!data) return; let update_data = JSON.parse(atob(data)); document.getElementById('inputAppVersion').value = document.querySelector('#update_dropdown div.text').innerText; document.getElementById('inputAppUpdateLogs').value = update_data.logs; document.getElementById('inputAppUpdateLink').value = update_data.upd; document.getElementById('inputMediafireLink').value = update_data.dl; // building screenshots update_data.imgs.forEach(item => { if (item == "auth") return; let img = document.createElement('img'); img.src = item; document.getElementById('imagesattachments').appendChild(img); }); }); ImgurJS.uploadMultipleImgs('file_attachments', 'imagesattachments', () => { query('uploadBtn').classList.add('loading'); query('uploadBtn').classList.add('disabled'); }, () => { query('uploadBtn').classList.remove('loading'); query('uploadBtn').classList.remove('disabled'); query('uploadBtn').innerHTML = "<i class=\"upload icon\"></i>Upload"; }, false); document.getElementById('uploadBtn').addEventListener('click', () => { document.getElementById('file_attachments').click(); }); submitForm = async () => { // check all the values first document.getElementById('submit').classList.add('loading'); let app_signature = document.getElementById('inputMod').value; let ver_db = `${db}/${btoa(app_signature)}/versions.json`; let ver = allValues[0].value; let logs = allValues[1].value; let update_link = allValues[2].value; let med_link = allValues[3].value; let date = new Date().getTime(); let attachments = []; // check for attachments let imgs = document.querySelectorAll('#imagesattachments img'); if (imgs.length == 0) { window.alert("Please you need to upload screenshots!"); document.getElementById('submit').classList.remove('loading'); return; } imgs.forEach(item => { attachments.push(item.src); }); let check = await FirebaseModule.fetchJSON(`${db}/${btoa(app_signature)}/versions/${ver}.json`); if (check) { ModalCreator.popFunction( `${new Date().getTime()}`, `${ver} is already added for ${app_signature}`, `The version you are trying to add is already in the database! Version ${ver} is already stored in the database. <br/> <br/> Do you want to update this app?`, `check circle icon`, `Yes`, async () => { let data = { [ver]: { dl: med_link, date: date, upd: update_link, logs: logs, imgs: attachments, }, auth: auth } data = JSON.stringify(data); await FirebaseModule.patch(ver_db, data); document.getElementById('submit').classList.remove('loading'); document.getElementById('uploadForm').reset(); $('#update_dropdown').dropdown('clear', '', ''); }, `` ); document.getElementById('submit').classList.remove('loading'); document.getElementById('imagesattachments').innerHTML = ''; return; } let data = { [ver]: { dl: med_link, date: date, upd: update_link, logs: logs, imgs: attachments, }, auth: auth } data = JSON.stringify(data); console.log(data); await FirebaseModule.patch(ver_db, data); document.getElementById('submit').classList.remove('loading'); document.getElementById('imagesattachments').innerHTML = ''; window.location.reload(); } // Deleting a versionn! document.getElementById('deleteVersion').addEventListener('click', async () => { let confirm = window.confirm("Do you really want to delete this Update?"); let confirm2; if (confirm) confirm2 = window.confirm("This is irreversible! Do you want to continue?"); if (confirm && confirm2) { let version = document.querySelector('#update_dropdown div.text').innerText; let mod = document.getElementById('inputMod').value; await FirebaseModule.patch(`${db}/${btoa(mod)}/versions/${version}.json`, `null`); ModalCreator.popFunction( `${new Date().getTime()}`, `The record ${version} is successfully deleted!`, `The record you removed is successfully wiped out from the database. <br/>Note that you need to be careful in removing versions since this will affect the overall records of the database`, `check circle icon`, `Reload`, () => window.location.reload(), `` ); } else return; }, false); }, false); </script>