Skip to content

Commit 462f05b

Browse files
authored
Update Wiki.html
1 parent aa05dfb commit 462f05b

File tree

1 file changed

+25
-45
lines changed

1 file changed

+25
-45
lines changed

Wiki/Wiki.html

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ <h1>Global Wiki</h1>
7474
window.location.href = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&scope=repo`;
7575
}
7676

77+
async function handleRedirect() {
78+
const code = new URLSearchParams(window.location.search).get('code');
79+
if (code) {
80+
try {
81+
const response = await fetch('/exchange-code', {
82+
method: 'POST',
83+
headers: {
84+
'Content-Type': 'application/json'
85+
},
86+
body: JSON.stringify({ code })
87+
});
88+
const data = await response.json();
89+
if (data.access_token) {
90+
accessToken = data.access_token;
91+
fetchWiki();
92+
} else {
93+
console.error('Failed to exchange code:', data);
94+
}
95+
} catch (error) {
96+
console.error('Error exchanging code:', error);
97+
}
98+
}
99+
}
100+
77101
async function fetchWiki() {
78102
try {
79103
const response = await fetch(`${GITHUB_API_URL}/repos/${REPO}/issues`, {
@@ -137,51 +161,7 @@ <h1>Global Wiki</h1>
137161
}
138162
}
139163

140-
async function editWikiEntry(number) {
141-
const newContent = prompt('Enter new content:');
142-
if (!newContent) return;
143-
try {
144-
const response = await fetch(`${GITHUB_API_URL}/repos/${REPO}/issues/${number}`, {
145-
method: 'PATCH',
146-
headers: {
147-
'Authorization': `Bearer ${accessToken}`,
148-
'Content-Type': 'application/json'
149-
},
150-
body: JSON.stringify({
151-
body: newContent
152-
})
153-
});
154-
const data = await response.json();
155-
if (response.ok) {
156-
fetchWiki();
157-
} else {
158-
console.error('Failed to edit wiki entry:', data);
159-
}
160-
} catch (error) {
161-
console.error('Error editing wiki entry:', error);
162-
}
163-
}
164-
165-
async function deleteWikiEntry(number) {
166-
if (!confirm('Are you sure you want to delete this entry?')) return;
167-
try {
168-
const response = await fetch(`${GITHUB_API_URL}/repos/${REPO}/issues/${number}`, {
169-
method: 'DELETE',
170-
headers: {
171-
'Authorization': `Bearer ${accessToken}`
172-
}
173-
});
174-
if (response.ok) {
175-
fetchWiki();
176-
} else {
177-
console.error('Failed to delete wiki entry:', response.statusText);
178-
}
179-
} catch (error) {
180-
console.error('Error deleting wiki entry:', error);
181-
}
182-
}
183-
184-
fetchWiki();
164+
handleRedirect();
185165
</script>
186166
</body>
187167
</html>

0 commit comments

Comments
 (0)