mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-11-11 06:17:58 +01:00
Merge branch 'transfer-calendar' into development
This commit is contained in:
commit
98e20ea843
22 files changed
+1258
-95
No files matched your search
@@ -248,7 +248,7 @@ func extractSourceProviderConfig(config *TransferConfig) *ProviderConfig {
|
||||
}
|
||||
|
||||
// Special handling for OAuth authentication status
|
||||
if config.SourceType == "gdrive" || config.SourceType == "gphotos" {
|
||||
if config.SourceType == "drive" || config.SourceType == "gphotos" {
|
||||
authenticated := config.GetGoogleAuthenticated()
|
||||
sourceConfig.Authenticated = &authenticated
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func extractDestinationProviderConfig(config *TransferConfig) *ProviderConfig {
|
||||
}
|
||||
|
||||
// Special handling for OAuth authentication status
|
||||
if config.DestinationType == "gdrive" || config.DestinationType == "gphotos" {
|
||||
if config.DestinationType == "drive" || config.DestinationType == "gphotos" {
|
||||
authenticated := config.GetGoogleAuthenticated()
|
||||
destConfig.Authenticated = &authenticated
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ const (
|
||||
ProviderTypeSFTP StorageProviderType = "sftp"
|
||||
ProviderTypeS3 StorageProviderType = "s3"
|
||||
ProviderTypeOneDrive StorageProviderType = "onedrive"
|
||||
ProviderTypeGoogleDrive StorageProviderType = "gdrive"
|
||||
ProviderTypeGoogleDrive StorageProviderType = "drive"
|
||||
ProviderTypeGooglePhoto StorageProviderType = "gphotos"
|
||||
ProviderTypeFTP StorageProviderType = "ftp"
|
||||
ProviderTypeSMB StorageProviderType = "smb"
|
||||
|
||||
@@ -465,7 +465,7 @@ func (db *DB) GenerateRcloneConfig(config *TransferConfig) error {
|
||||
if err := os.WriteFile(configPath, []byte(content), 0600); err != nil {
|
||||
return fmt.Errorf("failed to write source config (local): %v", err)
|
||||
}
|
||||
case "gdrive":
|
||||
case "drive":
|
||||
// For Google Drive, we need client ID and secret
|
||||
clientID := getStringValue(sourceCredentials, "client_id", config.SourceClientID)
|
||||
|
||||
@@ -1018,7 +1018,7 @@ func (db *DB) GenerateRcloneConfig(config *TransferConfig) error {
|
||||
if _, err := f.WriteString(content); err != nil {
|
||||
return fmt.Errorf("failed to write destination config (local): %v", err)
|
||||
}
|
||||
case "gdrive":
|
||||
case "drive":
|
||||
// For Google Drive, we need client ID and secret
|
||||
clientID := getStringValue(destCredentials, "client_id", config.DestClientID)
|
||||
|
||||
@@ -1244,7 +1244,7 @@ func (db *DB) StoreGoogleDriveToken(configIDStr string, token string) error {
|
||||
|
||||
// Check if we're using a provider reference and update the provider instead
|
||||
if config.IsUsingDestinationProviderReference() && config.DestinationProvider != nil &&
|
||||
(config.DestinationProvider.Type == "gdrive" || config.DestinationProvider.Type == "gphotos") {
|
||||
(config.DestinationProvider.Type == "drive" || config.DestinationProvider.Type == "gphotos") {
|
||||
// Update the provider with the token
|
||||
provider := config.DestinationProvider
|
||||
provider.RefreshToken = token // Set the clear token temporarily
|
||||
@@ -1257,7 +1257,7 @@ func (db *DB) StoreGoogleDriveToken(configIDStr string, token string) error {
|
||||
|
||||
// Continue with creating the rclone config file since this is still needed for transfers
|
||||
} else if config.IsUsingSourceProviderReference() && config.SourceProvider != nil &&
|
||||
(config.SourceProvider.Type == "gdrive" || config.SourceProvider.Type == "gphotos") {
|
||||
(config.SourceProvider.Type == "drive" || config.SourceProvider.Type == "gphotos") {
|
||||
// Update the provider with the token
|
||||
provider := config.SourceProvider
|
||||
provider.RefreshToken = token // Set the clear token temporarily
|
||||
@@ -1338,7 +1338,7 @@ func (db *DB) GenerateRcloneConfigWithToken(config *TransferConfig, token string
|
||||
var startYear int
|
||||
|
||||
// Determine if source or destination needs token update
|
||||
if config.DestinationType == "gdrive" || config.DestinationType == "gphotos" {
|
||||
if config.DestinationType == "drive" || config.DestinationType == "gphotos" {
|
||||
configType = config.DestinationType
|
||||
section = "dest"
|
||||
clientID = config.DestClientID
|
||||
@@ -1346,7 +1346,7 @@ func (db *DB) GenerateRcloneConfigWithToken(config *TransferConfig, token string
|
||||
readOnly = config.DestReadOnly
|
||||
startYear = config.DestStartYear
|
||||
includeArchived = config.DestIncludeArchived
|
||||
} else if config.SourceType == "gdrive" || config.SourceType == "gphotos" {
|
||||
} else if config.SourceType == "drive" || config.SourceType == "gphotos" {
|
||||
configType = config.SourceType
|
||||
section = "source"
|
||||
clientID = config.SourceClientID
|
||||
@@ -1367,7 +1367,7 @@ func (db *DB) GenerateRcloneConfigWithToken(config *TransferConfig, token string
|
||||
var sectionContent string
|
||||
sectionHeader := fmt.Sprintf("[%s_%d]", section, config.ID)
|
||||
|
||||
if configType == "gdrive" {
|
||||
if configType == "drive" {
|
||||
sectionContent = sectionHeader + "\ntype = drive\n"
|
||||
if clientID != "" {
|
||||
sectionContent += fmt.Sprintf("client_id = %s\n", clientID)
|
||||
@@ -1432,9 +1432,9 @@ func (db *DB) GenerateRcloneConfigWithToken(config *TransferConfig, token string
|
||||
|
||||
// Update the authentication status in DB
|
||||
authenticated := true
|
||||
if config.DestinationType == "gdrive" || config.DestinationType == "gphotos" {
|
||||
if config.DestinationType == "drive" || config.DestinationType == "gphotos" {
|
||||
config.SetGoogleAuthenticated(authenticated)
|
||||
} else if config.SourceType == "gdrive" || config.SourceType == "gphotos" {
|
||||
} else if config.SourceType == "drive" || config.SourceType == "gphotos" {
|
||||
config.SetGoogleAuthenticated(authenticated)
|
||||
}
|
||||
// Persist the change (assuming UpdateTransferConfig saves the whole object)
|
||||
@@ -1624,7 +1624,7 @@ func (db *DB) ConvertToProviderReferences(config *TransferConfig) error {
|
||||
}
|
||||
|
||||
// For Google Drive/Photos, carry over authentication status
|
||||
if config.DestinationType == "gdrive" || config.DestinationType == "gphotos" {
|
||||
if config.DestinationType == "drive" || config.DestinationType == "gphotos" {
|
||||
provider.SetAuthenticated(config.GetGoogleAuthenticated())
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ func TestRcloneConnection(config db.TransferConfig, providerType string, dbInsta
|
||||
if pass != "" {
|
||||
createArgs = append(createArgs, "pass", pass)
|
||||
}
|
||||
case "gdrive":
|
||||
case "drive":
|
||||
createArgs = append(createArgs, "scope", "drive")
|
||||
if clientID != "" {
|
||||
createArgs = append(createArgs, "client_id", clientID)
|
||||
|
||||
@@ -37,7 +37,7 @@ func (h *Handlers) HandleGDriveAuth(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Ensure it's a Google Drive or Google Photos configuration
|
||||
if config.SourceType != "gdrive" && config.DestinationType != "gdrive" && config.SourceType != "gphotos" && config.DestinationType != "gphotos" {
|
||||
if config.SourceType != "drive" && config.DestinationType != "drive" && config.SourceType != "gphotos" && config.DestinationType != "gphotos" {
|
||||
RenderErrorPage(c, "Not a Google configuration", "The selected configuration is not set up for Google Drive or Google Photos")
|
||||
return
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (h *Handlers) HandleGDriveAuth(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Create a config file with redirect URI-based auth
|
||||
configType := "gdrive"
|
||||
configType := "drive"
|
||||
if config.DestinationType == "gphotos" {
|
||||
configType = "gphotos"
|
||||
}
|
||||
@@ -362,7 +362,7 @@ func (h *Handlers) HandleGDriveTokenProcess(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Ensure it's a Google Drive or Google Photos configuration
|
||||
if config.SourceType != "gdrive" && config.DestinationType != "gdrive" && config.SourceType != "gphotos" && config.DestinationType != "gphotos" {
|
||||
if config.SourceType != "drive" && config.DestinationType != "drive" && config.SourceType != "gphotos" && config.DestinationType != "gphotos" {
|
||||
RenderErrorPage(c, "Not a Google Drive configuration", "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -42,6 +42,23 @@ func (h *Handlers) HandleJobs(c *gin.Context) {
|
||||
components.Jobs(c, data).Render(c, c.Writer)
|
||||
}
|
||||
|
||||
// HandleCalendarView handles the GET /calendar route
|
||||
func (h *Handlers) HandleCalendarView(c *gin.Context) {
|
||||
userID := c.GetUint("userID")
|
||||
|
||||
// Get all jobs with Next Run time for this user
|
||||
var jobs []db.Job
|
||||
h.DB.Where("created_by = ?", userID).Preload("Config").Find(&jobs)
|
||||
|
||||
// Prepare data for the calendar view
|
||||
data := components.JobCalendarData{
|
||||
Jobs: jobs,
|
||||
}
|
||||
|
||||
// Render the calendar view
|
||||
components.JobCalendar(c, data).Render(c, c.Writer)
|
||||
}
|
||||
|
||||
// HandleJobRunDetails handles the GET /job/:id route
|
||||
func (h *Handlers) HandleJobRunDetails(c *gin.Context) {
|
||||
userID := c.GetUint("userID")
|
||||
|
||||
@@ -109,6 +109,10 @@ func (h *Handlers) RegisterRoutes(router *gin.Engine) {
|
||||
authorized.POST("/jobs/:id/run", h.HandleRunJob)
|
||||
authorized.GET("/history", h.HandleHistory)
|
||||
authorized.GET("/job-runs/:id", h.HandleJobRunDetails)
|
||||
|
||||
// Calendar view route
|
||||
authorized.GET("/calendar", h.HandleCalendarView)
|
||||
|
||||
authorized.GET("/profile", h.HandleProfile)
|
||||
authorized.POST("/profile/theme", h.HandleUpdateTheme)
|
||||
authorized.POST("/logout", h.HandleLogout)
|
||||
|
||||
@@ -39,7 +39,7 @@ func (h *Handlers) HandleStorageProviderGDriveAuth(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Ensure it's a Google Drive or Google Photos provider
|
||||
if provider.Type != "gdrive" && provider.Type != "gphotos" {
|
||||
if provider.Type != "drive" && provider.Type != "gphotos" {
|
||||
RenderErrorPage(c, "Not a Google provider", "The selected provider is not set up for Google Drive or Google Photos")
|
||||
return
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (h *Handlers) HandleStorageProviderGDriveAuth(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Create a config file with redirect URI-based auth
|
||||
configType := "gdrive"
|
||||
configType := "drive"
|
||||
if provider.Type == "gphotos" {
|
||||
configType = "gphotos"
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func (h *Handlers) HandleStorageProviderGDriveTokenProcess(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Ensure it's a Google Drive or Google Photos provider
|
||||
if provider.Type != "gdrive" && provider.Type != "gphotos" {
|
||||
if provider.Type != "drive" && provider.Type != "gphotos" {
|
||||
RenderErrorPage(c, "Not a Google provider", "")
|
||||
return
|
||||
}
|
||||
@@ -378,15 +378,15 @@ func (h *Handlers) HandleStorageProviderGDriveHeadlessAuth(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Ensure it's a Google Drive or Google Photos provider
|
||||
if provider.Type != "gdrive" && provider.Type != "gphotos" {
|
||||
if provider.Type != "drive" && provider.Type != "gphotos" {
|
||||
RenderErrorPage(c, "Not a Google provider", "The selected provider is not set up for Google Drive or Google Photos")
|
||||
return
|
||||
}
|
||||
|
||||
// Determine which Google service we're authenticating with
|
||||
var serviceType string
|
||||
if provider.Type == "gdrive" {
|
||||
serviceType = "gdrive"
|
||||
if provider.Type == "drive" {
|
||||
serviceType = "drive"
|
||||
} else {
|
||||
serviceType = "gphotos"
|
||||
}
|
||||
|
||||
@@ -898,7 +898,7 @@ func storageProviderFromRcloneSection(name string, section map[string]string, us
|
||||
}
|
||||
// Optionally: you can check for known types and set generic if not recognized
|
||||
knownTypes := map[string]bool{
|
||||
"sftp": true, "s3": true, "onedrive": true, "gdrive": true, "gphotos": true, "ftp": true, "smb": true, "hetzner": true, "local": true, "webdav": true, "nextcloud": true, "b2": true, "wasabi": true, "minio": true,
|
||||
"sftp": true, "s3": true, "onedrive": true, "drive": true, "gphotos": true, "ftp": true, "smb": true, "hetzner": true, "local": true, "webdav": true, "nextcloud": true, "b2": true, "wasabi": true, "minio": true,
|
||||
}
|
||||
if !knownTypes[providerType] {
|
||||
providerType = string(db.ProviderTypeGeneric)
|
||||
|
||||
@@ -426,7 +426,7 @@ func TestInputValidation(t *testing.T) {
|
||||
"ftp": true,
|
||||
"smb": true,
|
||||
"onedrive": true,
|
||||
"gdrive": true,
|
||||
"drive": true,
|
||||
"gphotos": true,
|
||||
"hetzner": true,
|
||||
"local": true,
|
||||
|
||||
Reference in new issue
Block a user