feat: Add connection testing functionality for Rclone providers

- Introduced a new endpoint to test connections for source and destination providers.
- Implemented a TestResult component to display success or error messages based on connection outcomes.
- Enhanced the configuration form with buttons to initiate connection tests, improving user experience.
- Updated backend logic to handle connection testing and return appropriate feedback to the frontend.
- Refactored existing handlers and routes to accommodate the new testing functionality.
This commit is contained in:
StarFleetCPTN committed 2025-03-29 11:27:48 -07:00
1 parent f95720758e
commit 68dd9fc173
7 files changed
+452 -4

No files matched your search

+32 -3
View File
@@ -459,6 +459,9 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) {
<i class="fas fa-terminal mr-2 text-blue-500 dark:text-blue-400"></i>Command Configuration
</h3>
<!-- Additonal Rclone Flags -->
@common.RcloneFlags(data.Config.CommandID) // Pass current command ID
<!-- Container for flags, pre-rendered on edit, loaded via HTMX on new/change -->
<div id="command-flags-container" class="mt-4">
if !data.IsNew && data.InitialCommand != nil {
@@ -467,9 +470,7 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) {
}
</div>
<!-- Additonal Rclone Flags -->
@common.RcloneFlags(data.Config.CommandID) // Pass current command ID
</div>
<!-- Source Configuration Section -->
@@ -481,6 +482,20 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) {
<!-- Source selection -->
@common.SourceSelection()
<div class="mt-4">
<button type="button"
class="text-white bg-green-600 hover:bg-green-700 focus:ring-4 focus:ring-green-300 font-medium rounded-lg text-sm px-4 py-2 text-center dark:bg-green-500 dark:hover:bg-green-600 dark:focus:ring-green-800"
hx-post="/configs/test-connection"
hx-include="closest form"
hx-vals='{"providerType": "source"}'
hx-swap="none"
hx-indicator="#source-test-spinner">
<i class="fas fa-plug mr-1"></i> Test Source
<span id="source-test-spinner" class="htmx-indicator ml-2"><i class="fas fa-spinner fa-spin"></i></span>
</button>
<!-- Removed target div, result shown via toast -->
</div>
<!-- Source type specific forms -->
<template x-if="sourceType === 'local'">
@source.LocalSourceForm()
@@ -542,6 +557,20 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) {
<!-- Destination selection -->
@common.DestinationSelection()
<div class="mt-4">
<button type="button"
class="text-white bg-green-600 hover:bg-green-700 focus:ring-4 focus:ring-green-300 font-medium rounded-lg text-sm px-4 py-2 text-center dark:bg-green-500 dark:hover:bg-green-600 dark:focus:ring-green-800"
hx-post="/configs/test-connection"
hx-include="closest form"
hx-vals='{"providerType": "destination"}'
hx-swap="none"
hx-indicator="#dest-test-spinner">
<i class="fas fa-plug mr-1"></i> Test Destination
<span id="dest-test-spinner" class="htmx-indicator ml-2"><i class="fas fa-spinner fa-spin"></i></span>
</button>
<!-- Removed target div, result shown via toast -->
</div>
<!-- Destination type specific forms -->
<template x-if="destinationType === 'local'">
@destination.LocalDestinationForm()
+1 -1
View File
@@ -235,7 +235,7 @@ templ RcloneCommandOptionsContent(categoryMap map[string][]db.RcloneCommand, cat
<select id="command_id" name="command_id" x-model="commandId"
hx-get="/api/rclone/command-flags"
hx-target="#command-flags-container"
hx-trigger="load, change"
hx-trigger="change"
hx-include="[name='command_id']"
hx-vals={ fmt.Sprintf(`{"commandFlags": %s, "commandFlagValues": %s}`, commandFlagsJSON, commandFlagValuesJSON) }
@change="updateCommandRequirements()"
+15
View File
@@ -0,0 +1,15 @@
package components
templ TestResult(success bool, message string) {
if success {
<div class="text-green-600 dark:text-green-400 flex items-center">
<i class="fas fa-check-circle mr-2"></i>
<span>{ message }</span>
</div>
} else {
<div class="text-red-600 dark:text-red-400 flex items-center">
<i class="fas fa-exclamation-triangle mr-2"></i>
<span>{ message }</span>
</div>
}
}