@@ -189,23 +189,46 @@ function getReleases() {
189189}
190190
191191function getDevCommits() {
192- fetch (' https://api.github.com/repos/Soulter/AstrBot/commits' , {
193- headers: {
194- ' Host' : ' api.github.com' ,
195- ' Referer' : ' https://api.github.com'
196- }
197- })
192+ let proxy = localStorage .getItem (' selectedGitHubProxy' ) || ' ' ;
193+ const originalUrl = " https://api.github.com/repos/Soulter/AstrBot/commits" ;
194+ let commits_url = originalUrl ;
195+ if (proxy !== ' ' ) {
196+ proxy = proxy .endsWith (' /' ) ? proxy : proxy + ' /' ;
197+ commits_url = proxy + originalUrl ;
198+ }
199+
200+ function fetchCommits(url : string , onError ? : () => void ) {
201+ fetch (url , {
202+ headers: {
203+ ' Host' : ' api.github.com' ,
204+ ' Referer' : ' https://api.github.com'
205+ }
206+ })
198207 .then (response => response .json ())
199208 .then (data => {
200- devCommits .value = data .map ((commit : any ) => ({
201- sha: commit .sha ,
202- date: new Date (commit .commit .author .date ).toLocaleString (),
203- message: commit .commit .message
204- }));
209+ devCommits .value = Array .isArray (data )
210+ ? data .map ((commit : any ) => ({
211+ sha: commit .sha ,
212+ date: new Date (commit .commit .author .date ).toLocaleString (),
213+ message: commit .commit .message
214+ }))
215+ : [];
205216 })
206217 .catch (err => {
207- console .log (err );
218+ if (onError ) {
219+ onError ();
220+ } else {
221+ console .log (' 获取开发版提交信息失败:' , err );
222+ }
208223 });
224+ }
225+
226+ fetchCommits (commits_url , () => {
227+ if (proxy !== ' ' && commits_url !== originalUrl ) {
228+ console .log (' 使用代理请求失败,尝试直接请求' );
229+ fetchCommits (originalUrl );
230+ }
231+ });
209232}
210233
211234function switchVersion(version : string ) {
0 commit comments