diff --git a/frontend/composables/useSftp.ts b/frontend/composables/useSftp.ts index 8597d1f..ee67105 100644 --- a/frontend/composables/useSftp.ts +++ b/frontend/composables/useSftp.ts @@ -1,4 +1,4 @@ -import { ref, type Ref } from 'vue' +import { ref, watch, type Ref } from 'vue' import { useAuthStore } from '~/stores/auth.store' export function useSftp(sessionId: Ref) { @@ -16,9 +16,17 @@ export function useSftp(sessionId: Ref) { ws = new WebSocket(wsUrl) ws.onopen = () => { + console.log('[SFTP] WS open, sessionId=', sessionId.value, 'pendingList=', pendingList) if (pendingList !== null) { - send({ type: 'list', path: pendingList }) + // Send directly — don't rely on send() guard since we know WS is open + const path = pendingList pendingList = null + if (sessionId.value) { + ws!.send(JSON.stringify({ type: 'list', path, sessionId: sessionId.value })) + } else { + console.warn('[SFTP] No sessionId available yet, cannot list') + pendingList = path // put it back + } } } @@ -72,6 +80,15 @@ export function useSftp(sessionId: Ref) { function chmod(path: string, mode: string) { send({ type: 'chmod', path, mode }) } function download(path: string) { send({ type: 'download', path }) } + // If sessionId arrives after WS is already open, send any pending list + watch(sessionId, (newId) => { + if (newId && pendingList !== null && ws?.readyState === WebSocket.OPEN) { + const path = pendingList + pendingList = null + ws!.send(JSON.stringify({ type: 'list', path, sessionId: newId })) + } + }) + function disconnect() { ws?.close() ws = null diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue index 73a26bc..58e8251 100644 --- a/frontend/pages/index.vue +++ b/frontend/pages/index.vue @@ -85,16 +85,13 @@ function closeDetails() { } function connectHost(host: any) { - if (host.protocol !== 'ssh') { - return - } const pendingId = `pending-${Date.now()}` sessions.addSession({ key: pendingId, id: pendingId, hostId: host.id, hostName: host.name, - protocol: 'ssh', + protocol: host.protocol, color: host.color, active: true, })