From dc665b9fa428de3b85c33d3f7a17c37803189d27 Mon Sep 17 00:00:00 2001 From: StarFleetCPTN Date: Fri, 18 Apr 2025 02:43:22 -0700 Subject: [PATCH] feat: Enhance configuration forms and validation for storage providers - Added hidden input fields to ensure critical values are submitted with the form for S3 and other storage providers. - Implemented JavaScript functionality to auto-populate hidden fields based on user input for S3-compatible providers. - Updated validation logic for WebDAV and SMB providers to ensure required fields are checked. - Enhanced the configuration handler to explicitly set fields for various storage provider types, including S3, Wasabi, MinIO, and B2. - Improved error handling and logging for form submissions and provider credential management. --- components/config_form.templ | 68 +++++ components/storage_provider_form.templ | 218 +++++++++++++++- internal/db/storage_provider.go | 4 +- internal/db/storage_provider_validator.go | 24 +- internal/db/transfer_config_store.go | 238 +++++++++++++++++- internal/storage/connector_service.go | 17 +- internal/web/handlers/config_handlers.go | 106 ++++++++ .../web/handlers/storage_provider_handlers.go | 16 +- 8 files changed, 661 insertions(+), 30 deletions(-) diff --git a/components/config_form.templ b/components/config_form.templ index ff377fe..90e685f 100644 --- a/components/config_form.templ +++ b/components/config_form.templ @@ -457,6 +457,29 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) { // Initialize command requirements updateCommandRequirements(); + + // Initialize hidden input fields with their values to ensure they're included in form submission + document.getElementById('hidden_name').value = name; + document.getElementById('hidden_source_path').value = sourcePath; + document.getElementById('hidden_destination_path').value = destinationPath; + + // Initialize S3 source fields if applicable + if (sourceType === 's3' || sourceType === 'b2' || sourceType === 'wasabi' || sourceType === 'minio') { + document.getElementById('hidden_source_access_key').value = sourceAccessKey; + document.getElementById('hidden_source_secret_key').value = sourceSecretKey; + document.getElementById('hidden_source_endpoint').value = sourceEndpoint; + document.getElementById('hidden_source_bucket').value = sourceBucket; + document.getElementById('hidden_source_region').value = sourceRegion; + } + + // Initialize S3 destination fields if applicable + if (destinationType === 's3' || destinationType === 'b2' || destinationType === 'wasabi' || destinationType === 'minio') { + document.getElementById('hidden_dest_access_key').value = destAccessKey; + document.getElementById('hidden_dest_secret_key').value = destSecretKey; + document.getElementById('hidden_dest_endpoint').value = destEndpoint; + document.getElementById('hidden_dest_bucket').value = destBucket; + document.getElementById('hidden_dest_region').value = destRegion; + } })" x-effect="if (sourceType === 'sftp' && (sourcePort === 0 || sourcePort === 21 || sourcePort === 23)) { sourcePort = 22; @@ -478,8 +501,50 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) { console.log('Updating destination port to 23 for Hetzner'); }" @formvalidation + @submit=" + // Basic fields + document.getElementById('hidden_name').value = name; + document.getElementById('hidden_source_path').value = sourcePath; + document.getElementById('hidden_destination_path').value = destinationPath; + + // S3 source fields + if (sourceType === 's3' || sourceType === 'b2' || sourceType === 'wasabi' || sourceType === 'minio') { + document.getElementById('hidden_source_access_key').value = sourceAccessKey; + document.getElementById('hidden_source_secret_key').value = sourceSecretKey; + document.getElementById('hidden_source_endpoint').value = sourceEndpoint; + document.getElementById('hidden_source_bucket').value = sourceBucket; + document.getElementById('hidden_source_region').value = sourceRegion; + } + + // S3 destination fields + if (destinationType === 's3' || destinationType === 'b2' || destinationType === 'wasabi' || destinationType === 'minio') { + document.getElementById('hidden_dest_access_key').value = destAccessKey; + document.getElementById('hidden_dest_secret_key').value = destSecretKey; + document.getElementById('hidden_dest_endpoint').value = destEndpoint; + document.getElementById('hidden_dest_bucket').value = destBucket; + document.getElementById('hidden_dest_region').value = destRegion; + } + " > + + + + + + + + + + + + + + + + + +