feat(auth): clarify login identity and speed up mobile entry

This commit is contained in:
xsl
2026-10-12 11:01:49 +08:00
parent 85790ef985
commit d2931a41e4
28 changed files with 1903 additions and 1046 deletions
+9 -1
View File
@@ -5,11 +5,19 @@ window.AccountClient = (function () {
function read(name) { try { return localStorage.getItem(name || key); } catch (_) { return null; } }
function rememberKind() { try { if (user) localStorage.setItem(kindKey, user.kind); } catch (_) {} }
function request(url, data) {
var controller = new AbortController();
// Bound only authentication waits. Full report snapshots contain photos and
// must retain their existing download budget on a slow mobile connection.
var timer = url.indexOf('api/auth/') === 0 ? setTimeout(function () { controller.abort(); }, 12000) : null;
return fetch(url, { credentials: 'same-origin', method: data ? 'POST' : 'GET',
signal: controller.signal,
headers: data ? { 'Content-Type': 'application/json' } : {},
body: data ? JSON.stringify(data) : undefined }).then(function (r) {
return r.json().then(function (v) { if (!r.ok || !v.ok) throw new Error(v.message || '请求失败'); return v; });
});
}).catch(function (error) {
if (error.name === 'AbortError') throw new Error('网络响应超时,请检查网络后重试');
throw error;
}).finally(function () { clearTimeout(timer); });
}
function browser(consent) {
return request('api/auth/browser', { consent: consent, token: read() }).then(function (v) {