bd09c55c47
Integrates nine commits of reviewed work from the lane-go branch after the automated resolver failed on this merge five times (each attempt dying on the malformed-result defect whose fix is contained in this same merge). Integration decisions: - Search: kept main's shipped design (Store.Search + SearchResponse.Results) and dropped lane-go's parallel, older attempt (an unused Message.Matches field, an absent runs.search, and two partial TUI plumbing blocks). lane-go itself did not compile: protocol.SearchMatch was undefined and model.go referenced searchNav, requestSearch and applyRunNav, which exist nowhere. Those partial TUI blocks are removed; the queued TUI omni-search item will implement the surface properly on main's design. - Both sides' additions are kept where they are independent: run titles and provenance, the human decision stage and its CLI/TUI surface, the derived stage verdict, the stale-client guard, the line-oriented result format, and main's search command. - The search key's help label is now "/ omni search"; the two tests asserting the old label are updated rather than the label reverted. - docs/cli.md and the packaged operations reference carry both sides' text. Verified: go build ./... , go vet ./... and the full go test ./... suite pass.
108 lines
3.5 KiB
JavaScript
108 lines
3.5 KiB
JavaScript
// Server-URL validation mirroring android/.../data/transport/ServerUrl.kt and
|
|
// internal/client/config.go: only ws/wss with a non-empty hostname and no
|
|
// userinfo/fragment. The endpoint path defaults to /connect, matching
|
|
// internal/server/websocket.go `GET /connect`.
|
|
|
|
export const ServerUrlKind = Object.freeze({
|
|
EMPTY: "EMPTY",
|
|
MALFORMED: "MALFORMED",
|
|
UNSUPPORTED_SCHEME: "UNSUPPORTED_SCHEME",
|
|
MISSING_HOST: "MISSING_HOST",
|
|
USER_INFO: "USER_INFO",
|
|
FRAGMENT: "FRAGMENT",
|
|
});
|
|
|
|
/**
|
|
* @returns {{valid:true, wsUrl:string, httpUrl:string, host:string, port:number, secure:boolean}
|
|
* |{valid:false, kind:string, message:string}}
|
|
*/
|
|
export function validateServerUrl(raw) {
|
|
const trimmed = (raw ?? "").trim();
|
|
if (!trimmed) {
|
|
return {
|
|
valid: false,
|
|
kind: ServerUrlKind.EMPTY,
|
|
message:
|
|
"Enter the Pipelines server URL, for example ws://192.168.1.20:8081/connect",
|
|
};
|
|
}
|
|
|
|
let url;
|
|
try {
|
|
url = new URL(trimmed);
|
|
} catch {
|
|
return {
|
|
valid: false,
|
|
kind: ServerUrlKind.MALFORMED,
|
|
message: "That is not a valid URL.",
|
|
};
|
|
}
|
|
|
|
const scheme = url.protocol.replace(/:$/, "").toLowerCase();
|
|
if (scheme !== "ws" && scheme !== "wss") {
|
|
return {
|
|
valid: false,
|
|
kind: ServerUrlKind.UNSUPPORTED_SCHEME,
|
|
message: `Unsupported scheme "${scheme}"; use ws:// (trusted LAN/VPN) or wss://`,
|
|
};
|
|
}
|
|
if (url.username || url.password) {
|
|
return {
|
|
valid: false,
|
|
kind: ServerUrlKind.USER_INFO,
|
|
message:
|
|
"Credentials are not supported; the server has no authentication. Remove userinfo from the URL",
|
|
};
|
|
}
|
|
if (url.hash) {
|
|
return {
|
|
valid: false,
|
|
kind: ServerUrlKind.FRAGMENT,
|
|
message: "Remove the # fragment; it is not part of the server endpoint",
|
|
};
|
|
}
|
|
if (!url.hostname) {
|
|
return {
|
|
valid: false,
|
|
kind: ServerUrlKind.MISSING_HOST,
|
|
message:
|
|
"The URL is missing a host, for example ws://192.168.1.20:8081/connect",
|
|
};
|
|
}
|
|
|
|
const secure = scheme === "wss";
|
|
const port = url.port ? Number(url.port) : secure ? 443 : 80;
|
|
let path = url.pathname || "";
|
|
if (!path || path === "/") path = "/connect";
|
|
|
|
const authority = url.host; // host + explicit port only when present
|
|
const search = url.search || "";
|
|
const wsUrl = `${scheme}://${authority}${path}${search}`;
|
|
const httpUrl = `${secure ? "https" : "http"}://${authority}${path}${search}`;
|
|
|
|
return { valid: true, wsUrl, httpUrl, host: url.hostname, port, secure };
|
|
}
|
|
|
|
/**
|
|
* Resolves a server-relative artifact url (for example "/artifacts/55/4/shot.png")
|
|
* against the configured server URL by mapping ws/wss to http/https and dropping
|
|
* the /connect path. Never hardcodes a host: a blank or invalid configuration, or
|
|
* a blank path, yields null so the UI can disable actions. An already-absolute
|
|
* http(s) url is returned unchanged. Mirrors ServerUrl.resolveArtifactUrl.
|
|
*/
|
|
export function resolveArtifactUrl(configured, artifactUrl) {
|
|
const relative = (artifactUrl ?? "").trim();
|
|
if (!relative) return null;
|
|
if (relative.startsWith("http://") || relative.startsWith("https://")) {
|
|
return relative;
|
|
}
|
|
const validated = validateServerUrl(configured);
|
|
if (!validated.valid) return null;
|
|
const { secure, host, port } = validated;
|
|
const defaultPort = secure ? 443 : 80;
|
|
const authority = port && port !== defaultPort ? `${host}:${port}` : host;
|
|
const origin = `${secure ? "https" : "http"}://${authority}`;
|
|
const path = relative.startsWith("/") ? relative : `/${relative}`;
|
|
return origin + path;
|
|
}
|