MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / formatInstanceData

Function formatInstanceData

panel/src/app/service/exchange_service.ts:116–148  ·  view source on GitHub ↗
(instance: IAdvancedInstanceInfo)

Source from the content-addressed store, hash-verified

114}
115
116function formatInstanceData(instance: IAdvancedInstanceInfo): IInstanceInfoProtocol {
117 let ports: string[] = instance.docker?.ports ?? [];
118 let portRules: Array<IPortInfo> = [];
119 if (ports?.length > 0) {
120 ports.forEach((line: string) => {
121 // line = "23333:24444/tcp"
122 const [ports, protocol] = line.split("/");
123 if (!ports || !protocol) return;
124 const [host, container] = ports.split(":");
125 if (isNaN(Number(container)) || isNaN(Number(host))) return;
126 portRules.push({
127 protocol,
128 container: Number(container),
129 host: Number(host)
130 });
131 });
132 }
133 const lines = [];
134 if (instance.info?.maxPlayers && Number(instance.info?.maxPlayers) != -1) {
135 lines.push({
136 title: t("TXT_CODE_7e9727bd"),
137 value: `${instance.info?.currentPlayers}/${instance.info?.maxPlayers}`
138 });
139 }
140 return {
141 instance_id: instance.instanceUuid,
142 name: instance.nickname || "",
143 status: instance.status || 0,
144 ports: portRules,
145 expire: instance.endTime || 0,
146 lines
147 };
148}
149
150export function parseUserName(t?: string) {
151 if (!t || typeof t !== "string") return "";

Callers 2

buyOrRenewInstanceFunction · 0.85
queryInstanceByUserIdFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected