chore: unify code formatting and remove unused code

- Apply cargo fmt to Rust code with multiline error handling
- Apply Prettier formatting to TypeScript code with trailing commas
- Unify #[allow(non_snake_case)] attribute formatting
- Remove unused ProviderNotFound error variant from error.rs
- Add vitest-report.json to .gitignore to exclude test artifacts
- Optimize readability of error handling chains with vertical alignment

All tests passing: 22 Rust tests + 126 frontend tests
This commit is contained in:
Jason
2025-11-05 23:17:34 +08:00
parent 4f4c1e4ed7
commit d6fa0060fb
15 changed files with 344 additions and 195 deletions

View File

@@ -331,26 +331,34 @@ export function ProviderForm({
// 处理 meta 字段:基于 draftCustomEndpoints 生成 custom_endpoints
// 注意:不使用 customEndpointsMap因为它包含了候选端点预设、Base URL 等)
// 而我们只需要保存用户真正添加的自定义端点
const customEndpointsToSave: Record<string, import("@/types").CustomEndpoint> | null =
const customEndpointsToSave: Record<
string,
import("@/types").CustomEndpoint
> | null =
draftCustomEndpoints.length > 0
? draftCustomEndpoints.reduce((acc, url) => {
// 尝试从 initialData.meta 中获取原有的端点元数据(保留 addedAt 和 lastUsed
const existing = initialData?.meta?.custom_endpoints?.[url];
if (existing) {
acc[url] = existing;
} else {
// 新端点:使用当前时间戳
const now = Date.now();
acc[url] = { url, addedAt: now, lastUsed: undefined };
}
return acc;
}, {} as Record<string, import("@/types").CustomEndpoint>)
? draftCustomEndpoints.reduce(
(acc, url) => {
// 尝试从 initialData.meta 中获取原有的端点元数据(保留 addedAt 和 lastUsed
const existing = initialData?.meta?.custom_endpoints?.[url];
if (existing) {
acc[url] = existing;
} else {
// 新端点:使用当前时间戳
const now = Date.now();
acc[url] = { url, addedAt: now, lastUsed: undefined };
}
return acc;
},
{} as Record<string, import("@/types").CustomEndpoint>,
)
: null;
// 检测是否需要清空端点(重要:区分"用户清空端点"和"用户没有修改端点"
const hadEndpoints = initialData?.meta?.custom_endpoints &&
Object.keys(initialData.meta.custom_endpoints).length > 0;
const needsClearEndpoints = hadEndpoints && draftCustomEndpoints.length === 0;
const hadEndpoints =
initialData?.meta?.custom_endpoints &&
Object.keys(initialData.meta.custom_endpoints).length > 0;
const needsClearEndpoints =
hadEndpoints && draftCustomEndpoints.length === 0;
// 如果用户明确清空了端点,传递空对象(而不是 null让后端知道要删除
const mergedMeta = needsClearEndpoints