feat: Update storage provider form and validation enhancements

- Added new HTML elements and JavaScript functionality to improve the user experience for WebDAV and Hetzner storage providers.
- Updated form field descriptions and placeholders for clarity, ensuring users understand the required input.
- Enhanced validation logic for WebDAV to ensure the host includes the protocol.
- Improved logging for debugging during form submissions, particularly for WebDAV credentials.
- Removed the deprecated provider form component to streamline the codebase.
This commit is contained in:
StarFleetCPTN committed 2025-04-18 03:54:48 -07:00
1 parent dc665b9fa4
commit b819162732
6 files changed
+314 -200

No files matched your search

+1 -1
View File
@@ -184,7 +184,7 @@ func (sp *StorageProvider) GetSensitiveFields() map[string]string {
// Add fields based on provider type
switch sp.Type {
case ProviderTypeSFTP, ProviderTypeFTP, ProviderTypeSMB, ProviderTypeHetzner:
case ProviderTypeSFTP, ProviderTypeFTP, ProviderTypeSMB, ProviderTypeHetzner, ProviderTypeWebDAV, ProviderTypeNextcloud:
if sp.Password != "" {
sensitiveFields["Password"] = sp.Password
}
@@ -75,6 +75,11 @@ func (sp *StorageProvider) validateWebDAV() error {
return errors.New("host is required for WebDAV provider")
}
// Host must include the protocol
if !strings.HasPrefix(sp.Host, "http://") && !strings.HasPrefix(sp.Host, "https://") {
return errors.New("host must include the protocol (http:// or https://)")
}
if strings.TrimSpace(sp.Username) == "" {
return errors.New("username is required for WebDAV provider")
}
+23 -4
View File
@@ -399,7 +399,8 @@ func (db *DB) GenerateRcloneConfig(config *TransferConfig) error {
case "webdav", "nextcloud": // Handle both webdav and nextcloud similarly
// Construct the WebDAV URL
// Parse the provided source URL, assuming it includes the scheme
inputURL := config.SourceHost
inputURL := getStringValue(sourceCredentials, "host", config.SourceHost)
fmt.Printf("Input URL: %s\n", inputURL)
parsedURL, err := url.Parse(inputURL)
if err != nil {
return fmt.Errorf("failed to parse source URL '%s': %v", inputURL, err)
@@ -424,12 +425,30 @@ func (db *DB) GenerateRcloneConfig(config *TransferConfig) error {
"config", "create", sourceName, "webdav",
"url", webdavURL,
"vendor", vendor,
"user", config.SourceUser,
"pass", config.SourcePassword, // rclone obscures this
"user", getStringValue(sourceCredentials, "username", config.SourceUser),
"--non-interactive",
"--config", configPath,
"--log-level", "ERROR",
}
// Handle password
password := ""
if config.SourcePassword != "" {
password = config.SourcePassword
} else if encryptedPwd, ok := sourceCredentials["encrypted_password"].(string); ok && encryptedPwd != "" {
decryptedPwd, err := db.DecryptCredential(encryptedPwd)
if err != nil {
return fmt.Errorf("failed to decrypt source password: %v", err)
}
password = decryptedPwd
} else if pwVal, ok := sourceCredentials["password"].(string); ok && pwVal != "" {
password = pwVal
}
if password != "" {
args = append(args, "pass", password)
}
cmd := exec.Command(rclonePath, args...)
if output, err := cmd.CombinedOutput(); err != nil {
errorMsg := fmt.Sprintf("failed to create source config (%s): %v", config.SourceType, err)
@@ -751,7 +770,7 @@ func (db *DB) GenerateRcloneConfig(config *TransferConfig) error {
case "webdav", "nextcloud": // Combined case for WebDAV and Nextcloud
// Parse and reconstruct the WebDAV URL robustly
// Parse the provided destination URL, assuming it includes the scheme
inputURL := config.DestHost
inputURL := getStringValue(destCredentials, "host", config.DestHost)
parsedURL, err := url.Parse(inputURL)
if err != nil {
return fmt.Errorf("failed to parse destination URL '%s': %v", inputURL, err)
@@ -2,6 +2,7 @@ package handlers
import (
"fmt"
"log"
"net/http"
"strconv"
"strings"
@@ -446,6 +447,19 @@ func (h *Handlers) parseProviderFromForm(c *gin.Context) (db.StorageProvider, er
provider.Username = c.PostForm("username")
provider.Password = c.PostForm("password")
// Log for debugging
log.Printf("WebDAV provider: username=%s, password present=%v",
provider.Username, provider.Password != "")
// WebDAV uses Host without port (full URL)
if provider.Host == "" {
return provider, fmt.Errorf("host/URL is required for WebDAV provider")
}
if provider.Username == "" {
return provider, fmt.Errorf("username is required for WebDAV provider")
}
case db.ProviderTypeS3, db.ProviderTypeWasabi, db.ProviderTypeMinio, db.ProviderTypeB2:
// S3 specific fields
provider.AccessKey = c.PostForm("accessKey")