From b1db53b89eeaaf436a734ec4a4dda0f44a291387 Mon Sep 17 00:00:00 2001 From: StarFleetCPTN Date: Sun, 16 Mar 2025 16:12:42 -0700 Subject: [PATCH] feat: Refactor Google Drive and Google Photos authentication handling - Separate built-in authentication options for source and destination in configuration forms. - Update UI components to reflect changes in authentication handling for Google Drive and Google Photos. - Implement path validation for local directories in the configuration forms, enhancing user experience. - Revise README to clarify supported source and destination types, including updated terminology for Google Drive. - Introduce new API endpoint for path validation, improving error handling and user feedback. --- README.md | 4 +- components/config_form.templ | 49 ++- components/configs.templ | 6 +- components/providers/common/common.templ | 2 +- components/providers/destination/gdrive.templ | 25 +- .../providers/destination/gphotos.templ | 29 +- components/providers/destination/local.templ | 25 +- components/providers/source/gdrive.templ | 21 +- components/providers/source/gphotos.templ | 23 +- components/providers/source/local.templ | 25 +- internal/api/api.go | 2 +- internal/db/db.go | 59 ++-- internal/db/db_test.go | 55 ++-- internal/db/migrations/001_initial_schema.go | 278 ++++++++++++++++++ .../002_update_builtin_auth_fields.go | 49 +++ .../db/migrations/003_update_gdrive_type.go | 31 ++ .../db/migrations/add_cloud_storage_fields.go | 63 ---- .../migrations/add_delete_after_transfer.go | 19 -- .../add_google_drive_authenticated.go | 21 -- .../migrations/add_google_photos_support.go | 61 ---- .../add_max_concurrent_transfers.go | 21 -- .../db/migrations/add_multi_config_support.go | 49 --- .../db/migrations/add_skip_processed_files.go | 21 -- internal/db/migrations/add_webhook_support.go | 61 ---- internal/db/migrations/migrations.go | 13 +- ...update_skip_processed_files_to_nullable.go | 70 ----- internal/db/rclone_test.go | 8 +- internal/web/handlers/config_handlers.go | 21 +- internal/web/handlers/gdrive_handlers.go | 6 +- internal/web/handlers/gdrive_handlers_test.go | 28 +- internal/web/handlers/path_handlers.go | 76 +++++ internal/web/handlers/routes.go | 3 + 32 files changed, 676 insertions(+), 548 deletions(-) create mode 100644 internal/db/migrations/001_initial_schema.go create mode 100644 internal/db/migrations/002_update_builtin_auth_fields.go create mode 100644 internal/db/migrations/003_update_gdrive_type.go delete mode 100644 internal/db/migrations/add_cloud_storage_fields.go delete mode 100644 internal/db/migrations/add_delete_after_transfer.go delete mode 100644 internal/db/migrations/add_google_drive_authenticated.go delete mode 100644 internal/db/migrations/add_google_photos_support.go delete mode 100644 internal/db/migrations/add_max_concurrent_transfers.go delete mode 100644 internal/db/migrations/add_multi_config_support.go delete mode 100644 internal/db/migrations/add_skip_processed_files.go delete mode 100644 internal/db/migrations/add_webhook_support.go delete mode 100644 internal/db/migrations/update_skip_processed_files_to_nullable.go create mode 100644 internal/web/handlers/path_handlers.go diff --git a/README.md b/README.md index 54968fb..e7a30a8 100644 --- a/README.md +++ b/README.md @@ -348,8 +348,8 @@ User management features: ### Transfer Configuration Options 1. **Source/Destination Types**: - - Google Drive (with built-in or custom authentication) - - Google Photos (with built-in or custom authentication) + - Google Drive + - Google Photos - Local filesystem - Amazon S3 - MinIO (S3-compatible storage) diff --git a/components/config_form.templ b/components/config_form.templ index 9ee1a18..710bc92 100644 --- a/components/config_form.templ +++ b/components/config_form.templ @@ -84,7 +84,8 @@ func getInitialData(config *db.TransferConfig) string { skipProcessedFiles := true maxConcurrentTransfers := 4 rcloneFlags := "" - useBuiltinAuth := true + useBuiltinAuthSource := true + useBuiltinAuthDest := true // If editing an existing config, populate with those values if config != nil { @@ -162,14 +163,19 @@ func getInitialData(config *db.TransferConfig) string { skipProcessedFiles = config.GetSkipProcessedFiles() maxConcurrentTransfers = config.MaxConcurrentTransfers rcloneFlags = config.RcloneFlags - if config.UseBuiltinAuth != nil { - useBuiltinAuth = *config.UseBuiltinAuth + if config.UseBuiltinAuthSource != nil { + useBuiltinAuthSource = *config.UseBuiltinAuthSource + } else if sourceClientId != "" || sourceClientSecret != "" { + useBuiltinAuthSource = false + } + if config.UseBuiltinAuthDest != nil { + useBuiltinAuthDest = *config.UseBuiltinAuthDest } else if destClientId != "" || destClientSecret != "" { - useBuiltinAuth = false + useBuiltinAuthDest = false } } - // Return the JSON-formatted string with all the data + // Return the JSON-formatted string with all the data, add new path validation states return fmt.Sprintf(`{ name: '%s', sourceType: '%s', @@ -223,7 +229,8 @@ func getInitialData(config *db.TransferConfig) string { destStartYear: %d, destIncludeArchived: %v, - useBuiltinAuth: %v, + useBuiltinAuthSource: %v, + useBuiltinAuthDest: %v, archivePath: '%s', archiveEnabled: %v, @@ -231,6 +238,32 @@ func getInitialData(config *db.TransferConfig) string { skipProcessedFiles: %v, maxConcurrentTransfers: %d, rcloneFlags: '%s', + + // Path validation states + sourcePathValid: null, + sourcePathError: '', + destPathValid: null, + destPathError: '', + + // Methods for path validation + checkPath(path, type) { + if (!path) { + this[type + 'PathValid'] = false; + this[type + 'PathError'] = 'Path cannot be empty'; + return; + } + + fetch('/check-path?path=' + encodeURIComponent(path)) + .then(response => response.json()) + .then(data => { + this[type + 'PathValid'] = data.valid; + this[type + 'PathError'] = data.error || ''; + }) + .catch(error => { + this[type + 'PathValid'] = false; + this[type + 'PathError'] = 'Error checking path: ' + error.message; + }); + } }`, name, sourceType, sourcePath, sourceHost, sourcePort, sourceUser, sourcePassword, sourceKeyFile, sourceAuthType, sourceBucket, sourceRegion, sourceAccessKey, sourceSecretKey, sourceEndpoint, sourceShare, sourceDomain, sourcePassiveMode, @@ -241,7 +274,7 @@ func getInitialData(config *db.TransferConfig) string { destBucket, destRegion, destAccessKey, destSecretKey, destEndpoint, destShare, destDomain, destPassiveMode, destClientId, destClientSecret, destDriveId, destTeamDrive, destReadOnly, destStartYear, destIncludeArchived, - useBuiltinAuth, + useBuiltinAuthSource, useBuiltinAuthDest, archivePath, archiveEnabled, deleteAfterTransfer, skipProcessedFiles, maxConcurrentTransfers, rcloneFlags) } @@ -321,7 +354,7 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) { @source.NextCloudSourceForm() -