fix: SFTP sidebar empty on load — list sent before WebSocket open
The list('/') call fired immediately after connect(), but the
WebSocket was still in CONNECTING state so send() silently dropped
the message. Now buffers the initial list request and sends it
in the onopen callback.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
aa457b54d4
commit
9e30e5915f
@ -9,10 +9,19 @@ export function useSftp(sessionId: Ref<string | null>) {
|
|||||||
const fileContent = ref<{ path: string; content: string } | null>(null)
|
const fileContent = ref<{ path: string; content: string } | null>(null)
|
||||||
const transfers = ref<any[]>([])
|
const transfers = ref<any[]>([])
|
||||||
|
|
||||||
|
let pendingList: string | null = null
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
const wsUrl = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}/api/ws/sftp?token=${auth.token}`
|
const wsUrl = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}/api/ws/sftp?token=${auth.token}`
|
||||||
ws = new WebSocket(wsUrl)
|
ws = new WebSocket(wsUrl)
|
||||||
|
|
||||||
|
ws.onopen = () => {
|
||||||
|
if (pendingList !== null) {
|
||||||
|
send({ type: 'list', path: pendingList })
|
||||||
|
pendingList = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ws.onmessage = (event) => {
|
ws.onmessage = (event) => {
|
||||||
const msg = JSON.parse(event.data)
|
const msg = JSON.parse(event.data)
|
||||||
switch (msg.type) {
|
switch (msg.type) {
|
||||||
@ -48,7 +57,13 @@ export function useSftp(sessionId: Ref<string | null>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function list(path: string) { send({ type: 'list', path }) }
|
function list(path: string) {
|
||||||
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||||
|
send({ type: 'list', path })
|
||||||
|
} else {
|
||||||
|
pendingList = path
|
||||||
|
}
|
||||||
|
}
|
||||||
function readFile(path: string) { send({ type: 'read', path }) }
|
function readFile(path: string) { send({ type: 'read', path }) }
|
||||||
function writeFile(path: string, data: string) { send({ type: 'write', path, data }) }
|
function writeFile(path: string, data: string) { send({ type: 'write', path, data }) }
|
||||||
function mkdir(path: string) { send({ type: 'mkdir', path }) }
|
function mkdir(path: string) { send({ type: 'mkdir', path }) }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user