fix: SFTP list not sent + RDP connect button does nothing
SFTP: Added console logging to diagnose, plus a watcher that sends the pending list when sessionId becomes available (covers the race where WS opens before sessionId is set). RDP: connectHost() was returning early for non-SSH protocols. Removed the guard and use host.protocol instead of hardcoded 'ssh'. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
46e2cb6e2f
commit
711ef73786
@ -1,4 +1,4 @@
|
|||||||
import { ref, type Ref } from 'vue'
|
import { ref, watch, type Ref } from 'vue'
|
||||||
import { useAuthStore } from '~/stores/auth.store'
|
import { useAuthStore } from '~/stores/auth.store'
|
||||||
|
|
||||||
export function useSftp(sessionId: Ref<string | null>) {
|
export function useSftp(sessionId: Ref<string | null>) {
|
||||||
@ -16,9 +16,17 @@ export function useSftp(sessionId: Ref<string | null>) {
|
|||||||
ws = new WebSocket(wsUrl)
|
ws = new WebSocket(wsUrl)
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
|
console.log('[SFTP] WS open, sessionId=', sessionId.value, 'pendingList=', pendingList)
|
||||||
if (pendingList !== null) {
|
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
|
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<string | null>) {
|
|||||||
function chmod(path: string, mode: string) { send({ type: 'chmod', path, mode }) }
|
function chmod(path: string, mode: string) { send({ type: 'chmod', path, mode }) }
|
||||||
function download(path: string) { send({ type: 'download', path }) }
|
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() {
|
function disconnect() {
|
||||||
ws?.close()
|
ws?.close()
|
||||||
ws = null
|
ws = null
|
||||||
|
|||||||
@ -85,16 +85,13 @@ function closeDetails() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function connectHost(host: any) {
|
function connectHost(host: any) {
|
||||||
if (host.protocol !== 'ssh') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const pendingId = `pending-${Date.now()}`
|
const pendingId = `pending-${Date.now()}`
|
||||||
sessions.addSession({
|
sessions.addSession({
|
||||||
key: pendingId,
|
key: pendingId,
|
||||||
id: pendingId,
|
id: pendingId,
|
||||||
hostId: host.id,
|
hostId: host.id,
|
||||||
hostName: host.name,
|
hostName: host.name,
|
||||||
protocol: 'ssh',
|
protocol: host.protocol,
|
||||||
color: host.color,
|
color: host.color,
|
||||||
active: true,
|
active: true,
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user