div.brdCmb, h1.pTtl { display: none; } #apksContainer img { max-height: 32px; margin: 0px 3px; } Add New Mod to the Database Add Versions Lists of all apks added in the database App Icon Upload App Name App Signature Publisher Requirements Category Size Downloads Blog Post ID Description Update Download Counts Add Mod Clear Delete Mod let appName = ''; let appSignature = ''; let inputPublisher = ''; let inputAppRequirements = ''; let inputAppCategory = ''; let inputSize = ''; let blogPostID = ''; let inputDescription = ''; let appIcon = ''; let downloads = ''; let isUpdating = false; const db = 'https://ptc-database-default-rtdb.firebaseio.com/mods'; window.submit = async() => {}; window.addEventListener('load', async() => { await initFunctions(['ModalCreator', 'FirebaseModule', 'ImgurJS', 'supabase']); 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('clear').addEventListener('click', () => { document.getElementById('uploadForm').reset(); document.getElementById('submit').innerHTML = `<i class="upload icon"></i>Add Mod`; document.getElementById('profile_img').src = ''; isUpdating = false; }); (async() => { // retrieve all the icons in the firebase database of all the apks! const db = 'https://ptc-database-default-rtdb.firebaseio.com/mods'; let data = await FirebaseModule.fetchJSON(`${db}.json`); if (!data) { document.getElementById('profile_img').src = ''; document.getElementById('apksContainer').classList.remove('loader'); return; } let keys = Object.keys(data); keys.forEach((item) => { let img = document.createElement('img'); img.src = data[item].icon; img.style.cursor = 'pointer'; document.getElementById('apksContainer').appendChild(img); img.addEventListener('click', async() => { let temp_json = await FirebaseModule.fetchJSON(`${db}/${item}.json`); isUpdating = true; document.getElementById('inputAppName').value = temp_json.name; document.getElementById('inputAppSignature').value = atob(item); document.getElementById('inputPublisher').value = temp_json.publisher; document.getElementById('inputAppRequirements').value = temp_json.requirement; document.getElementById('inputAppCategory').value = temp_json.category; document.getElementById('inputSize').value = temp_json.size; document.getElementById('inputBlogPostID').value = temp_json.blogPostID; document.getElementById('profile_img').src = temp_json.icon; document.getElementById('downloads').value = temp_json.downloads; document.getElementById('inputDescription').value = temp_json.description; appSignature = atob(item); document.getElementById('submit').innerHTML = `<i class="pencil alternate icon"></i>Update Mod`; }); }); // deleting the mod document.getElementById('deleteMod').addEventListener('click', async() => { if (window.confirm("Do you really want to delete this mod? It will wipe out all of its versions!") && window.confirm("Are you really sure you want to delete this mod record and its versions???")) { let signature = document.getElementById('inputAppSignature').value; const db = 'https://ptc-database-default-rtdb.firebaseio.com/mods'; const path = `${db}/${btoa(signature)}.json`; let { error } = await FirebaseModule.fetchJSON(path); if (error) { window.alert("You are deleting invalid path!"); return; } await FirebaseModule.patch(path, 'null'); window.alert(`${signature} has been deleted from database!`); window.location.reload(); } }); document.getElementById('apksContainer').classList.remove('loader'); })(); document.querySelector('#uploadBtn').addEventListener('click', () => { document.querySelector('#file_attachments').click(); }, false); ImgurJS.uploadImgUr('file_attachments', 'profile_img', () => { 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); submit = async() => { let allInputs = document.querySelectorAll('#uploadForm input'); appName = allInputs[1].value; appSignature = allInputs[2].value; inputPublisher = allInputs[3].value; inputAppRequirements = allInputs[4].value; inputAppCategory = allInputs[5].value; inputSize = allInputs[6].value; downloads = allInputs[7].value; blogPostID = allInputs[8].value; inputDescription = document.querySelector('#inputDescription').value; document.getElementById('submit').classList.add('loading'); if (!document.getElementById('profile_img').src) { window.alert(`Please upload some icon for the game. Thank you!`); return; } appIcon = document.getElementById('profile_img').src; let apk_data = await FirebaseModule.fetchJSON(`${db}/${btoa(appSignature)}.json`); if (apk_data && !isUpdating) { ModalCreator.pop( `${new Date().getTime()}`, `<i class="exclamation circle large middle aligned icon"></i> Signature name is already Exists!`, `${appName} is already in the database.`, `exclamation circle large middle aligned icon`, `Reload`, `${window.location.href}`, `` ); document.getElementById('uploadForm').reset(); return; } let json_data; if (isUpdating && !document.getElementById('inputUpdateDLCount').checked) // when updating the record, download count will not be changed... json_data = { name: appName, icon: appIcon, publisher: inputPublisher, requirement: inputAppRequirements, category: inputAppCategory, size: inputSize, blogPostID: blogPostID, description: inputDescription } else json_data = { name: appName, icon: appIcon, publisher: inputPublisher, requirement: inputAppRequirements, category: inputAppCategory, size: inputSize, downloads: parseInt(downloads), blogPostID: blogPostID, description: inputDescription } json_data = JSON.stringify(json_data); await FirebaseModule.patch(`${db}/${btoa(appSignature)}.json`, `${json_data}`); document.getElementById('uploadForm').reset(); document.getElementById('submit').classList.remove('loading'); ModalCreator.pop( `appModalID`, `<i class="check circle large middle aligned icon"></i> ${appName} is added/edited in the database successfully!`, `You have successfully added/updated the mod in the database.`, `check circle large middle aligned icon`, `Reload Page`, `${window.location.href}`, `` ); } }, false);