fix(terminal): simplify REST endpoints to use instance_id only
The frontend router navigates to /instances/:instanceId/terminal without
project_id or repo_id. The backend terminal REST endpoints were requiring
these path params, causing 404s.
- Simplify _get_terminal_instance to validate by instance_id only
- Update all REST routes from /projects/{pid}/repositories/{rid}/instances/{iid}/terminal/*
to /instances/{instance_id}/terminal/*
- Update frontend API client to match new paths
- Update useTerminalSessions hook to take instanceId only
- Update TerminalPage to use simplified hook
- Update tests to match new paths
Fixes: 404 on GET /projects/repositories/instances/{id}/terminal/sessions
This commit is contained in:
@@ -21,8 +21,6 @@ export interface UseTerminalSessionsResult {
|
||||
}
|
||||
|
||||
export function useTerminalSessions(
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
instanceId: string,
|
||||
): UseTerminalSessionsResult {
|
||||
const [sessions, setSessions] = useState<TerminalSession[]>([]);
|
||||
@@ -34,7 +32,7 @@ export function useTerminalSessions(
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const sess = await listTerminalSessions(projectId, repoId, instanceId);
|
||||
const sess = await listTerminalSessions(instanceId);
|
||||
setSessions(sess);
|
||||
if (sess.length > 0 && !activeSessionId) {
|
||||
setActiveSessionId(sess[0].id);
|
||||
@@ -44,18 +42,13 @@ export function useTerminalSessions(
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [projectId, repoId, instanceId, activeSessionId]);
|
||||
}, [instanceId, activeSessionId]);
|
||||
|
||||
const createSession = useCallback(
|
||||
async (name?: string) => {
|
||||
setError(null);
|
||||
try {
|
||||
const newSession = await createTerminalSession(
|
||||
projectId,
|
||||
repoId,
|
||||
instanceId,
|
||||
name,
|
||||
);
|
||||
const newSession = await createTerminalSession(instanceId, name);
|
||||
const session: TerminalSession = {
|
||||
id: newSession.id,
|
||||
name: newSession.name,
|
||||
@@ -74,14 +67,14 @@ export function useTerminalSessions(
|
||||
return null;
|
||||
}
|
||||
},
|
||||
[projectId, repoId, instanceId],
|
||||
[instanceId],
|
||||
);
|
||||
|
||||
const closeSession = useCallback(
|
||||
async (sessionId: string) => {
|
||||
setError(null);
|
||||
try {
|
||||
await closeTerminalSession(projectId, repoId, instanceId, sessionId);
|
||||
await closeTerminalSession(instanceId, sessionId);
|
||||
setSessions((prev) => {
|
||||
const filtered = prev.filter((s) => s.id !== sessionId);
|
||||
if (activeSessionId === sessionId && filtered.length > 0) {
|
||||
@@ -97,20 +90,14 @@ export function useTerminalSessions(
|
||||
);
|
||||
}
|
||||
},
|
||||
[projectId, repoId, instanceId, activeSessionId],
|
||||
[instanceId, activeSessionId],
|
||||
);
|
||||
|
||||
const renameSession = useCallback(
|
||||
async (sessionId: string, name: string) => {
|
||||
setError(null);
|
||||
try {
|
||||
await renameTerminalSession(
|
||||
projectId,
|
||||
repoId,
|
||||
instanceId,
|
||||
sessionId,
|
||||
name,
|
||||
);
|
||||
await renameTerminalSession(instanceId, sessionId, name);
|
||||
setSessions((prev) =>
|
||||
prev.map((s) => (s.id === sessionId ? { ...s, name } : s)),
|
||||
);
|
||||
@@ -120,14 +107,14 @@ export function useTerminalSessions(
|
||||
);
|
||||
}
|
||||
},
|
||||
[projectId, repoId, instanceId],
|
||||
[instanceId],
|
||||
);
|
||||
|
||||
const resetSession = useCallback(
|
||||
async (sessionId: string) => {
|
||||
setError(null);
|
||||
try {
|
||||
await resetTerminalSession(projectId, repoId, instanceId, sessionId);
|
||||
await resetTerminalSession(instanceId, sessionId);
|
||||
// Refetch to get updated session info
|
||||
await loadSessions();
|
||||
} catch (err) {
|
||||
@@ -136,7 +123,7 @@ export function useTerminalSessions(
|
||||
);
|
||||
}
|
||||
},
|
||||
[projectId, repoId, instanceId, loadSessions],
|
||||
[instanceId, loadSessions],
|
||||
);
|
||||
|
||||
// Initial load
|
||||
|
||||
Reference in New Issue
Block a user