fix: custom endpoints not saved when creating new provider

When creating a new provider, custom endpoints added in the speed test
modal were not being saved properly. The issue was in ProviderForm.tsx
where the CustomEndpoint object was constructed without the optional
lastUsed field.

This caused inconsistency between:
- Edit mode: uses backend API (addCustomEndpoint) which correctly
  constructs complete CustomEndpoint objects
- Create mode: directly constructs objects in frontend, missing the
  lastUsed field

Fixed by explicitly setting lastUsed to undefined when constructing
custom endpoints in create mode, ensuring structural consistency with
the TypeScript CustomEndpoint interface.
This commit is contained in:
Jason
2025-10-08 17:32:20 +08:00
parent 75ce5a0723
commit a6d461282d

View File

@@ -615,7 +615,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
...(category ? { category } : {}), ...(category ? { category } : {}),
}; };
// 若为新建供应商,且已在弹窗中添加了自定义端点,则随提交一并落盘 // 若为"新建供应商",且已在弹窗中添加了自定义端点,则随提交一并落盘
if (!initialData && draftCustomEndpoints.length > 0) { if (!initialData && draftCustomEndpoints.length > 0) {
const now = Date.now(); const now = Date.now();
const customMap: Record<string, CustomEndpoint> = {}; const customMap: Record<string, CustomEndpoint> = {};
@@ -623,7 +623,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
const url = raw.trim().replace(/\/+$/, ""); const url = raw.trim().replace(/\/+$/, "");
if (!url) continue; if (!url) continue;
if (!customMap[url]) { if (!customMap[url]) {
customMap[url] = { url, addedAt: now }; customMap[url] = { url, addedAt: now, lastUsed: undefined };
} }
} }
onSubmit({ ...basePayload, meta: { custom_endpoints: customMap } }); onSubmit({ ...basePayload, meta: { custom_endpoints: customMap } });