mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-14 01:31:50 +02:00
add resource info to side panel
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import type { GetResourceResponse } from "@server/routers/resource/getResource";
|
||||
import type { GetResourceAuthInfoResponse } from "@server/routers/resource/getResourceAuthInfo";
|
||||
import type { GetSiteResourceResponse } from "@server/routers/siteResource/getSiteResource";
|
||||
|
||||
export type PublicAuthState = "protected" | "not_protected" | "none";
|
||||
|
||||
const BROWSER_MODES = ["http", "ssh", "rdp", "vnc"];
|
||||
|
||||
export function derivePublicAuthState(
|
||||
mode: string | null,
|
||||
authInfo: Pick<
|
||||
GetResourceAuthInfoResponse,
|
||||
"password" | "pincode" | "sso" | "whitelist" | "headerAuth"
|
||||
>
|
||||
): PublicAuthState {
|
||||
if (!BROWSER_MODES.includes(mode || "")) {
|
||||
return "none";
|
||||
}
|
||||
|
||||
if (
|
||||
authInfo.password ||
|
||||
authInfo.pincode ||
|
||||
authInfo.sso ||
|
||||
authInfo.whitelist ||
|
||||
authInfo.headerAuth
|
||||
) {
|
||||
return "protected";
|
||||
}
|
||||
|
||||
return "not_protected";
|
||||
}
|
||||
|
||||
export function formatPublicResourceType(
|
||||
resource: Pick<GetResourceResponse, "mode" | "ssl">
|
||||
): string {
|
||||
if (resource.mode === "http") {
|
||||
return resource.ssl ? "HTTPS" : "HTTP";
|
||||
}
|
||||
|
||||
const mode = (resource.mode || "").toLowerCase();
|
||||
if (mode === "tcp") {
|
||||
return "TCP";
|
||||
}
|
||||
if (mode === "udp") {
|
||||
return "UDP";
|
||||
}
|
||||
|
||||
return (resource.mode || "—").toUpperCase();
|
||||
}
|
||||
|
||||
export type PortProtocolState = "all" | "blocked" | "custom";
|
||||
|
||||
function getPortProtocolState(
|
||||
value: string | null | undefined
|
||||
): PortProtocolState {
|
||||
if (value === "*") {
|
||||
return "all";
|
||||
}
|
||||
|
||||
if (!value || value.trim() === "") {
|
||||
return "blocked";
|
||||
}
|
||||
|
||||
return "custom";
|
||||
}
|
||||
|
||||
export type PortRestrictionDisplay = {
|
||||
hasNonDefaultPorts: boolean;
|
||||
tcp: { state: PortProtocolState; ports: string | null };
|
||||
udp: { state: PortProtocolState; ports: string | null };
|
||||
};
|
||||
|
||||
export function formatPortRestrictionDisplay(
|
||||
resource: Pick<
|
||||
GetSiteResourceResponse,
|
||||
"tcpPortRangeString" | "udpPortRangeString"
|
||||
>
|
||||
): PortRestrictionDisplay {
|
||||
const tcpState = getPortProtocolState(resource.tcpPortRangeString);
|
||||
const udpState = getPortProtocolState(resource.udpPortRangeString);
|
||||
|
||||
return {
|
||||
hasNonDefaultPorts: tcpState !== "all" || udpState !== "all",
|
||||
tcp: {
|
||||
state: tcpState,
|
||||
ports: tcpState === "custom" ? resource.tcpPortRangeString : null
|
||||
},
|
||||
udp: {
|
||||
state: udpState,
|
||||
ports: udpState === "custom" ? resource.udpPortRangeString : null
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -54,8 +54,12 @@ import type {
|
||||
ListLauncherSitesResponse,
|
||||
ListLauncherViewsResponse,
|
||||
LauncherListQuery,
|
||||
LauncherResource,
|
||||
LauncherViewConfig
|
||||
} from "@server/routers/launcher/types";
|
||||
import type { GetResourceResponse } from "@server/routers/resource/getResource";
|
||||
import type { GetResourceAuthInfoResponse } from "@server/routers/resource/getResourceAuthInfo";
|
||||
import type { GetSiteResourceResponse } from "@server/routers/siteResource/getSiteResource";
|
||||
import type { LauncherQueryFilters } from "@app/lib/launcherSearchParams";
|
||||
import { buildLauncherSearchParams } from "@app/lib/launcherSearchParams";
|
||||
|
||||
@@ -1313,5 +1317,48 @@ export const launcherQueries = {
|
||||
>(`/org/${orgId}/launcher/scale?${sp.toString()}`, { signal });
|
||||
return res.data.data.scale;
|
||||
}
|
||||
}),
|
||||
resourceDetail: (orgId: string, resource: LauncherResource | null) =>
|
||||
queryOptions({
|
||||
queryKey: [
|
||||
"ORG",
|
||||
orgId,
|
||||
"LAUNCHER",
|
||||
"RESOURCE_DETAIL",
|
||||
resource?.launcherResourceKey ?? null
|
||||
] as const,
|
||||
enabled: resource != null,
|
||||
queryFn: async ({ signal, meta }) => {
|
||||
if (!resource) {
|
||||
throw new Error("Resource is required");
|
||||
}
|
||||
|
||||
if (resource.resourceType === "public") {
|
||||
const res = await meta!.api.get<
|
||||
AxiosResponse<GetResourceResponse>
|
||||
>(`/org/${orgId}/resource/${resource.niceId}`, { signal });
|
||||
const resourceData = res.data.data;
|
||||
const authRes = await meta!.api.get<
|
||||
AxiosResponse<GetResourceAuthInfoResponse>
|
||||
>(`/resource/${resourceData.resourceGuid}/auth`, {
|
||||
signal
|
||||
});
|
||||
return {
|
||||
resourceType: "public" as const,
|
||||
data: resourceData,
|
||||
authInfo: authRes.data.data
|
||||
};
|
||||
}
|
||||
|
||||
const siteResourceId =
|
||||
resource.siteResourceId ?? resource.resourceId;
|
||||
const res = await meta!.api.get<
|
||||
AxiosResponse<GetSiteResourceResponse>
|
||||
>(`/org/${orgId}/site-resource/${siteResourceId}`, { signal });
|
||||
return {
|
||||
resourceType: "site" as const,
|
||||
data: res.data.data
|
||||
};
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user