enh: ot ports

This commit is contained in:
Timothy Jaeryang Baek
2026-03-04 15:51:03 -06:00
parent 890949abe6
commit e08341dab3
2 changed files with 164 additions and 0 deletions
+23
View File
@@ -5,6 +5,12 @@ export type FileEntry = {
modified?: number;
};
export type ListeningPort = {
port: number;
pid: number | null;
process: string | null;
};
export type TerminalFeatures = {
terminal?: boolean;
};
@@ -235,3 +241,20 @@ export const moveEntry = async (
});
return res;
};
export const getListeningPorts = async (
baseUrl: string,
apiKey: string
): Promise<ListeningPort[]> => {
const url = `${baseUrl.replace(/\/$/, '')}/ports`;
const res = await fetch(url, {
headers: { Authorization: `Bearer ${apiKey}` }
}).catch(() => null);
if (!res || !res.ok) return [];
const json = await res.json().catch(() => null);
return json?.ports ?? [];
};
export const getPortProxyUrl = (baseUrl: string, port: number, path: string = ''): string => {
return `${baseUrl.replace(/\/$/, '')}/proxy/${port}/${path}`;
};