refactor(openclaw): extract gateway url validator
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
+1
-19
@@ -3,6 +3,7 @@ import type {
|
||||
OpenClawGateway,
|
||||
OpenClawReplyListenerConfig,
|
||||
} from "./types"
|
||||
export { validateGatewayUrl } from "./gateway-url-validation"
|
||||
|
||||
const DEFAULT_REPLY_POLL_INTERVAL_MS = 3000
|
||||
const MIN_REPLY_POLL_INTERVAL_MS = 500
|
||||
@@ -97,22 +98,3 @@ export function resolveGateway(
|
||||
|
||||
return { gatewayName: mapping.gateway, gateway, instruction: mapping.instruction }
|
||||
}
|
||||
|
||||
export function validateGatewayUrl(url: string): boolean {
|
||||
try {
|
||||
const parsed = new URL(url)
|
||||
if (parsed.protocol === "https:") return true
|
||||
if (
|
||||
parsed.protocol === "http:" &&
|
||||
(parsed.hostname === "localhost" ||
|
||||
parsed.hostname === "127.0.0.1" ||
|
||||
parsed.hostname === "::1" ||
|
||||
parsed.hostname === "[::1]")
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { spawn } from "bun"
|
||||
import { validateGatewayUrl } from "./config"
|
||||
import { validateGatewayUrl } from "./gateway-url-validation"
|
||||
import type { OpenClawGateway, WakeResult } from "./types"
|
||||
|
||||
const DEFAULT_HTTP_TIMEOUT_MS = 10_000
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
export function validateGatewayUrl(url: string): boolean {
|
||||
try {
|
||||
const parsed = new URL(url)
|
||||
if (parsed.protocol === "https:") return true
|
||||
if (
|
||||
parsed.protocol === "http:" &&
|
||||
(parsed.hostname === "localhost" ||
|
||||
parsed.hostname === "127.0.0.1" ||
|
||||
parsed.hostname === "::1" ||
|
||||
parsed.hostname === "[::1]")
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user