mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 15:41:20 +02:00
feat: Add rclone config regeneration after API updates
- Implemented logic to regenerate the rclone config file after updating configurations in the database. - Added logging to capture warnings if the regeneration fails, while ensuring the update process continues smoothly. - Enhanced user feedback by logging successful regeneration of the rclone config.
This commit is contained in:
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -294,6 +295,12 @@ func handleUpdateConfig(database *db.DB) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// Regenerate the rclone config file
|
||||
if err := database.GenerateRcloneConfig(&updatedConfig); err != nil {
|
||||
// Log the error but continue anyway as the config was updated in the database
|
||||
log.Printf("Warning: Failed to regenerate rclone config after API update: %v", err)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, updatedConfig)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -142,6 +143,12 @@ func (h *Handlers) HandleAPIUpdateConfig(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Regenerate the rclone config file
|
||||
if err := h.DB.GenerateRcloneConfig(&config); err != nil {
|
||||
log.Printf("Warning: Failed to regenerate rclone config after API update: %v", err)
|
||||
// Continue anyway, as the config was updated in the database
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"config": config})
|
||||
}
|
||||
|
||||
|
||||
@@ -463,6 +463,14 @@ func (h *Handlers) HandleUpdateConfig(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Regenerate the rclone config file
|
||||
if err := h.DB.GenerateRcloneConfig(&config); err != nil {
|
||||
log.Printf("Warning: Failed to regenerate rclone config after update: %v", err)
|
||||
// Continue anyway, as the config was updated in the database
|
||||
} else {
|
||||
log.Printf("Regenerated rclone config for config ID %d after update", config.ID)
|
||||
}
|
||||
|
||||
// Redirect to the configs page
|
||||
c.Redirect(http.StatusSeeOther, "/configs")
|
||||
}
|
||||
|
||||
@@ -101,16 +101,14 @@ func (h *Handlers) HandleGDriveAuth(c *gin.Context) {
|
||||
}
|
||||
|
||||
if config.DestClientID != "" && config.DestClientSecret == "" {
|
||||
// If user provided just client ID but no secret, try to find the secret in the config
|
||||
_, existingClientSecret := h.DB.GetGDriveCredentialsFromConfig(config)
|
||||
|
||||
if existingClientSecret != "" {
|
||||
// Use the secret from the existing config with the provided client ID
|
||||
clientSecret = existingClientSecret
|
||||
// If user provided just client ID but no secret, use environment variable or default
|
||||
envSecret := os.Getenv("GOOGLE_CLIENT_SECRET")
|
||||
if envSecret != "" {
|
||||
// Use the secret from environment variable
|
||||
clientSecret = envSecret
|
||||
} else {
|
||||
// If we still can't find a matching secret, show an error
|
||||
RenderErrorPage(c, "Missing client secret", "You provided a custom client ID but no client secret. Both are required for Google authentication.")
|
||||
return
|
||||
// Use default rclone client secret
|
||||
clientSecret = "X4Z3ca8xfWDb1Voo-F9a7ZxJ"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,16 +237,14 @@ func (h *Handlers) HandleGDriveAuthCallback(c *gin.Context) {
|
||||
}
|
||||
|
||||
if config.DestClientID != "" && config.DestClientSecret == "" {
|
||||
// If user provided just client ID but no secret, try to find the secret in the config
|
||||
_, existingClientSecret := h.DB.GetGDriveCredentialsFromConfig(config)
|
||||
|
||||
if existingClientSecret != "" {
|
||||
// Use the secret from the existing config with the provided client ID
|
||||
clientSecret = existingClientSecret
|
||||
// If user provided just client ID but no secret, use environment variable or default
|
||||
envSecret := os.Getenv("GOOGLE_CLIENT_SECRET")
|
||||
if envSecret != "" {
|
||||
// Use the secret from environment variable
|
||||
clientSecret = envSecret
|
||||
} else {
|
||||
// If we still can't find a matching secret, show an error
|
||||
RenderErrorPage(c, "Missing client secret", "You provided a custom client ID but no client secret. Both are required for Google authentication.")
|
||||
return
|
||||
// Use default rclone client secret
|
||||
clientSecret = "X4Z3ca8xfWDb1Voo-F9a7ZxJ"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user