- 前端:vite ^8.2.2、react/react-dom ^19.2.8、react-router ^8.3.1(移除 react-router-dom)、typescript ^7.0.2、zustand ^5.0.15;适配升级带来的类型变化(react-hook-form Resolver、ProseMirror node.parent、tiptap focus 参数、timer undefined 等) - 后端:升级 gin/jwt/minio-go/gorm/modernc-sqlite/x-crypto 等直接依赖至最新;gowebp v0.1.1 已是最新版本 - tsconfig 移除 baseUrl,paths 改为相对路径以兼容 TS7
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { useEffect, useRef } from 'react';
|
||
import { useLocation } from 'react-router';
|
||
import { api } from '../api/client';
|
||
import { useForumLimits } from './useForumLimits';
|
||
|
||
const DEDUPE_MS = 800;
|
||
|
||
function shouldSkipPath(pathname: string) {
|
||
const p = pathname.toLowerCase();
|
||
return (
|
||
p === '/admin' ||
|
||
p.startsWith('/admin/') ||
|
||
p === '/login' ||
|
||
p === '/register' ||
|
||
p === '/forgot-password' ||
|
||
p.startsWith('/oauth')
|
||
);
|
||
}
|
||
|
||
/** 主站布局:路由变化时上报第一方 pageview(采集关闭则不请求) */
|
||
export function useMonitorPageview() {
|
||
const loc = useLocation();
|
||
const { limits } = useForumLimits();
|
||
const lastRef = useRef<{ key: string; at: number }>({ key: '', at: 0 });
|
||
const enabled = !!limits.monitor_pageview;
|
||
|
||
useEffect(() => {
|
||
if (!enabled) return;
|
||
if (shouldSkipPath(loc.pathname)) return;
|
||
|
||
const path = `${loc.pathname}${loc.search || ''}`;
|
||
const now = Date.now();
|
||
if (lastRef.current.key === path && now - lastRef.current.at < DEDUPE_MS) {
|
||
return;
|
||
}
|
||
lastRef.current = { key: path, at: now };
|
||
|
||
const referrer = typeof document !== 'undefined' ? document.referrer || '' : '';
|
||
void api.monitorPageview({ path, referrer });
|
||
}, [enabled, loc.pathname, loc.search]);
|
||
}
|