-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileUpload.html
99 lines (79 loc) · 3.82 KB
/
fileUpload.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ION-Lang Module Submission</title>
<link rel="stylesheet" href="css/fileUpload.css">
<link rel="icon" type="image/x-icon"
href="https://raw.githubusercontent.com/The-ION-Language/ION-Lang/main/assets/ION_LANG_LOGO.png">
<script>
let l;
async function findUsername() {
const t = document.querySelector('#username');
const r = await fetch(`https://api.github.com/users/${document.querySelector('#username').value}/repos`);
const container = document.createElement('div');
container.classList.add('container');
const selectMenu = document.createElement('select');
selectMenu.innerHTML = `<option value="" disabled selected>Select a repository</option>`;
selectMenu.className = 'repo-select';
selectMenu.id = 'repoSelect';
(await r.json()).forEach(repo => {
const option = document.createElement('option');
option.value = repo.contents_url.replace("{+path}", '');
option.textContent = repo.name;
selectMenu.appendChild(option);
});
container.appendChild(selectMenu);
t.replaceWith(container);
document.querySelector('button[type="submit"]').style.display = 'inline-block';
document.querySelector('#usernamelabel').remove();
}
const waitForChange = (e) => {
clearTimeout(l);
l = setTimeout(findUsername, 2000);
}
window.addEventListener('DOMContentLoaded', () => {
document.querySelector('#username').addEventListener('input', waitForChange);
document.getElementById('uploadForm').addEventListener('submit', async function (event) {
event.preventDefault();
const code = (new URLSearchParams(window.location.search)).get('code'),
repourl = `${document.querySelector('#repoSelect').value}bundleinfo.json`,
r = await fetch(repourl),
j = atob((await r.json()).content);
if (!j) return alert("CONFIG FILE NOT FOUND!");
const response = await fetch('/upload', {
method: 'POST',
headers: new Headers({
code,
repourl,
})
});
if (response.statusText !== 'OK') {
const txt = await response.text();
try {
const r = JSON.parse(txt);
return alert(`ERROR!!!\n${r.error}\n${r.error_description}`);
}
catch(err) {
return alert(response.statusText);
}
}
document.querySelector("#statusTitle").textContent = "Module Uploaded!";
const newHref = await response.text();
document.getElementById('uploadForm').innerHTML = `<p>uploaded module to <a href="${newHref}" target="_blank">${newHref}</a></p><br><button type="submit" onclick="window.location.href = '/'" class="btn">Home</button>`;
});
})
</script>
</head>
<body>
<div class="container">
<h1 id="statusTitle">Upload Your Module</h1>
<form id="uploadForm" action="/upload" method="post" enctype="multipart/form-data">
<label id="usernamelabel" for="username">Github Username</label><input type="text" id="username"
class="file-input" onKeyUp="waitForChange(Event)">
<button style="display: none;" type="submit" class="btn">Upload</button>
</form>
</div>
</body>
</html>