SleePy Public Git Projects
Repositories
Main Site
GitHub Profile
smf_package_parser
Code
Commits
Branches
Tags
Search
Tree:
b63f61b
Branches
Tags
master
smf_package_parser
index.html
Add some future logic for getting release files from GitHub
jdarwood007
commited
b63f61b
at 2023-07-11 19:27:56
index.html
Blame
History
Raw
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>SMF Package Parser</title> <meta name="robots" content="noindex, nofollow"> <meta name="googlebot" content="noindex, nofollow"> <meta http-equiv='Content-Security-Policy' CONTENT="default-src 'self'; script-src 'self' 'unsafe-inline' cdn.jsdelivr.net esm.sh; style-src 'self' 'unsafe-inline' cdn.jsdelivr.net; img-src 'self' data: *; media-src 'self'; connect-src 'self' custom.simplemachines.org *.github.com github.com objects.githubusercontent.com; worker-src 'self' data: blob:;">` <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous"> <link rel="modulepreload" crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"> <link rel="modulepreload" crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/jszip-utils@0.1.0/dist/jszip-utils.min.js"> <link rel="modulepreload" crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js"> <link rel="modulepreload" crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/compare-versions@6.0.0-rc.1/lib/umd/index.min.js"> <link rel="modulepreload" crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/js-untar@2.0.0/build/dist/untar.min.js"> <link rel="modulepreload" crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/pako@2.1.0/+esm"> <link rel="modulepreload" crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/js-bbcode-parser@4.0.0/src/simple.min.js"> <link rel="modulepreload" href="./Parser.js"> <link rel="modulepreload" href="./languages/en-us.js"> <style> pre {tab-size: 4;} </style> </head> <body> <main class="container"> <header class="d-flex flex-wrap justify-content-center py-3 mb-4 border-bottom"> <form id="myform" class="me-md-auto"> <input id="myfile" name="files[]" multiple="" type="file" class="form-control" /> <input id="file" name="file" type="text" class="form-control" hidden /> </form> <a href="#" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-body-emphasis text-decoration-none"> <span class="fs-4" id="packageName">Package Parser</span> </a> <form> <select id="smfVersions" class="form-select"> <optgroup id="preferedVersions" label="Prefered SMF Versions"></optgroup> <optgroup id="otherVersions" label="Other SMF Versions"></optgroup> </select> </form> </header> <div id="errorContainer" class="alert alert-danger" role="alert" hidden></div> <div id="instructionsContainer" hidden class="container"> </div> <div id="templateContainer"> <div id="templateReadme" class="container" hidden> <div class="d-flex flex-row"> <h2 class="p-2">{TITLE}</h2> <div class="p-2"><button type="button" class="btn" aria-label="Close"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-expand" viewBox="0 0 16 16"> <path fill-rule="evenodd" d="M3.646 9.146a.5.5 0 0 1 .708 0L8 12.793l3.646-3.647a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 0-.708zm0-2.292a.5.5 0 0 0 .708 0L8 3.207l3.646 3.647a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 0 0 0 .708z"/> </svg> </button></div> </div> <div id="collapseReadme" class="accordion-collapse collapse show" data-bs-parent=""> <div class="accordion-body bg-primary-subtle p-2 border">{CONTENT}</div> </div> <hr> </div> <div id="ciplboard" hidden> </div> <div id="templateOperationsTitle" class="container mt-3" hidden> <h3>{TITLE}</h3> <div class="alert alert-warning" role="alert" hidden></div> </div> <div id="templateOperations" class="container mb-3" hidden> <div class="alert alert-warning" role="alert" hidden></div> <div class="alert alert-info" role="alert" hidden></div> <div class="searchContainer d-flex"> <h5 class="titleSearch d-inline fs-4"></h5> <button class="operationSearchCopy d-inline btn pt-0"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clipboard" viewBox="0 0 16 16"> <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/> <path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/> </svg> </button> </div> <div class="operationSearch highlight text-bg-light p-3 pb-1 ms-3 border"> <pre></pre> </div> <div class="addContainer d-flex"> <h5 class="titleAdd d-inline fs-4"></h5> <button class="operationAddCopy d-inline btn pt-0"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clipboard" viewBox="0 0 16 16"> <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/> <path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/> </svg> </button> </div> <div class="operationAdd highlight text-bg-light p-3 pb-1 ms-3 border"> <pre></pre> </div> </div> <div id="templateHooks" class="container" hidden> <table class="table table-sm table-striped"> <thead class="table-dark"> <th>{TITLE}</th> </thead> <tbody> </tbody> </table> <hr> </div> <div id="templateCode" class="container" hidden> <table class="table table-sm table-striped"> <thead class="table-dark"> <th colspan="2">{TITLE}</th> </thead> <tbody> </tbody> </table> <hr> </div> <div id="templateFileOperations" class="container" hidden> <table class="table table-sm table-striped"> <thead class="table-dark"> <th>{TITLE}</th> </thead> <tbody> </tbody> </table> <hr> </div> <div id="templateCredits" class="container" hidden> <table class="table table-sm table-striped"> <thead class="table-dark"> <th>{TITLE}</th> </thead> <tbody> </tbody> </table> <hr> </div> </div> </main> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jszip-utils@0.1.0/dist/jszip-utils.min.js" crossorigin="anonymous"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js" crossorigin="anonymous"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/compare-versions@6.0.0-rc.1/lib/umd/index.min.js" crossorigin="anonymous"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/js-untar@2.0.0/build/dist/untar.min.js" crossorigin="anonymous"></script> <script type="module"> import pako from 'https://cdn.jsdelivr.net/npm/pako@2.1.0/+esm' window.pako = pako; </script> <script type="module"> import bbCodeParser from 'https://cdn.jsdelivr.net/npm/js-bbcode-parser@4.0.0/src/simple.min.js'; window.bbcParser = bbCodeParser; </script> <script type="module"> import { Octokit } from 'https://cdn.jsdelivr.net/npm/@octokit/core@5.0.0/+esm'; window.octokit = new Octokit({}); </script> <script type="text/javascript" src="./Parser.js"></script> <script type="text/javascript" src="./languages/en-us.js"></script> <script type="text/javascript"> const SmfVersionApiURL = 'https://custom.simplemachines.org/api.php?action=smf;sa=versions'; let FileName = ''; // Check if we have another language to support. const language = window.navigator.language.toLowerCase(); const supportedLanguages = []; // ['en-us'] if (supportedLanguages.includes(language)) { const i18n = document.createElement('script'); i18n.src = './languages/' + language + '.js'; document.getElementsByTagName('head')[0].appendChild(i18n); } // Wait for everything to load, then add a listener on attaching files. window.addEventListener('load', async (e) => { // Setup the BBC Codes for the parser. await setBBCodes(); // If we have a file we are defaulting to/passing in if (FileName != '') runParser(FileName); document.getElementById('myfile').addEventListener('change', uploadFileToJS); }); document.getElementById('file').addEventListener('change', async function(){ const FileName = document.getElementById('file').value; const repoMatch = /https:\/\/github.com\/([^/]+)\/([^/$]+)\/?$/i; const found = FileName.match(repoMatch); if (typeof found === 'undefined' || found === null || !("1" in found) || !("2" in found)) { console.debug('Unable to match USERNAME and REPO from requested URL'); runParser(FileName); return; } const OWNER = found[1]; const REPO = found[2]; const release = await octokit.request('GET /repos/' + OWNER + '/' + REPO + '/releases/latest', { owner: OWNER, repo: REPO, }); if (release.data.id === null) { console.debug('Unable to find a release ID'); return; } const assets = await octokit.request('GET /repos/' + OWNER + '/' + REPO + '/releases/' + release.data.id + 'latest', { owner: OWNER, repo: REPO, release_id: release.data.id }); if (assets.data.assets === null || assets.data.assets.length == 0) { console.debug('Unable to find any assets'); return; } let asset = null; assets.data.assets.forEach(function(data, index, theArray) { if (asset === null && (data.name.indexOf("tgz") > 0 || data.name.indexOf("tar.gz") > 0 || data.name.indexOf("zip") > 0)) { asset = data; return; } }); const fileData = await octokit.request('GET /repos/' + OWNER + '/' + REPO + '/releases/assets/' + asset.id, { owner: OWNER, repo: REPO, asset_id: asset.id, headers: { 'Accept': 'application/octet-stream' } }); console.log(fileData); // !! TODO File is a blob, can we just send to runParser? }); </script> </body> </html>