From 6649b31e17e9925b90d51e2a485a9371eb0ec342 Mon Sep 17 00:00:00 2001 From: qing <1776177662@qq.com> Date: Thu, 30 Jul 2026 12:25:11 +0800 Subject: [PATCH] feat(static): add frontend token auto-refresh for dnfs page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New token_manager.js: silent refresh timer (80% lifetime) + global fetch 401 interceptor with one-shot retry. - dnfs.py /whoami now returns iat, created_at, keep_time for expiry estimation. - Dnfs.html loads token_manager.js before dnfs.js (zero change to dnfs.js). - Graceful fallback: stale tokens without new fields, refresh failures, and /refresh_token 401 itself all degrade to the existing 401→login flow. --- dnfs/dnfs.py | 12 ++- static/public/dnfs.html | 1 + static/public/js/token_manager.js | 118 ++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 static/public/js/token_manager.js diff --git a/dnfs/dnfs.py b/dnfs/dnfs.py index 60c49c8..c06f7c4 100755 --- a/dnfs/dnfs.py +++ b/dnfs/dnfs.py @@ -288,11 +288,19 @@ def whoami(): if info is None: return jsonify({'login': False}), 200 - return jsonify({ + resp = { 'login': True, 'user': info.get('user'), 'is_admin': bool(info.get('is_admin')) - }), 200 + } + # 附加 Token 生命周期信息,供前端 Token 管理器估算过期时间 + if info.get('iat'): + resp['iat'] = info['iat'] + if info.get('created_at'): + resp['created_at'] = info['created_at'] + if info.get('keep_time'): + resp['keep_time'] = info['keep_time'] + return jsonify(resp), 200 # eg: {"id": 1} diff --git a/static/public/dnfs.html b/static/public/dnfs.html index 31286b3..bc4c659 100644 --- a/static/public/dnfs.html +++ b/static/public/dnfs.html @@ -26,6 +26,7 @@ +