删除后端AI助手服务文件及对应的/api/ai-assistant接口路由,移除前端ai-assistant.js脚本及所有HTML页面中的脚本引用,清理静态资源版本配置文件里的相关配置项,同时更新bump-web-asset-version.js脚本的示例命令与错误提示文本。
89 lines
2.7 KiB
JavaScript
89 lines
2.7 KiB
JavaScript
/*
|
|
* @Author: HenryDu8133 813367384@qq.com
|
|
* @Date: 2026-06-19 17:30:23
|
|
* @LastEditors: HenryDu8133 813367384@qq.com
|
|
* @LastEditTime: 2026-06-19 17:35:05
|
|
* @FilePath: \TicketMachine\web\public-status.js
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
*/
|
|
(() => {
|
|
const STATUS_CLASSES = ['is-checking', 'is-online', 'is-offline'];
|
|
const ENDPOINTS = [
|
|
'/api/public/config',
|
|
'/api/public/popular',
|
|
'/api/assets/manifest'
|
|
];
|
|
|
|
const roots = () => Array.from(document.querySelectorAll('[data-server-status-root]'));
|
|
|
|
const setStatus = (state, text) => {
|
|
roots().forEach((root) => {
|
|
root.classList.remove(...STATUS_CLASSES);
|
|
root.classList.add(`is-${state}`);
|
|
|
|
const value = root.querySelector('[data-server-status-value]');
|
|
if (value) value.textContent = text;
|
|
});
|
|
};
|
|
|
|
const probe = async () => {
|
|
for (const endpoint of ENDPOINTS) {
|
|
const separator = endpoint.includes('?') ? '&' : '?';
|
|
const controller = new AbortController();
|
|
const timeoutId = window.setTimeout(() => controller.abort(), 3500);
|
|
|
|
try {
|
|
const response = await fetch(`${endpoint}${separator}_=${Date.now()}`, {
|
|
cache: 'no-store',
|
|
signal: controller.signal
|
|
});
|
|
|
|
if (response.ok) {
|
|
window.clearTimeout(timeoutId);
|
|
return true;
|
|
}
|
|
} catch (error) {
|
|
void error;
|
|
}
|
|
|
|
window.clearTimeout(timeoutId);
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
const refresh = async () => {
|
|
if (!roots().length) return;
|
|
|
|
if (navigator.onLine === false) {
|
|
setStatus('offline', '网络离线');
|
|
return;
|
|
}
|
|
|
|
setStatus('checking', '检测中');
|
|
const online = await probe();
|
|
setStatus(online ? 'online' : 'offline', online ? '连接正常' : '连接异常');
|
|
};
|
|
|
|
let timerId = null;
|
|
|
|
const init = () => {
|
|
if (!roots().length || timerId !== null) return;
|
|
|
|
refresh();
|
|
timerId = window.setInterval(refresh, 30000);
|
|
|
|
window.addEventListener('online', refresh);
|
|
window.addEventListener('offline', () => setStatus('offline', '网络离线'));
|
|
document.addEventListener('visibilitychange', () => {
|
|
if (!document.hidden) refresh();
|
|
});
|
|
};
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init, { once: true });
|
|
} else {
|
|
init();
|
|
}
|
|
})();
|