Upload index.html with huggingface_hub
Browse files- index.html +11 -4
index.html
CHANGED
|
@@ -2018,17 +2018,24 @@
|
|
| 2018 |
updateAuthUI(null);
|
| 2019 |
}
|
| 2020 |
|
|
|
|
|
|
|
| 2021 |
function isHfTokenExpired(oauthResult) {
|
| 2022 |
if (!oauthResult?.accessTokenExpiresAt) return false;
|
| 2023 |
-
|
| 2024 |
-
return new Date(oauthResult.accessTokenExpiresAt).getTime() - 60_000 < Date.now();
|
| 2025 |
}
|
| 2026 |
|
| 2027 |
function scheduleHfExpiry(oauthResult) {
|
| 2028 |
if (_hfExpiryTimer) clearTimeout(_hfExpiryTimer);
|
| 2029 |
if (!oauthResult?.accessTokenExpiresAt) return;
|
| 2030 |
-
const
|
| 2031 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2032 |
_hfExpiryTimer = setTimeout(() => {
|
| 2033 |
console.warn('HF OAuth token expired, signing out automatically.');
|
| 2034 |
hfSignOut();
|
|
|
|
| 2018 |
updateAuthUI(null);
|
| 2019 |
}
|
| 2020 |
|
| 2021 |
+
const HF_EXPIRY_BUFFER_MS = 5 * 60_000; // 5 minutes
|
| 2022 |
+
|
| 2023 |
function isHfTokenExpired(oauthResult) {
|
| 2024 |
if (!oauthResult?.accessTokenExpiresAt) return false;
|
| 2025 |
+
return new Date(oauthResult.accessTokenExpiresAt).getTime() - HF_EXPIRY_BUFFER_MS < Date.now();
|
|
|
|
| 2026 |
}
|
| 2027 |
|
| 2028 |
function scheduleHfExpiry(oauthResult) {
|
| 2029 |
if (_hfExpiryTimer) clearTimeout(_hfExpiryTimer);
|
| 2030 |
if (!oauthResult?.accessTokenExpiresAt) return;
|
| 2031 |
+
const expiresAt = new Date(oauthResult.accessTokenExpiresAt).getTime();
|
| 2032 |
+
const ms = expiresAt - HF_EXPIRY_BUFFER_MS - Date.now();
|
| 2033 |
+
if (ms <= 0) {
|
| 2034 |
+
// Already expired or about to — sign out now
|
| 2035 |
+
hfSignOut();
|
| 2036 |
+
return;
|
| 2037 |
+
}
|
| 2038 |
+
console.log(`HF token expires at ${new Date(expiresAt).toISOString()}, auto-signout in ${Math.round(ms / 60_000)}m`);
|
| 2039 |
_hfExpiryTimer = setTimeout(() => {
|
| 2040 |
console.warn('HF OAuth token expired, signing out automatically.');
|
| 2041 |
hfSignOut();
|