@@ -74,6 +74,30 @@ <h1>Global Wiki</h1>
74
74
window . location . href = `https://github.com/login/oauth/authorize?client_id=${ clientId } &redirect_uri=${ redirectUri } &scope=repo` ;
75
75
}
76
76
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
+
77
101
async function fetchWiki ( ) {
78
102
try {
79
103
const response = await fetch ( `${ GITHUB_API_URL } /repos/${ REPO } /issues` , {
@@ -137,51 +161,7 @@ <h1>Global Wiki</h1>
137
161
}
138
162
}
139
163
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 ( ) ;
185
165
</ script >
186
166
</ body >
187
167
</ html >
0 commit comments