mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 20:10:24 +00:00
refactor(gateway): harden plugin http route contracts
This commit is contained in:
@@ -12,8 +12,9 @@ export function registerPluginHttpRoute(params: {
|
||||
path?: string | null;
|
||||
fallbackPath?: string | null;
|
||||
handler: PluginHttpRouteHandler;
|
||||
auth?: PluginHttpRouteRegistration["auth"];
|
||||
auth: PluginHttpRouteRegistration["auth"];
|
||||
match?: PluginHttpRouteRegistration["match"];
|
||||
replaceExisting?: boolean;
|
||||
pluginId?: string;
|
||||
source?: string;
|
||||
accountId?: string;
|
||||
@@ -36,6 +37,22 @@ export function registerPluginHttpRoute(params: {
|
||||
(entry) => entry.path === normalizedPath && entry.match === routeMatch,
|
||||
);
|
||||
if (existingIndex >= 0) {
|
||||
const existing = routes[existingIndex];
|
||||
if (!existing) {
|
||||
return () => {};
|
||||
}
|
||||
if (!params.replaceExisting) {
|
||||
params.log?.(
|
||||
`plugin: route conflict at ${normalizedPath} (${routeMatch})${suffix}; owned by ${existing.pluginId ?? "unknown-plugin"} (${existing.source ?? "unknown-source"})`,
|
||||
);
|
||||
return () => {};
|
||||
}
|
||||
if (existing.pluginId && params.pluginId && existing.pluginId !== params.pluginId) {
|
||||
params.log?.(
|
||||
`plugin: route replacement denied for ${normalizedPath} (${routeMatch})${suffix}; owned by ${existing.pluginId}`,
|
||||
);
|
||||
return () => {};
|
||||
}
|
||||
const pluginHint = params.pluginId ? ` (${params.pluginId})` : "";
|
||||
params.log?.(
|
||||
`plugin: replacing stale webhook path ${normalizedPath} (${routeMatch})${suffix}${pluginHint}`,
|
||||
@@ -46,7 +63,7 @@ export function registerPluginHttpRoute(params: {
|
||||
const entry: PluginHttpRouteRegistration = {
|
||||
path: normalizedPath,
|
||||
handler: params.handler,
|
||||
auth: params.auth ?? "gateway",
|
||||
auth: params.auth,
|
||||
match: routeMatch,
|
||||
pluginId: params.pluginId,
|
||||
source: params.source,
|
||||
|
||||
Reference in New Issue
Block a user