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.
This commit is contained in:
StarFleetCPTN
2025-03-27 16:29:50 -07:00
parent fde60b7d68
commit 748d5c0939
5 changed files with 42 additions and 8 deletions
+34 -4
View File
@@ -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');
}"
>
<!-- Configuration Details Section -->
+3 -1
View File
@@ -23,7 +23,9 @@ templ FTPDestinationForm() {
</div>
<input type="number" id="dest_port" name="dest_port" x-model="destPort"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full ps-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="21" min="1" max="65535" />
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" />
</div>
<p class="mt-2 text-sm text-gray-500 dark:text-gray-400">FTP port number (default: 21)</p>
</div>
+2 -2
View File
@@ -23,7 +23,7 @@ templ SFTPDestinationForm() {
</div>
<input type="number" id="dest_port" name="dest_port" x-model="destPort"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full ps-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="22" min="1" max="65535" />
placeholder="22" min="1" max="65535" x-init="if (!destPort || destPort === 0) destPort = 22" />
</div>
<p class="mt-2 text-sm text-gray-500 dark:text-gray-400">SFTP port number (default: 22)</p>
</div>
@@ -74,7 +74,7 @@ templ SFTPDestinationForm() {
<div class="absolute inset-y-0 start-0 flex items-center ps-3.5 pointer-events-none">
<i class="fas fa-key text-gray-400 dark:text-gray-500"></i>
</div>
<input type="text" id="dest_key_file" name="dest_key_file" x-model="destinationKeyFile"
<input type="text" id="dest_key_file" name="dest_key_file" x-model="destKeyFile"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full ps-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="/path/to/id_rsa" x-bind:required="destAuthType === 'key'" />
</div>
+1 -1
View File
@@ -23,7 +23,7 @@ templ FTPSourceForm() {
</div>
<input type="number" id="source_port" name="source_port" x-model="sourcePort"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full ps-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="21" min="1" max="65535" />
placeholder="21" min="1" max="65535" value="21"/>
</div>
<p class="mt-2 text-sm text-gray-500 dark:text-gray-400">FTP port number (default: 21)</p>
</div>
+2
View File
@@ -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",