feat: add SFTP drag-and-drop file handling and upload functionality
- Implemented drag-and-drop support for file uploads in the terminal. - Added a modal for users to choose between uploading files or pasting contents. - Enhanced SFTP browser with a directory picker for selecting upload destinations. - Introduced methods for handling file uploads and reading file contents from the local system. - Added a new API endpoint for uploading raw file data to the server. - Implemented session management improvements to retrieve the current working directory for SSH sessions. - Updated documentation to include an overview and quick start guide for Nexus Terminal.
This commit is contained in:
@@ -258,6 +258,26 @@ func (m *Manager) ResizeSession(sessionID string, cols, rows int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSessionCwd returns a best-effort working directory for SSH sessions.
|
||||
func (m *Manager) GetSessionCwd(sessionID string) (string, error) {
|
||||
m.mu.RLock()
|
||||
sess, ok := m.sessions[sessionID]
|
||||
m.mu.RUnlock()
|
||||
|
||||
if !ok {
|
||||
return "", fmt.Errorf("sessions: session %q not found", sessionID)
|
||||
}
|
||||
if sess.sshClient == nil {
|
||||
return "", fmt.Errorf("sessions: session %q is not an SSH connection", sessionID)
|
||||
}
|
||||
|
||||
cwd, err := sess.sshClient.RunCommand("pwd")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(cwd), nil
|
||||
}
|
||||
|
||||
// GetSession returns session info by ID.
|
||||
func (m *Manager) GetSession(sessionID string) (*models.SessionInfo, error) {
|
||||
m.mu.RLock()
|
||||
@@ -1074,6 +1094,23 @@ func (m *Manager) SFTPUpload(sessionID, localPath, remotePath string) error {
|
||||
})
|
||||
}
|
||||
|
||||
// SFTPUploadBytes uploads in-memory data to a remote path.
|
||||
func (m *Manager) SFTPUploadBytes(sessionID, remotePath string, data []byte) error {
|
||||
sc, err := m.getSFTP(sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return sc.UploadBytes(remotePath, data, func(p sftpclient.TransferProgress) {
|
||||
m.emitEvent("session:sftp:progress", map[string]interface{}{
|
||||
"sessionID": sessionID,
|
||||
"transferred": p.Transferred,
|
||||
"total": p.Total,
|
||||
"path": p.Path,
|
||||
"done": p.Done,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// SFTPPwd returns the current working directory on the remote host.
|
||||
func (m *Manager) SFTPPwd(sessionID string) (string, error) {
|
||||
sc, err := m.getSFTP(sessionID)
|
||||
|
||||
Reference in New Issue
Block a user