MCPcopy
hub / github.com/Eugeny/tabby / edit

Method edit

tabby-electron/src/sftpContextMenu.ts:41–71  ·  view source on GitHub ↗
(item: SFTPFile, sftp: SFTPSession)

Source from the content-addressed store, hash-verified

39 }
40
41 private async edit (item: SFTPFile, sftp: SFTPSession) {
42 const tempDir = (await tmp.dir({ unsafeCleanup: true })).path
43 const tempPath = path.join(tempDir, item.name)
44 const transfer = await this.platform.startDownload(item.name, item.mode, item.size, tempPath)
45 if (!transfer) {
46 return
47 }
48 await sftp.download(item.fullPath, transfer)
49 this.platform.openPath(tempPath)
50
51 const events = new Subject<string>()
52 fs.chmodSync(tempPath, 0o700)
53
54 // skip the first burst of events
55 setTimeout(() => {
56 const watcher = fs.watch(tempPath, event => events.next(event))
57 events.pipe(debounceTime(1000), debounce(async event => {
58 if (event === 'rename') {
59 watcher.close()
60 }
61 const upload = await this.platform.startUpload({ multiple: false }, [tempPath])
62 if (!upload.length) {
63 return
64 }
65 await sftp.upload(item.fullPath, upload[0])
66 await sftp.chmod(item.fullPath, item.mode)
67 })).subscribe()
68 watcher.on('close', () => events.complete())
69 sftp.closed$.subscribe(() => watcher.close())
70 }, 1000)
71 }
72}

Callers 1

getItemsMethod · 0.95

Calls 10

openPathMethod · 0.80
nextMethod · 0.80
chmodMethod · 0.80
onMethod · 0.80
startDownloadMethod · 0.45
downloadMethod · 0.45
subscribeMethod · 0.45
closeMethod · 0.45
startUploadMethod · 0.45
uploadMethod · 0.45

Tested by

no test coverage detected