From 748d5c0939da1cd8c0328abcc5a3dfe1ba0122e2 Mon Sep 17 00:00:00 2001 From: StarFleetCPTN Date: Thu, 27 Mar 2025 16:29:50 -0700 Subject: [PATCH] feat: Update port initialization and handling for FTP/SFTP configurations - Changed default port initialization for source and destination configurations to 0, triggering default settings based on connection type. - Implemented logic to set default ports for FTP (21) and SFTP (22) in the frontend templates. - Enhanced input fields for FTP and SFTP forms to initialize and update port values dynamically based on user selections. - Updated backend configuration generation to include the correct port values for source and destination settings. --- components/config_form.templ | 38 ++++++++++++++++++--- components/providers/destination/ftp.templ | 4 ++- components/providers/destination/sftp.templ | 4 +-- components/providers/source/ftp.templ | 2 +- internal/db/db.go | 2 ++ 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/components/config_form.templ b/components/config_form.templ index a3dad3d..397053f 100644 --- a/components/config_form.templ +++ b/components/config_form.templ @@ -27,7 +27,7 @@ func getInitialData(config *db.TransferConfig) string { sourceType := "local" sourcePath := "" sourceHost := "" - sourcePort := 22 + sourcePort := 0 // Initialize to 0 to trigger default setting sourceUser := "" sourcePassword := "" sourceKeyFile := "" @@ -55,7 +55,7 @@ func getInitialData(config *db.TransferConfig) string { destinationType := "local" destinationPath := "" destHost := "" - destPort := 22 + destPort := 0 // Initialize to 0 to trigger default setting destUser := "" destPassword := "" destKeyFile := "" @@ -386,11 +386,41 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) { // Ensure initial form state displays correctly on load sourceType = sourceType || 'local'; destinationType = destinationType || 'local'; - sourcePort = sourcePort || 22; - destPort = destPort || 22; + + // Set default ports based on connection type + if (sourcePort === 0 || !sourcePort) { + if (sourceType === 'sftp') { + sourcePort = 22; + } else if (sourceType === 'ftp') { + sourcePort = 21; + } + } + + if (destPort === 0 || !destPort) { + if (destinationType === 'sftp') { + destPort = 22; + } else if (destinationType === 'ftp') { + destPort = 21; + } + } + // Initialize command requirements updateCommandRequirements(); })" + x-effect="if (sourceType === 'sftp' && (sourcePort === 0 || sourcePort === 21)) { + sourcePort = 22; + console.log('Updating source port to 22 for SFTP'); + } else if (sourceType === 'ftp' && (sourcePort === 0 || sourcePort === 22)) { + sourcePort = 21; + console.log('Updating source port to 21 for FTP'); + }" + x-effect="if (destinationType === 'sftp' && (destPort === 0 || destPort === 21)) { + destPort = 22; + console.log('Updating destination port to 22 for SFTP'); + } else if (destinationType === 'ftp' && (destPort === 0 || destPort === 22)) { + destPort = 21; + console.log('Updating destination port to 21 for FTP'); + }" > diff --git a/components/providers/destination/ftp.templ b/components/providers/destination/ftp.templ index bab99b2..c69372f 100644 --- a/components/providers/destination/ftp.templ +++ b/components/providers/destination/ftp.templ @@ -23,7 +23,9 @@ templ FTPDestinationForm() { + placeholder="21" min="1" max="65535" + x-init="if (!destPort || destPort === 0) destPort = 21" + x-effect="if (destinationType === 'ftp' && (destPort === 0 || destPort === 22)) destPort = 21" />

FTP port number (default: 21)

diff --git a/components/providers/destination/sftp.templ b/components/providers/destination/sftp.templ index 21ec906..063c782 100644 --- a/components/providers/destination/sftp.templ +++ b/components/providers/destination/sftp.templ @@ -23,7 +23,7 @@ templ SFTPDestinationForm() { + placeholder="22" min="1" max="65535" x-init="if (!destPort || destPort === 0) destPort = 22" />

SFTP port number (default: 22)

@@ -74,7 +74,7 @@ templ SFTPDestinationForm() {
- diff --git a/components/providers/source/ftp.templ b/components/providers/source/ftp.templ index 89eef6d..53cf5e2 100644 --- a/components/providers/source/ftp.templ +++ b/components/providers/source/ftp.templ @@ -23,7 +23,7 @@ templ FTPSourceForm() { + placeholder="21" min="1" max="65535" value="21"/>

FTP port number (default: 21)

diff --git a/internal/db/db.go b/internal/db/db.go index 01120be..feeb9eb 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -637,6 +637,7 @@ func (db *DB) GenerateRcloneConfig(config *TransferConfig) error { "host", config.SourceHost, "user", config.SourceUser, "pass", config.SourcePassword, + "port", fmt.Sprintf("%d", config.SourcePort), "--non-interactive", "--config", configPath, "--log-level", "ERROR", @@ -860,6 +861,7 @@ func (db *DB) GenerateRcloneConfig(config *TransferConfig) error { args := []string{ "config", "create", destName, "ftp", "host", config.DestHost, + "port", fmt.Sprintf("%d", config.DestPort), "user", config.DestUser, "pass", config.DestPassword, "--non-interactive",