feat: enhance TokenRoutes with edit functionality and route visibility management

- Added editing capabilities for route management in TokenRoutes, allowing users to modify existing routes.
- Introduced a reset function for the route form to clear inputs after adding or editing routes.
- Implemented a visibility filter for routes, ensuring exact routes covered by group routes are hidden from the main list.
- Updated tests to cover new functionalities, including editing routes and verifying visibility logic.
- Created a new helper function to build a list of visible routes based on defined criteria.
- Enhanced schema compatibility checks for site configurations, ensuring necessary columns are added to the database.
This commit is contained in:
cita
2026-03-07 19:56:40 +08:00
parent 5ad5b87b16
commit ed05b37626
18 changed files with 1476 additions and 153 deletions
@@ -68,6 +68,10 @@ function maskSecret(value: string): string {
return `${value.slice(0, 4)}****${value.slice(-4)}`;
}
function getExposedRouteName(route: { modelPattern: string; displayName: string | null }): string {
return (route.displayName || '').trim() || route.modelPattern.trim();
}
function normalizePositiveNumberOrNull(value: unknown): number | null {
if (value === null || value === undefined || value === '') return null;
const n = Number(value);
@@ -191,11 +195,7 @@ async function isModelMatchedByAllowedRoutes(model: string, allowedRouteIds: num
))
.all();
return routes.some((route) => {
if (matchesDownstreamModelPattern(model, route.modelPattern)) return true;
const alias = (route.displayName || '').trim();
return !!alias && alias === model;
});
return routes.some((route) => getExposedRouteName(route) === model);
}
export async function isModelAllowedByPolicyOrAllowedRoutes(model: string, policy: DownstreamRoutingPolicy): Promise<boolean> {