fix: 管理页每次打开即自动测速所有资源站(测速提升到页面级) (fixed124)
Docker Build & Test / build (push) Canceled after 0s
Docker Build & Test / test (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/amd64) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm/v7) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm64) (push) Canceled after 0s
Build & Push Docker image / merge-images (push) Canceled after 0s

This commit is contained in:
jinghui committed 2026-11-10 17:46:38 +08:00
1 parent dc7787a5ab
commit aee4b48995
2 files changed
+29 -27

No files matched your search

+2 -2
View File
@@ -35,7 +35,7 @@ RUN find ./src -type f -name "route.ts" -print0 \
ENV DOCKER_ENV=true
# 海报走站内 /api/image-proxy(浏览器直连豆瓣图被拦导致全裂)
ENV NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy
ENV NEXT_PUBLIC_SITE_VERSION=fixed123
ENV NEXT_PUBLIC_SITE_VERSION=fixed124
ENV NEXT_PUBLIC_ENABLE_REGISTER=true
# For Docker builds, force dynamic rendering to read runtime environment variables.
@@ -56,7 +56,7 @@ ENV HOSTNAME=0.0.0.0
ENV PORT=3000
ENV DOCKER_ENV=true
ENV NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy
ENV NEXT_PUBLIC_SITE_VERSION=fixed123
ENV NEXT_PUBLIC_SITE_VERSION=fixed124
ENV NEXT_PUBLIC_ENABLE_REGISTER=true
# 从构建器中复制 standalone 输出
+27 -25
View File
@@ -650,16 +650,17 @@ const UserConfig = ({ config, role, refreshConfig }: UserConfigProps) => {
const VideoSourceConfig = ({
config,
refreshConfig,
speeds,
}: {
config: AdminConfig | null;
refreshConfig: () => Promise<void>;
speeds: Record<string, { ms: number; ok: boolean }>;
}) => {
const [sources, setSources] = useState<DataSource[]>([]);
const [showAddForm, setShowAddForm] = useState(false);
const [orderChanged, setOrderChanged] = useState(false);
const [batchMode, setBatchMode] = useState(false);
const [selectedSources, setSelectedSources] = useState<Set<string>>(new Set());
const [speeds, setSpeeds] = useState<Record<string, { ms: number; ok: boolean }>>({});
const [newSource, setNewSource] = useState<DataSource>({
name: '',
key: '',
@@ -694,29 +695,6 @@ const VideoSourceConfig = ({
}
}, [config]);
// 打开页面自动测速各资源站响应时间
useEffect(() => {
let alive = true;
const run = async () => {
try {
const r = await fetch('/api/filter?action=probe');
const j = await r.json().catch(() => null);
if (!alive) return;
const map: Record<string, { ms: number; ok: boolean }> = {};
(j?.results || []).forEach((x: any) => {
map[x.key] = { ms: x.ms, ok: x.ok };
});
setSpeeds(map);
} catch {
/* 忽略测速失败 */
}
};
run();
return () => {
alive = false;
};
}, []);
// 通用 API 请求
const callSourceApi = async (body: Record<string, any>) => {
try {
@@ -1704,6 +1682,7 @@ const SiteConfigComponent = ({ config }: { config: AdminConfig | null }) => {
function AdminPageClient() {
const router = useRouter();
const [speeds, setSpeeds] = useState<Record<string, { ms: number; ok: boolean }>>({});
const [config, setConfig] = useState<AdminConfig | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
@@ -1714,6 +1693,29 @@ function AdminPageClient() {
siteConfig: false,
});
// 每次打开管理页自动并发测速所有资源站一次
useEffect(() => {
let alive = true;
const run = async () => {
try {
const r = await fetch('/api/filter?action=probe');
const j = await r.json().catch(() => null);
if (!alive) return;
const map: Record<string, { ms: number; ok: boolean }> = {};
(j?.results || []).forEach((x: any) => {
map[x.key] = { ms: x.ms, ok: x.ok };
});
setSpeeds(map);
} catch {
/* 测速失败不阻塞页面 */
}
};
run();
return () => {
alive = false;
};
}, []);
// 获取管理员配置
// showLoading 用于控制是否在请求期间显示整体加载骨架。
const fetchConfig = useCallback(async (showLoading = false) => {
@@ -1873,7 +1875,7 @@ function AdminPageClient() {
isExpanded={expandedTabs.videoSource}
onToggle={() => toggleTab('videoSource')}
>
<VideoSourceConfig config={config} refreshConfig={fetchConfig} />
<VideoSourceConfig config={config} refreshConfig={fetchConfig} speeds={speeds} />
</CollapsibleTab>
</div>
</div>