ESLint 升级到 recommended-type-checked + stylistic-type-checked, 引入 perfectionist 导入排序和 import 插件导入验证。 Prettier 显式声明全部格式化参数,消除跨环境差异。 TypeScript 启用 noUnusedLocals 和 noPropertyAccessFromIndexSignature。 完善 ignore 列表,排除 .agents/、bun.lock、data/ 等。 引入 husky + lint-staged(pre-commit)+ commitlint(commit-msg)。 更新 DEVELOPMENT.md 代码质量章节。 修复所有新增规则检测到的类型和风格违规。
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import type { RuntimeMode, TargetStatus } from "../../shared/api";
|
|
import type { ProbeStore } from "../checker/store";
|
|
|
|
import { formatDuration, jsonResponse, mapCheckResult } from "../helpers";
|
|
|
|
export function handleTargets(store: ProbeStore, method: string, mode: RuntimeMode): Response {
|
|
const targets = store.getTargets();
|
|
const latestChecksMap = store.getLatestChecksMap();
|
|
const allStats = store.getAllTargetStats();
|
|
|
|
const result: TargetStatus[] = targets.map((target) => {
|
|
const latest = latestChecksMap.get(target.id) ?? null;
|
|
const stats = allStats.get(target.id) ?? { availability: 0, totalChecks: 0 };
|
|
const recentSamples = store.getRecentSamples(target.id, 30);
|
|
|
|
return {
|
|
group: target.grp,
|
|
id: target.id,
|
|
interval: formatDuration(target.interval_ms),
|
|
latestCheck: latest ? mapCheckResult(latest) : null,
|
|
name: target.name,
|
|
recentSamples: recentSamples.map((s) => ({
|
|
durationMs: s.duration_ms,
|
|
timestamp: s.timestamp,
|
|
up: s.matched === 1,
|
|
})),
|
|
stats: {
|
|
availability: stats.availability,
|
|
totalChecks: stats.totalChecks,
|
|
},
|
|
target: target.target,
|
|
type: target.type,
|
|
};
|
|
});
|
|
|
|
return jsonResponse(result, { method, mode });
|
|
}
|