feat: 设置页(本地/线上OCR可配+一键测试) + 右上角开源地址/版本/通知 + CardAuth 授权接入(v1.2.0)
- 后端: utils/settings.js(settings.json持久化)、utils/ocr.js(本地tesseract+线上视觉模型,失败回退本地)、 routes/settings.js(GET/PUT/test-ocr,密钥掩码)、utils/hub.js(开机查+6h版本比对+30min心跳+60s公告,失败开放, 机器码仅存服务端)、routes/hub.js(免登录 /api/hub)、server.js 启动拉起 hub - 前端: SettingsModal(左菜单右参数,线上OCR默认 ai.88531.cn/v1 + mimo-v2.6-flash)、useHub 60s轮询、 Header 右上角 开源地址/通知铃铛(红点+公告+在线人数)/设置/版本徽标 v1.2.0、搜索框提示改「支持 OCR 图内文字」 - CardAuth: HUB_API_KEY 经 compose 插值 + .env(不入库), 项目「FlyPic 素材库」project_id=15 - 修复: 前端端点 /api 重复拼接、设置响应结构对齐、测试识别结果解析、版本徽标 v 前缀
This commit is contained in:
1 parent
ffb47a0f81
commit
50c53a5e21
18 files changed
+961
-15
No files matched your search
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* hub API:版本检查 / 公告 / 在线人数(后端代理授权系统,前端轮询)
|
||||
* 注意:client 的 API_BASE 已含 /api,这里只写 /hub 段
|
||||
*/
|
||||
import { api } from '../client';
|
||||
|
||||
export function getHub() {
|
||||
return api.get('/hub');
|
||||
}
|
||||
|
||||
export const hubAPI = { getHub };
|
||||
export default hubAPI;
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 设置 API(OCR 等)
|
||||
* 注意:client 的 API_BASE 已含 /api,这里只写 /settings 段
|
||||
*/
|
||||
import { api } from '../client';
|
||||
|
||||
export function getSettings() {
|
||||
return api.get('/settings');
|
||||
}
|
||||
|
||||
export function updateSettings(data) {
|
||||
return api.put('/settings', data);
|
||||
}
|
||||
|
||||
export function testOcr(data) {
|
||||
return api.post('/settings/test-ocr', data);
|
||||
}
|
||||
|
||||
export const settingsAPI = { getSettings, updateSettings, testOcr };
|
||||
export default settingsAPI;
|
||||
@@ -6,11 +6,14 @@ import * as library from './endpoints/library';
|
||||
import * as image from './endpoints/image';
|
||||
import * as scan from './endpoints/scan';
|
||||
import { fileAPI } from './file';
|
||||
import { settingsAPI } from './endpoints/settings';
|
||||
import { hubAPI } from './endpoints/hub';
|
||||
|
||||
export const libraryAPI = library;
|
||||
export const imageAPI = image;
|
||||
export const scanAPI = scan;
|
||||
export { fileAPI };
|
||||
export { settingsAPI, hubAPI };
|
||||
|
||||
export { api, APIError } from './client';
|
||||
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import { useState, useEffect, useMemo, useRef } from 'react';
|
||||
import { Sun, Moon, Search, Filter, Sliders, RefreshCw, Star } from 'lucide-react';
|
||||
import { Sun, Moon, Search, Filter, Sliders, RefreshCw, Star, Bell, Github, Settings, ExternalLink } from 'lucide-react';
|
||||
import { useLibraryStore } from '../stores/useLibraryStore';
|
||||
import { useImageStore } from '../stores/useImageStore';
|
||||
import { useUIStore } from '../stores/useUIStore';
|
||||
import { useScanStore } from '../stores/useScanStore';
|
||||
import { useTheme } from '../hooks/useTheme';
|
||||
import { useHub } from '../hooks/useHub';
|
||||
import { libraryAPI, scanAPI, watchAPI } from '../api';
|
||||
import SettingsModal from './SettingsModal';
|
||||
import { createLogger } from '../utils/logger';
|
||||
|
||||
const logger = createLogger('Header');
|
||||
|
||||
const REPO_URL = 'https://gitea.88531.cn/jinghui/flypic';
|
||||
|
||||
function Header() {
|
||||
const { currentLibraryId } = useLibraryStore();
|
||||
const { searchKeywords, originalImages, selectedFolder, setSearchKeywords, filters, setFilters, resetFilters } = useImageStore();
|
||||
@@ -21,7 +25,14 @@ function Header() {
|
||||
const [isMobile, setIsMobile] = useState(false);
|
||||
const [showMobileSettings, setShowMobileSettings] = useState(false);
|
||||
const [localSearchValue, setLocalSearchValue] = useState(searchKeywords);
|
||||
const [showNotices, setShowNotices] = useState(false);
|
||||
const [showSettings, setShowSettings] = useState(false);
|
||||
const searchDebounceRef = useRef(null);
|
||||
|
||||
// 授权系统 hub:版本 / 公告 / 在线人数
|
||||
const hub = useHub();
|
||||
const announcements = hub.announcements || [];
|
||||
const appVersion = hub.version ? `v${String(hub.version).replace(/^v/, '')}` : 'v1.2.0';
|
||||
|
||||
// 从全局 store 获取筛选状态
|
||||
const selectedFormats = filters.formats || [];
|
||||
@@ -294,6 +305,88 @@ function Header() {
|
||||
);
|
||||
const availableRatings = filterOptions.ratings;
|
||||
|
||||
// 右上角图标组:开源地址 / 通知 / 设置 / 版本号
|
||||
const rightIcons = (
|
||||
<>
|
||||
<a
|
||||
href={REPO_URL}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
title="开源地址"
|
||||
className="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"
|
||||
>
|
||||
<Github className="w-5 h-5 text-gray-700 dark:text-gray-300" />
|
||||
</a>
|
||||
|
||||
<div className="relative">
|
||||
<button
|
||||
onClick={() => setShowNotices((v) => !v)}
|
||||
title="通知公告"
|
||||
className="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors relative"
|
||||
>
|
||||
<Bell className="w-5 h-5 text-gray-700 dark:text-gray-300" />
|
||||
{announcements.length > 0 && (
|
||||
<span className="absolute top-1.5 right-1.5 w-2 h-2 rounded-full bg-red-500"></span>
|
||||
)}
|
||||
</button>
|
||||
|
||||
{showNotices && (
|
||||
<>
|
||||
<div className="fixed inset-0 z-40" onClick={() => setShowNotices(false)}></div>
|
||||
<div className="absolute right-0 mt-2 w-80 max-h-96 overflow-y-auto z-50 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl shadow-2xl p-3">
|
||||
<div className="flex items-center justify-between text-xs text-gray-500 dark:text-gray-400 pb-2 mb-2 border-b border-gray-100 dark:border-gray-700">
|
||||
<span>通知公告</span>
|
||||
<span className="flex items-center gap-1">
|
||||
{hub.online != null && <span className="text-green-600 dark:text-green-400">在线 {hub.online}</span>}
|
||||
<span>{appVersion}</span>
|
||||
</span>
|
||||
</div>
|
||||
{announcements.length === 0 ? (
|
||||
<div className="text-sm text-gray-400 dark:text-gray-500 py-4 text-center">暂无公告</div>
|
||||
) : (
|
||||
<div className="space-y-2.5">
|
||||
{announcements.map((a, i) => (
|
||||
<div key={a.id || i} className="p-2.5 rounded-lg bg-gray-50 dark:bg-gray-900/60">
|
||||
{a.title && (
|
||||
<div className="text-sm font-medium text-gray-900 dark:text-white mb-1">{a.title}</div>
|
||||
)}
|
||||
<div className="text-xs text-gray-600 dark:text-gray-300 whitespace-pre-wrap leading-relaxed">{a.content}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{hub.update_available && (
|
||||
<a
|
||||
href={hub.download_url || REPO_URL}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="mt-2 flex items-center justify-center gap-1 text-xs text-blue-600 dark:text-blue-400 hover:underline py-1.5"
|
||||
>
|
||||
发现新版本 {hub.latest},去更新
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={() => setShowSettings(true)}
|
||||
title="设置"
|
||||
className="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"
|
||||
>
|
||||
<Settings className="w-5 h-5 text-gray-700 dark:text-gray-300" />
|
||||
</button>
|
||||
|
||||
<span className="hidden sm:inline-block px-2 py-0.5 text-xs text-gray-500 dark:text-gray-400 border border-gray-200 dark:border-gray-700 rounded-full select-none">
|
||||
{appVersion}
|
||||
</span>
|
||||
|
||||
<SettingsModal open={showSettings} onClose={() => setShowSettings(false)} versionLabel={appVersion} />
|
||||
</>
|
||||
);
|
||||
|
||||
// 移动端布局
|
||||
if (isMobile) {
|
||||
// 文件夹视图不显示搜索和筛选
|
||||
@@ -331,6 +424,8 @@ function Header() {
|
||||
<Sun className="w-5 h-5 text-gray-700 dark:text-gray-300" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
{rightIcons}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -342,7 +437,7 @@ function Header() {
|
||||
<Search className="absolute left-3 top-2.5 w-5 h-5 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="搜索图片..."
|
||||
placeholder="搜索图片...(支持 OCR 图内文字)"
|
||||
value={searchKeywords}
|
||||
onChange={(e) => handleSearchChange(e.target.value)}
|
||||
className="w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 text-sm"
|
||||
@@ -512,7 +607,7 @@ function Header() {
|
||||
<Search className="absolute left-3 top-2.5 w-5 h-5 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="搜索图片... (多个关键词用空格分隔,即时搜索)"
|
||||
placeholder="搜索图片...(支持 OCR 图内文字,多个关键词用空格分隔)"
|
||||
value={localSearchValue}
|
||||
onChange={(e) => handleSearchChange(e.target.value)}
|
||||
className="w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
@@ -578,6 +673,9 @@ function Header() {
|
||||
<Sun className="w-5 h-5 text-gray-700 dark:text-gray-300" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="w-px h-6 bg-gray-200 dark:bg-gray-700 ml-1"></div>
|
||||
{rightIcons}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { X, ScanText, Info, Save, FlaskConical, Github, ExternalLink } from 'lucide-react';
|
||||
import { settingsAPI } from '../api';
|
||||
|
||||
const APP_VERSION = 'v1.2.0';
|
||||
const REPO_URL = 'https://gitea.88531.cn/jinghui/flypic';
|
||||
|
||||
/**
|
||||
* 设置弹窗:左侧菜单 + 右侧参数
|
||||
* - OCR 识别:本地 tesseract / 线上接口切换、线上参数、测试
|
||||
* - 关于:版本号 / 开源地址
|
||||
*/
|
||||
export default function SettingsModal({ open, onClose, versionLabel }) {
|
||||
const [active, setActive] = useState('ocr');
|
||||
const [cfg, setCfg] = useState(null); // { provider, online:{url,model,apiKeyMasked} }
|
||||
const [apiKeyInput, setApiKeyInput] = useState(''); // 新密钥(留空=保持原密钥)
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [testing, setTesting] = useState(false);
|
||||
const [msg, setMsg] = useState(null); // { type, text }
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
setMsg(null);
|
||||
setApiKeyInput('');
|
||||
settingsAPI.getSettings()
|
||||
.then((d) => setCfg({
|
||||
provider: d?.provider || 'local',
|
||||
online: {
|
||||
url: d?.online?.url || 'https://ai.88531.cn/v1',
|
||||
model: d?.online?.model || 'mimo-v2.6-flash',
|
||||
apiKeyMasked: d?.online?.apiKeyMasked || ''
|
||||
},
|
||||
telemetry: d?.telemetry !== false
|
||||
}))
|
||||
.catch((e) => setMsg({ type: 'error', text: '读取设置失败: ' + (e.data?.message || e.message) }));
|
||||
}, [open]);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const patch = (p) => setCfg((c) => ({ ...c, ...p, online: { ...c.online, ...(p.online || {}) } }));
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
setMsg(null);
|
||||
try {
|
||||
const payload = {
|
||||
ocr: {
|
||||
provider: cfg.provider,
|
||||
online: {
|
||||
url: cfg.online.url,
|
||||
model: cfg.online.model,
|
||||
apiKey: apiKeyInput // 空字符串 = 保留原密钥
|
||||
}
|
||||
}
|
||||
};
|
||||
const data = await settingsAPI.updateSettings(payload);
|
||||
setCfg((c) => ({ ...(c || {}), ...data, online: { ...(c?.online || {}), ...(data?.online || {}) } }));
|
||||
setApiKeyInput('');
|
||||
setMsg({ type: 'ok', text: '已保存,新配置立即生效' });
|
||||
} catch (e) {
|
||||
setMsg({ type: 'error', text: '保存失败: ' + (e.data?.message || e.message) });
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleTest = async () => {
|
||||
setTesting(true);
|
||||
setMsg(null);
|
||||
try {
|
||||
// 若用户改了线上参数但没保存,测试时带上输入框内容
|
||||
const apiKey = apiKeyInput || undefined;
|
||||
const d = await settingsAPI.testOcr({
|
||||
provider: cfg.provider,
|
||||
url: cfg.online.url,
|
||||
model: cfg.online.model,
|
||||
...(cfg.provider === 'online' && apiKey ? { apiKey } : {})
|
||||
});
|
||||
if (d && typeof d.ms === 'number') {
|
||||
setMsg({ type: 'ok', text: `识别成功(${d.ms}ms):${(d.text || '').slice(0, 80) || '(空)'}` });
|
||||
} else {
|
||||
setMsg({ type: 'error', text: (d && d.message) || '识别失败' });
|
||||
}
|
||||
} catch (e) {
|
||||
setMsg({ type: 'error', text: '测试失败: ' + (e.data?.message || e.message) });
|
||||
} finally {
|
||||
setTesting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const menus = [
|
||||
{ key: 'ocr', label: 'OCR 识别', icon: ScanText },
|
||||
{ key: 'about', label: '关于', icon: Info }
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4" onClick={onClose}>
|
||||
<div
|
||||
className="bg-white dark:bg-gray-800 rounded-xl shadow-2xl w-full max-w-3xl max-h-[85vh] overflow-hidden flex"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* 左侧菜单 */}
|
||||
<div className="w-44 flex-shrink-0 border-r border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 p-3 flex flex-col">
|
||||
<div className="text-sm font-semibold text-gray-900 dark:text-white px-2 py-2">设置</div>
|
||||
{menus.map((m) => (
|
||||
<button
|
||||
key={m.key}
|
||||
onClick={() => { setActive(m.key); setMsg(null); }}
|
||||
className={`flex items-center gap-2 px-3 py-2.5 rounded-lg text-sm transition-colors ${
|
||||
active === m.key
|
||||
? 'bg-blue-50 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300 font-medium'
|
||||
: 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700'
|
||||
}`}
|
||||
>
|
||||
<m.icon className="w-4 h-4" />
|
||||
{m.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 右侧参数 */}
|
||||
<div className="flex-1 p-6 overflow-y-auto">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h2 className="text-lg font-semibold text-gray-900 dark:text-white">
|
||||
{active === 'ocr' ? 'OCR 识别设置' : '关于'}
|
||||
</h2>
|
||||
<button onClick={onClose} className="p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700">
|
||||
<X className="w-5 h-5 text-gray-500" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{msg && (
|
||||
<div className={`mb-4 px-3 py-2 rounded-lg text-sm ${
|
||||
msg.type === 'ok' ? 'bg-green-50 text-green-700 dark:bg-green-500/15 dark:text-green-300'
|
||||
: 'bg-red-50 text-red-700 dark:bg-red-500/15 dark:text-red-300'
|
||||
}`}>{msg.text}</div>
|
||||
)}
|
||||
|
||||
{active === 'ocr' && cfg && (
|
||||
<div className="space-y-5">
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||
OCR 用于「图内文字搜索」:识别图片中的文字并建立索引,扫描素材库时自动执行。
|
||||
</p>
|
||||
|
||||
{/* 识别方式 */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">识别方式</label>
|
||||
<div className="space-y-2">
|
||||
<label className="flex items-start gap-2.5 p-3 border border-gray-200 dark:border-gray-700 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50">
|
||||
<input
|
||||
type="radio"
|
||||
className="mt-0.5"
|
||||
checked={cfg.provider === 'local'}
|
||||
onChange={() => patch({ provider: 'local' })}
|
||||
/>
|
||||
<span>
|
||||
<span className="block text-sm font-medium text-gray-900 dark:text-white">本地 OCR(tesseract)</span>
|
||||
<span className="block text-xs text-gray-500 dark:text-gray-400 mt-0.5">免费离线,中英文识别,随容器内置,无需任何配置</span>
|
||||
</span>
|
||||
</label>
|
||||
<label className="flex items-start gap-2.5 p-3 border border-gray-200 dark:border-gray-700 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50">
|
||||
<input
|
||||
type="radio"
|
||||
className="mt-0.5"
|
||||
checked={cfg.provider === 'online'}
|
||||
onChange={() => patch({ provider: 'online' })}
|
||||
/>
|
||||
<span>
|
||||
<span className="block text-sm font-medium text-gray-900 dark:text-white">线上 OCR(视觉大模型)</span>
|
||||
<span className="block text-xs text-gray-500 dark:text-gray-400 mt-0.5">识别率更高,需 OpenAI 兼容接口(/v1/chat/completions)</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 线上参数 */}
|
||||
{cfg.provider === 'online' && (
|
||||
<div className="space-y-3 p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700">
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">接口地址</label>
|
||||
<input
|
||||
type="text"
|
||||
value={cfg.online.url}
|
||||
onChange={(e) => patch({ online: { url: e.target.value } })}
|
||||
placeholder="https://ai.88531.cn/v1(默认)"
|
||||
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">模型名称</label>
|
||||
<input
|
||||
type="text"
|
||||
value={cfg.online.model}
|
||||
onChange={(e) => patch({ online: { model: e.target.value } })}
|
||||
placeholder="mimo-v2.6-flash(默认)"
|
||||
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">API Key</label>
|
||||
<input
|
||||
type="password"
|
||||
value={apiKeyInput}
|
||||
onChange={(e) => setApiKeyInput(e.target.value)}
|
||||
placeholder={cfg.online.apiKeyMasked ? `已配置(${cfg.online.apiKeyMasked}),留空保持不变` : 'sk-...'}
|
||||
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={saving}
|
||||
className="flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-lg disabled:opacity-50"
|
||||
>
|
||||
<Save className="w-4 h-4" />
|
||||
{saving ? '保存中...' : '保存'}
|
||||
</button>
|
||||
<button
|
||||
onClick={handleTest}
|
||||
disabled={testing}
|
||||
className="flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 disabled:opacity-50"
|
||||
>
|
||||
<FlaskConical className="w-4 h-4" />
|
||||
{testing ? '测试中...' : '测试识别'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{active === 'about' && (
|
||||
<div className="space-y-4 text-sm">
|
||||
<div className="flex items-center justify-between py-2 border-b border-gray-100 dark:border-gray-700">
|
||||
<span className="text-gray-500 dark:text-gray-400">当前版本</span>
|
||||
<span className="font-medium text-gray-900 dark:text-white">{versionLabel || APP_VERSION}</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between py-2 border-b border-gray-100 dark:border-gray-700">
|
||||
<span className="text-gray-500 dark:text-gray-400">项目名称</span>
|
||||
<span className="font-medium text-gray-900 dark:text-white">FlyPic 素材库</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between py-2">
|
||||
<span className="text-gray-500 dark:text-gray-400">开源地址</span>
|
||||
<a
|
||||
href={REPO_URL}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex items-center gap-1 text-blue-600 dark:text-blue-400 hover:underline"
|
||||
>
|
||||
<Github className="w-4 h-4" />
|
||||
gitea.88531.cn/jinghui/flypic
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
</a>
|
||||
</div>
|
||||
<p className="text-xs text-gray-400 dark:text-gray-500 pt-2">
|
||||
FlyPic 基于 ZangXincz/FlyPic 二次开发,修复多项问题并新增 OCR 图内文字搜索、线上 OCR、授权系统接入等能力。
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useEffect, useState, useCallback, useRef } from 'react';
|
||||
import { hubAPI } from '../api/endpoints/hub';
|
||||
|
||||
/**
|
||||
* 轮询 hub:新版本 + 公告 + 在线人数
|
||||
* 失败开放:接口不可用时状态保持默认,不影响页面使用
|
||||
*/
|
||||
export function useHub(pollMs = 60000) {
|
||||
const [status, setStatus] = useState({
|
||||
version: '',
|
||||
latest: '',
|
||||
update_available: false,
|
||||
changelog: '',
|
||||
download_url: '',
|
||||
announcements: [],
|
||||
popup: [],
|
||||
online: null,
|
||||
hub_ok: false
|
||||
});
|
||||
const timerRef = useRef(null);
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
try {
|
||||
const data = await hubAPI.getHub();
|
||||
if (data && typeof data === 'object') {
|
||||
setStatus((prev) => ({ ...prev, ...data }));
|
||||
}
|
||||
} catch {
|
||||
// 失败开放
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
refresh();
|
||||
timerRef.current = setInterval(refresh, pollMs);
|
||||
return () => clearInterval(timerRef.current);
|
||||
}, [refresh, pollMs]);
|
||||
|
||||
return { ...status, refresh };
|
||||
}
|
||||
|
||||
export default useHub;
|
||||
Reference in new issue
Block a user