From 550bb2fd91ddfcf45c5a01a11b980b18a2524646 Mon Sep 17 00:00:00 2001 From: "xiaoqi.cxq" Date: Tue, 19 Sep 2023 09:29:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E9=A1=B5=E9=9D=A2=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/landing/share.html | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/static/landing/share.html b/static/landing/share.html index 511c1a88..ad8a22d2 100644 --- a/static/landing/share.html +++ b/static/landing/share.html @@ -99,11 +99,14 @@ } } } - let url = `https://gitee.com/api/v5/gists/${gistId}`; + const url = `https://gitee.com/api/v5/gists/${gistId}`; + let urlWithToken = url; + let withToken = false; if (accessToken) { - url = `${url}?access_token=${accessToken}`; + urlWithToken = `${url}?access_token=${accessToken}`; + withToken = true; } - xhr.open('GET', url); + xhr.open('GET', urlWithToken); xhr.onload = function() { if (xhr.status === 200) { const newdoc = document.implementation.createHTMLDocument(""); @@ -124,9 +127,17 @@ const rateLimit = xhr.responseText && xhr.responseText.indexOf('Rate Limit') >= 0; const appUri = `${window.location.protocol}//${window.location.host}/app`; document.getElementById('div_info').innerHTML = `${rateLimit ? "请求太过频繁" : "无权限访问"},请登录 主文档空间 后再刷新此页面!`; + } else if (xhr.status === 401) { + if (withToken) { + withToken = false; + xhr.open('GET', url); + } else { + console.error('An error occurred: ' + xhr.status); + document.getElementById('div_info').innerHTML = `分享内容获取失败或已失效!请登录 主文档空间 后再刷新此页面!`; + } } else { console.error('An error occurred: ' + xhr.status); - document.getElementById('div_info').innerHTML = '分享内容获取失败或已失效!'; + document.getElementById('div_info').innerHTML = `分享内容获取失败或已失效!请登录 主文档空间 后再刷新此页面!`; } }; xhr.send();