db

package
v0.2.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRcloneFlags added in v0.2.0

func ParseRcloneFlags(flagsStr string) map[string]string

ParseRcloneFlags parses a string of rclone flags into a map Note: This is a general utility function, not tied to a specific struct instance. It might be better placed in a more general utility package if one exists, but keeping it here for now as per the original file structure.

Types

type AuditLog added in v0.2.0

type AuditLog struct {
	gorm.Model
	Action     string          `gorm:"size:50;not null;index"`
	EntityType string          `gorm:"size:50;not null;index"`
	EntityID   uint            `gorm:"not null;index"`
	UserID     uint            `gorm:"not null;index"`
	Details    AuditLogDetails `gorm:"type:json"`
	Timestamp  time.Time       `gorm:"not null;index;default:CURRENT_TIMESTAMP"`
}

AuditLog represents an audit trail entry in the system

type AuditLogDetails added in v0.2.0

type AuditLogDetails map[string]interface{}

AuditLogDetails is a custom type for storing audit log details as JSON

func (*AuditLogDetails) Scan added in v0.2.0

func (d *AuditLogDetails) Scan(value interface{}) error

Scan implements the sql.Scanner interface

func (AuditLogDetails) Value added in v0.2.0

func (d AuditLogDetails) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type AuthProvider added in v0.2.0

type AuthProvider struct {
	ID               uint         `gorm:"primarykey" json:"id"`
	Name             string       `gorm:"not null" json:"name"`
	Type             ProviderType `gorm:"not null" json:"type"`
	Enabled          *bool        `gorm:"default:true" json:"enabled"`
	Description      string       `json:"description"`
	ProviderURL      string       `json:"provider_url"`
	ClientID         string       `json:"client_id"`
	ClientSecret     string       `json:"-"` // Not returned in JSON responses
	RedirectURL      string       `json:"redirect_url"`
	Scopes           string       `json:"scopes"`
	AttributeMapping string       `json:"attribute_mapping"`
	Config           string       `json:"-"`        // Stores provider-specific configuration
	IconURL          string       `json:"icon_url"` // URL to provider icon
	SuccessfulLogins int          `json:"successful_logins"`
	LastUsed         sql.NullTime `json:"last_used"`
	CreatedAt        time.Time    `json:"created_at"`
	UpdatedAt        time.Time    `json:"updated_at"`
	// contains filtered or unexported fields
}

AuthProvider represents an external authentication provider configuration

func (*AuthProvider) GetConfig added in v0.2.0

func (p *AuthProvider) GetConfig() (map[string]interface{}, error)

GetConfig returns the unmarshalled configuration data

func (*AuthProvider) GetEnabled added in v0.2.4

func (p *AuthProvider) GetEnabled() bool

GetEnabled returns the value of Enabled with a default if nil

func (*AuthProvider) SetConfig added in v0.2.0

func (p *AuthProvider) SetConfig(data map[string]interface{}) error

SetConfig sets the configuration data and marshals it to JSON

func (*AuthProvider) SetEnabled added in v0.2.4

func (p *AuthProvider) SetEnabled(value bool)

SetEnabled sets the Enabled field

type DB

type DB struct {
	*gorm.DB
}

func Initialize

func Initialize(dbPath string) (*DB, error)

func ReopenWithoutMigrations added in v0.2.0

func ReopenWithoutMigrations(dbPath string) (*DB, error)

ReopenWithoutMigrations reopens the database connection without running migrations This should be used when temporarily closing and reopening the database

func (*DB) AssignRoleToUser added in v0.2.0

func (db *DB) AssignRoleToUser(roleID, userID, assignedByID uint) error

AssignRoleToUser assigns a role to a user, handling the join table

func (*DB) BuildRcloneCommand added in v0.2.0

func (db *DB) BuildRcloneCommand(commandName string, flags map[string]string) (string, error)

BuildRcloneCommand builds an rclone command string with the specified command and flags

func (*DB) Close

func (db *DB) Close() error

func (*DB) CountExternalUserIdentitiesByProviderID added in v0.2.0

func (db *DB) CountExternalUserIdentitiesByProviderID(ctx context.Context, providerID uint) (int64, error)

CountExternalUserIdentitiesByProviderID counts the number of external user identities for a specific provider

func (*DB) CreateAuthProvider added in v0.2.0

func (db *DB) CreateAuthProvider(ctx context.Context, provider *AuthProvider) error

CreateAuthProvider creates a new authentication provider

func (*DB) CreateConfigNotification added in v0.2.0

func (db *DB) CreateConfigNotification(
	userID uint,
	configID uint,
	title string,
	message string,
) error

CreateConfigNotification creates a notification for a config update

func (*DB) CreateExternalUserIdentity added in v0.2.0

func (db *DB) CreateExternalUserIdentity(ctx context.Context, identity *ExternalUserIdentity) error

CreateExternalUserIdentity creates a new external user identity

func (*DB) CreateFileMetadata added in v0.1.7

func (db *DB) CreateFileMetadata(metadata *FileMetadata) error

CreateFileMetadata creates a new file metadata record

func (*DB) CreateJob

func (db *DB) CreateJob(job *Job) error

CreateJob creates a new job record

func (*DB) CreateJobHistory

func (db *DB) CreateJobHistory(history *JobHistory) error

CreateJobHistory creates a new job history record

func (*DB) CreateJobNotification added in v0.2.0

func (db *DB) CreateJobNotification(
	userID uint,
	jobID uint,
	jobRunID uint,
	notificationType NotificationType,
	title string,
	message string,
) error

CreateJobNotification creates a notification for a job event

func (*DB) CreateNotificationService added in v0.2.0

func (db *DB) CreateNotificationService(service *NotificationService) error

CreateNotificationService creates a new notification service

func (*DB) CreatePasswordResetToken

func (db *DB) CreatePasswordResetToken(token *PasswordResetToken) error

CreatePasswordResetToken creates a new password reset token record

func (*DB) CreateRole added in v0.2.0

func (db *DB) CreateRole(role *Role) error

CreateRole creates a new role record

func (*DB) CreateSystemNotification added in v0.2.0

func (db *DB) CreateSystemNotification(
	title string,
	message string,
) error

CreateSystemNotification creates a system-wide notification

func (*DB) CreateTransferConfig

func (db *DB) CreateTransferConfig(config *TransferConfig) error

CreateTransferConfig creates a new transfer config record

func (*DB) CreateUser

func (db *DB) CreateUser(user *User) error

CreateUser creates a new user record

func (*DB) DeleteAuthProvider added in v0.2.0

func (db *DB) DeleteAuthProvider(ctx context.Context, id uint) error

DeleteAuthProvider deletes an authentication provider by ID

func (*DB) DeleteExternalUserIdentity added in v0.2.0

func (db *DB) DeleteExternalUserIdentity(ctx context.Context, id uint) error

DeleteExternalUserIdentity deletes an external user identity by ID

func (*DB) DeleteFileMetadata added in v0.1.7

func (db *DB) DeleteFileMetadata(id uint) error

DeleteFileMetadata deletes file metadata by ID

func (*DB) DeleteJob

func (db *DB) DeleteJob(id uint) error

DeleteJob deletes a job and its associated history records

func (*DB) DeleteNotificationService added in v0.2.0

func (db *DB) DeleteNotificationService(id uint) error

DeleteNotificationService deletes a notification service by ID

func (*DB) DeleteRole added in v0.2.0

func (db *DB) DeleteRole(id uint) error

DeleteRole deletes a role after checking dependencies and removing assignments

func (*DB) DeleteTransferConfig

func (db *DB) DeleteTransferConfig(id uint) error

DeleteTransferConfig deletes a transfer config record after checking dependencies

func (*DB) GenerateRcloneConfig

func (db *DB) GenerateRcloneConfig(config *TransferConfig) error

GenerateRcloneConfig generates the rclone config file content based on TransferConfig This function now primarily focuses on generating the content string or calling rclone config create

func (*DB) GenerateRcloneConfigWithToken added in v0.1.10

func (db *DB) GenerateRcloneConfigWithToken(config *TransferConfig, token string) error

GenerateRcloneConfigWithToken generates a rclone config file for a transfer config with a provided token Note: This seems partially redundant with StoreGoogleDriveToken and GenerateRcloneConfig. Consolidate if possible.

func (*DB) GetActiveJobs added in v0.1.8

func (db *DB) GetActiveJobs() ([]Job, error)

GetActiveJobs returns all active (enabled) jobs

func (*DB) GetAllAuthProviders added in v0.2.0

func (db *DB) GetAllAuthProviders(ctx context.Context) ([]AuthProvider, error)

GetAllAuthProviders returns all authentication providers

func (*DB) GetAuthProviderByID added in v0.2.0

func (db *DB) GetAuthProviderByID(ctx context.Context, id uint) (*AuthProvider, error)

GetAuthProviderByID retrieves an authentication provider by ID

func (*DB) GetAuthProviderByType added in v0.2.0

func (db *DB) GetAuthProviderByType(ctx context.Context, providerType ProviderType) ([]AuthProvider, error)

GetAuthProviderByType returns authentication providers of a specific type

func (*DB) GetConfigRclonePath

func (db *DB) GetConfigRclonePath(config *TransferConfig) string

GetConfigRclonePath returns the path to the rclone config file for a given transfer config

func (*DB) GetConfigsForJob added in v0.1.8

func (db *DB) GetConfigsForJob(jobID uint) ([]TransferConfig, error)

GetConfigsForJob returns all transfer configurations associated with a job, in the order specified by ConfigIDs

func (*DB) GetEnabledAuthProviders added in v0.2.0

func (db *DB) GetEnabledAuthProviders(ctx context.Context) ([]AuthProvider, error)

GetEnabledAuthProviders returns all enabled authentication providers

func (*DB) GetExternalUserIdentitiesByProviderID added in v0.2.0

func (db *DB) GetExternalUserIdentitiesByProviderID(ctx context.Context, providerID uint) ([]ExternalUserIdentity, error)

GetExternalUserIdentitiesByProviderID returns all external user identities for a specific provider

func (*DB) GetExternalUserIdentity added in v0.2.0

func (db *DB) GetExternalUserIdentity(ctx context.Context, providerID uint, externalID string) (*ExternalUserIdentity, error)

GetExternalUserIdentity gets an external user identity by provider ID and external ID

func (*DB) GetFileMetadataByHash added in v0.1.7

func (db *DB) GetFileMetadataByHash(fileHash string) (*FileMetadata, error)

GetFileMetadataByHash retrieves file metadata by file hash

func (*DB) GetFileMetadataByJobAndName added in v0.1.7

func (db *DB) GetFileMetadataByJobAndName(jobID uint, fileName string) (*FileMetadata, error)

GetFileMetadataByJobAndName retrieves file metadata by job ID and filename

func (*DB) GetGDriveCredentialsFromConfig added in v0.1.10

func (db *DB) GetGDriveCredentialsFromConfig(config *TransferConfig) (string, string)

GetGDriveCredentialsFromConfig extracts Google Drive client ID and secret from an existing rclone config file

func (*DB) GetJob

func (db *DB) GetJob(id uint) (*Job, error)

GetJob retrieves a single job by ID, preloading the associated config

func (*DB) GetJobHistory

func (db *DB) GetJobHistory(jobID uint) ([]JobHistory, error)

GetJobHistory retrieves all history records for a specific job, ordered by start time descending

func (*DB) GetJobs

func (db *DB) GetJobs(userID uint) ([]Job, error)

GetJobs retrieves all jobs for a user, preloading the associated config

func (*DB) GetNotificationService added in v0.2.0

func (db *DB) GetNotificationService(id uint) (*NotificationService, error)

GetNotificationService returns a notification service by ID

func (*DB) GetNotificationServices added in v0.2.0

func (db *DB) GetNotificationServices(onlyEnabled bool) ([]NotificationService, error)

GetNotificationServices returns notification services, filtered by enabled status if specified

func (*DB) GetPaginatedUserNotifications added in v0.2.0

func (db *DB) GetPaginatedUserNotifications(userID uint, offset, limit int) ([]UserNotification, error)

GetPaginatedUserNotifications returns paginated notifications for a user

func (*DB) GetPasswordResetToken

func (db *DB) GetPasswordResetToken(token string) (*PasswordResetToken, error)

GetPasswordResetToken retrieves a valid, unused password reset token

func (*DB) GetRcloneCategories added in v0.2.0

func (db *DB) GetRcloneCategories() ([]string, error)

GetRcloneCategories returns all unique categories of rclone commands

func (*DB) GetRcloneCommand added in v0.2.0

func (db *DB) GetRcloneCommand(id uint) (*RcloneCommand, error)

GetRcloneCommand returns a specific rclone command by ID

func (*DB) GetRcloneCommandByName added in v0.2.0

func (db *DB) GetRcloneCommandByName(name string) (*RcloneCommand, error)

GetRcloneCommandByName returns a specific rclone command by name

func (*DB) GetRcloneCommandFlag added in v0.2.0

func (db *DB) GetRcloneCommandFlag(id uint) (*RcloneCommandFlag, error)

GetRcloneCommandFlag returns a specific flag by ID

func (*DB) GetRcloneCommandFlagByName added in v0.2.0

func (db *DB) GetRcloneCommandFlagByName(commandID uint, name string) (*RcloneCommandFlag, error)

GetRcloneCommandFlagByName returns a specific flag by name for a command

func (*DB) GetRcloneCommandFlags added in v0.2.0

func (db *DB) GetRcloneCommandFlags(commandID uint) ([]RcloneCommandFlag, error)

GetRcloneCommandFlags returns all flags for a specific command

func (*DB) GetRcloneCommandFlagsMap added in v0.2.0

func (db *DB) GetRcloneCommandFlagsMap(commandID uint) (map[uint]RcloneCommandFlag, error)

GetRcloneCommandFlagsMap returns all flags for a specific command as a map keyed by flag ID

func (*DB) GetRcloneCommandUsage added in v0.2.0

func (db *DB) GetRcloneCommandUsage(commandID uint) (string, error)

GetRcloneCommandUsage returns a basic usage example for a command with its required flags

func (*DB) GetRcloneCommandWithFlags added in v0.2.0

func (db *DB) GetRcloneCommandWithFlags(commandID uint) (*RcloneCommand, error)

GetRcloneCommandWithFlags returns a command with all its flags

func (*DB) GetRcloneCommands added in v0.2.0

func (db *DB) GetRcloneCommands() ([]RcloneCommand, error)

GetRcloneCommands returns all rclone commands

func (*DB) GetRcloneCommandsByAdvanced added in v0.2.0

func (db *DB) GetRcloneCommandsByAdvanced(isAdvanced bool) ([]RcloneCommand, error)

GetRcloneCommandsByAdvanced returns commands filtered by their advanced status

func (*DB) GetRcloneCommandsInCategory added in v0.2.0

func (db *DB) GetRcloneCommandsInCategory(category string) ([]RcloneCommand, error)

GetRcloneCommandsInCategory returns all commands in a specific category

func (*DB) GetRole added in v0.2.0

func (db *DB) GetRole(id uint) (*Role, error)

GetRole retrieves a role by ID, preloading permissions

func (*DB) GetRoleByName added in v0.2.0

func (db *DB) GetRoleByName(name string) (*Role, error)

GetRoleByName retrieves a role by name, preloading permissions

func (*DB) GetTransferConfig

func (db *DB) GetTransferConfig(id uint) (*TransferConfig, error)

GetTransferConfig retrieves a single transfer config by ID

func (*DB) GetTransferConfigs

func (db *DB) GetTransferConfigs(userID uint) ([]TransferConfig, error)

GetTransferConfigs retrieves all transfer configs for a user

func (*DB) GetUnreadNotificationCount added in v0.2.0

func (db *DB) GetUnreadNotificationCount(userID uint) (int64, error)

GetUnreadNotificationCount returns the count of unread notifications for a user

func (*DB) GetUserByEmail

func (db *DB) GetUserByEmail(email string) (*User, error)

GetUserByEmail retrieves a user by their email address

func (*DB) GetUserByID

func (db *DB) GetUserByID(id uint) (*User, error)

GetUserByID retrieves a user by their ID

func (*DB) GetUserNotificationCount added in v0.2.0

func (db *DB) GetUserNotificationCount(userID uint) (int64, error)

GetUserNotificationCount returns the total count of notifications for a user

func (*DB) GetUserNotifications added in v0.2.0

func (db *DB) GetUserNotifications(userID uint, limit int) ([]UserNotification, error)

GetUserNotifications returns the latest notifications for a user

func (*DB) GetUserRoles added in v0.2.0

func (db *DB) GetUserRoles(userID uint) ([]Role, error)

GetUserRoles retrieves all roles assigned to a specific user ID

func (*DB) ListRoles added in v0.2.0

func (db *DB) ListRoles() ([]Role, error)

ListRoles retrieves all roles

func (*DB) MarkAllNotificationsAsRead added in v0.2.0

func (db *DB) MarkAllNotificationsAsRead(userID uint) error

MarkAllNotificationsAsRead marks all notifications for a user as read

func (*DB) MarkNotificationAsRead added in v0.2.0

func (db *DB) MarkNotificationAsRead(id uint) error

MarkNotificationAsRead marks a notification as read

func (*DB) MarkPasswordResetTokenAsUsed

func (db *DB) MarkPasswordResetTokenAsUsed(tokenID uint) error

MarkPasswordResetTokenAsUsed marks a password reset token as used

func (*DB) RenderRcloneCommandHelp added in v0.2.0

func (db *DB) RenderRcloneCommandHelp(commandID uint) (string, error)

RenderRcloneCommandHelp generates a help text for a command with its flags

func (*DB) SearchRcloneCommands added in v0.2.0

func (db *DB) SearchRcloneCommands(query string) ([]RcloneCommand, error)

SearchRcloneCommands searches for commands by name or description

func (*DB) StoreGoogleDriveToken added in v0.1.10

func (db *DB) StoreGoogleDriveToken(configIDStr string, token string) error

StoreGoogleDriveToken stores the Google Drive auth token for a config

func (*DB) UnassignRoleFromUser added in v0.2.0

func (db *DB) UnassignRoleFromUser(roleID, userID, unassignedByID uint) error

UnassignRoleFromUser removes a role from a user, handling the join table

func (*DB) UpdateAuthProvider added in v0.2.0

func (db *DB) UpdateAuthProvider(ctx context.Context, provider *AuthProvider) error

UpdateAuthProvider updates an existing authentication provider

func (*DB) UpdateAuthProviderLastUsed added in v0.2.0

func (db *DB) UpdateAuthProviderLastUsed(ctx context.Context, providerID uint) error

UpdateAuthProviderLastUsed updates the last used timestamp and increments the successful logins counter

func (*DB) UpdateExternalUserIdentity added in v0.2.0

func (db *DB) UpdateExternalUserIdentity(ctx context.Context, identity *ExternalUserIdentity) error

UpdateExternalUserIdentity updates an existing external user identity

func (*DB) UpdateJob

func (db *DB) UpdateJob(job *Job) error

UpdateJob updates an existing job record

func (*DB) UpdateJobHistory

func (db *DB) UpdateJobHistory(history *JobHistory) error

UpdateJobHistory updates an existing job history record

func (*DB) UpdateJobStatus

func (db *DB) UpdateJobStatus(job *Job) error

UpdateJobStatus updates the LastRun and NextRun fields of a job

func (*DB) UpdateNotificationService added in v0.2.0

func (db *DB) UpdateNotificationService(service *NotificationService) error

UpdateNotificationService updates an existing notification service

func (*DB) UpdateRole added in v0.2.0

func (db *DB) UpdateRole(role *Role) error

UpdateRole updates an existing role record

func (*DB) UpdateTransferConfig

func (db *DB) UpdateTransferConfig(config *TransferConfig) error

UpdateTransferConfig updates an existing transfer config record

func (*DB) UpdateUser

func (db *DB) UpdateUser(user *User) error

UpdateUser updates an existing user record

func (*DB) ValidateRcloneFlags added in v0.2.0

func (db *DB) ValidateRcloneFlags(commandName string, flags map[string]string) (bool, map[string]string)

ValidateRcloneFlags validates if the provided flags are valid for the command

type ExternalUserIdentity added in v0.2.0

type ExternalUserIdentity struct {
	ID           uint         `gorm:"primarykey" json:"id"`
	UserID       uint         `gorm:"not null" json:"user_id"`
	ProviderID   uint         `gorm:"not null" json:"provider_id"`
	ProviderType ProviderType `gorm:"not null" json:"provider_type"`
	ExternalID   string       `gorm:"not null" json:"external_id"`
	Email        string       `gorm:"not null" json:"email"`
	Username     string       `json:"username"`
	DisplayName  string       `json:"display_name"`
	Groups       string       `json:"groups"` // JSON array of groups
	LastLogin    sql.NullTime `json:"last_login"`
	ProviderData string       `json:"-"` // Raw data from provider
	CreatedAt    time.Time    `json:"created_at"`
	UpdatedAt    time.Time    `json:"updated_at"`

	// Foreign key relationships
	User     User         `gorm:"foreignKey:UserID" json:"-"`
	Provider AuthProvider `gorm:"foreignKey:ProviderID" json:"-"`
	// contains filtered or unexported fields
}

ExternalUserIdentity represents a user identity from an external authentication provider

func (*ExternalUserIdentity) GetGroups added in v0.2.0

func (e *ExternalUserIdentity) GetGroups() ([]string, error)

GetGroups returns the unmarshalled groups

func (*ExternalUserIdentity) GetProviderData added in v0.2.0

func (e *ExternalUserIdentity) GetProviderData() (map[string]interface{}, error)

GetProviderData returns the unmarshalled provider data

func (*ExternalUserIdentity) SetGroups added in v0.2.0

func (e *ExternalUserIdentity) SetGroups(groups []string) error

SetGroups sets the groups and marshals them to JSON

func (*ExternalUserIdentity) SetProviderData added in v0.2.0

func (e *ExternalUserIdentity) SetProviderData(data map[string]interface{}) error

SetProviderData sets the provider data and marshals it to JSON

type FileMetadata added in v0.1.7

type FileMetadata struct {
	ID              uint   `gorm:"primarykey"`
	JobID           uint   `gorm:"not null;index"`
	Job             Job    `gorm:"foreignkey:JobID"`
	ConfigID        uint   `gorm:"default:0"` // The specific config ID this file was processed with
	FileName        string `gorm:"not null"`
	OriginalPath    string `gorm:"not null"`
	FileSize        int64  `gorm:"not null"`
	FileHash        string `gorm:"index"` // MD5 or other hash for file identity
	CreationTime    time.Time
	ModTime         time.Time
	ProcessedTime   time.Time `gorm:"not null"`
	DestinationPath string    `gorm:"not null"`
	Status          string    `gorm:"not null"` // processed, archived, deleted, etc.
	ErrorMessage    string
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

FileMetadata stores information about processed files

type Job

type Job struct {
	ID        uint           `gorm:"primarykey"`
	Name      string         `form:"name"`
	ConfigID  uint           `gorm:"not null" form:"config_id"`
	Config    TransferConfig `gorm:"foreignkey:ConfigID"`
	ConfigIDs string         `gorm:"column:config_ids"` // Comma-separated list of config IDs
	Schedule  string         `gorm:"not null" form:"schedule"`
	Enabled   *bool          `gorm:"default:true" form:"enabled"`
	LastRun   *time.Time
	NextRun   *time.Time
	// Webhook notification fields
	WebhookEnabled  *bool  `gorm:"default:false" form:"webhook_enabled"`
	WebhookURL      string `form:"webhook_url"`
	WebhookSecret   string `form:"webhook_secret"`
	WebhookHeaders  string `form:"webhook_headers"` // JSON-encoded headers
	NotifyOnSuccess *bool  `gorm:"default:true" form:"notify_on_success"`
	NotifyOnFailure *bool  `gorm:"default:true" form:"notify_on_failure"`
	CreatedBy       uint
	User            User `gorm:"foreignkey:CreatedBy"`
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

Job represents a scheduled transfer task

func (*Job) GetConfigIDsAsStrings added in v0.1.8

func (j *Job) GetConfigIDsAsStrings() []string

GetConfigIDsAsStrings returns the list of config IDs as strings for template rendering

func (*Job) GetConfigIDsList added in v0.1.8

func (j *Job) GetConfigIDsList() []uint

GetConfigIDsList returns the list of config IDs as integers

func (*Job) GetEnabled added in v0.1.10

func (j *Job) GetEnabled() bool

GetEnabled returns the value of Enabled with a default if nil

func (*Job) GetNotifyOnFailure added in v0.1.10

func (j *Job) GetNotifyOnFailure() bool

GetNotifyOnFailure returns the value of NotifyOnFailure with a default if nil

func (*Job) GetNotifyOnSuccess added in v0.1.10

func (j *Job) GetNotifyOnSuccess() bool

GetNotifyOnSuccess returns the value of NotifyOnSuccess with a default if nil

func (*Job) GetWebhookEnabled added in v0.1.10

func (j *Job) GetWebhookEnabled() bool

GetWebhookEnabled returns the value of WebhookEnabled with a default if nil

func (*Job) SetConfigIDsList added in v0.1.8

func (j *Job) SetConfigIDsList(ids []uint)

SetConfigIDsList sets the config IDs from a slice of uint

func (*Job) SetEnabled added in v0.1.10

func (j *Job) SetEnabled(value bool)

SetEnabled sets the Enabled field

func (*Job) SetNotifyOnFailure added in v0.1.10

func (j *Job) SetNotifyOnFailure(value bool)

SetNotifyOnFailure sets the NotifyOnFailure field

func (*Job) SetNotifyOnSuccess added in v0.1.10

func (j *Job) SetNotifyOnSuccess(value bool)

SetNotifyOnSuccess sets the NotifyOnSuccess field

func (*Job) SetWebhookEnabled added in v0.1.10

func (j *Job) SetWebhookEnabled(value bool)

SetWebhookEnabled sets the WebhookEnabled field

type JobHistory

type JobHistory struct {
	ID               uint      `gorm:"primarykey"`
	JobID            uint      `gorm:"not null"`
	Job              Job       `gorm:"foreignkey:JobID"`
	ConfigID         uint      `gorm:"default:0"` // The specific config ID this history entry is for
	StartTime        time.Time `gorm:"not null"`
	EndTime          *time.Time
	Status           string `gorm:"not null"`
	BytesTransferred int64
	FilesTransferred int
	ErrorMessage     string
	CreatedAt        time.Time
	UpdatedAt        time.Time
}

JobHistory records the execution history of a job

type NotificationService added in v0.2.0

type NotificationService struct {
	ID                uint              `json:"id" gorm:"primaryKey"`
	Name              string            `json:"name" gorm:"not null"`
	Type              string            `json:"type" gorm:"not null"` // email, webhook
	IsEnabled         *bool             `json:"is_enabled" gorm:"default:true"`
	Config            map[string]string `json:"config" gorm:"-"`
	ConfigJSON        string            `json:"-" gorm:"column:config"`
	Description       string            `json:"description"`
	EventTriggers     []string          `json:"event_triggers" gorm:"-"`
	EventTriggersJSON string            `json:"-" gorm:"column:event_triggers;default:'[]'"`
	PayloadTemplate   string            `json:"payload_template" gorm:"column:payload_template"`
	SecretKey         string            `json:"secret_key" gorm:"column:secret_key"`
	RetryPolicy       string            `json:"retry_policy" gorm:"column:retry_policy;default:'simple'"`
	LastUsed          time.Time         `json:"last_used" gorm:"column:last_used"`
	SuccessCount      int               `json:"success_count" gorm:"column:success_count;default:0"`
	FailureCount      int               `json:"failure_count" gorm:"column:failure_count;default:0"`
	CreatedBy         uint              `json:"created_by"`
	CreatedAt         time.Time         `json:"created_at"`
	UpdatedAt         time.Time         `json:"updated_at"`
}

NotificationService represents a notification service configuration

func (*NotificationService) AfterFind added in v0.2.0

func (n *NotificationService) AfterFind(tx *gorm.DB) error

AfterFind converts JSON strings back to Config map and EventTriggers

func (*NotificationService) BeforeSave added in v0.2.0

func (n *NotificationService) BeforeSave(tx *gorm.DB) error

BeforeSave converts Config map and EventTriggers to JSON strings for storage

func (*NotificationService) GetIsEnabled added in v0.2.4

func (n *NotificationService) GetIsEnabled() bool

GetIsEnabled returns the value of IsEnabled with a default if nil

func (*NotificationService) SetIsEnabled added in v0.2.4

func (n *NotificationService) SetIsEnabled(value bool)

SetIsEnabled sets the IsEnabled field

type NotificationType added in v0.2.0

type NotificationType string

NotificationType defines the type of notification

const (
	NotificationJobStart     NotificationType = "job_start"
	NotificationJobComplete  NotificationType = "job_complete"
	NotificationJobFail      NotificationType = "job_fail"
	NotificationConfigUpdate NotificationType = "config_update"
	NotificationSystemAlert  NotificationType = "system_alert"
)

type PasswordHistory

type PasswordHistory struct {
	ID           uint   `gorm:"primarykey"`
	UserID       uint   `gorm:"not null"`
	User         User   `gorm:"foreignkey:UserID"`
	PasswordHash string `gorm:"not null"`
	CreatedAt    time.Time
}

PasswordHistory stores previous passwords for a user

type PasswordResetToken

type PasswordResetToken struct {
	ID        uint      `gorm:"primarykey"`
	UserID    uint      `gorm:"not null"`
	User      User      `gorm:"foreignkey:UserID"`
	Token     string    `gorm:"not null"`
	ExpiresAt time.Time `gorm:"not null"`
	Used      *bool     `gorm:"default:false"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

PasswordResetToken stores tokens for password reset requests

func (*PasswordResetToken) GetUsed added in v0.1.10

func (t *PasswordResetToken) GetUsed() bool

GetUsed returns the value of Used with a default if nil

func (*PasswordResetToken) SetUsed added in v0.1.10

func (t *PasswordResetToken) SetUsed(value bool)

SetUsed sets the Used field

type Permissions added in v0.2.0

type Permissions []string

Permissions is a custom type for storing permissions as a JSON array

func (*Permissions) Scan added in v0.2.0

func (p *Permissions) Scan(value interface{}) error

Scan implements the sql.Scanner interface

func (Permissions) Value added in v0.2.0

func (p Permissions) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type ProviderType added in v0.2.0

type ProviderType string

ProviderType represents the type of authentication provider

const (
	// ProviderTypeAuthentik represents an Authentik authentication provider
	ProviderTypeAuthentik ProviderType = "authentik"

	// ProviderTypeOIDC represents an OpenID Connect authentication provider
	ProviderTypeOIDC ProviderType = "oidc"

	// ProviderTypeSAML represents a SAML authentication provider
	ProviderTypeSAML ProviderType = "saml"

	// ProviderTypeOAuth2 represents an OAuth2 authentication provider
	ProviderTypeOAuth2 ProviderType = "oauth2"
)

type RcloneCommand added in v0.2.0

type RcloneCommand struct {
	ID          uint                `gorm:"primarykey"`
	Name        string              `gorm:"not null;uniqueIndex"`
	Description string              `gorm:"not null"`
	Category    string              `gorm:"not null;index"`
	IsAdvanced  bool                `gorm:"not null;default:false"`
	Flags       []RcloneCommandFlag `gorm:"foreignKey:CommandID;constraint:OnDelete:CASCADE"`
	CreatedAt   time.Time           `gorm:"not null"`
}

RcloneCommand represents a command available in rclone

type RcloneCommandFlag added in v0.2.0

type RcloneCommandFlag struct {
	ID           uint          `gorm:"primarykey"`
	CommandID    uint          `gorm:"not null;index"`
	Command      RcloneCommand `gorm:"foreignKey:CommandID"`
	Name         string        `gorm:"not null;index"`
	ShortName    string
	Description  string `gorm:"not null"`
	DataType     string `gorm:"not null"` // string, int, bool, etc.
	IsRequired   bool   `gorm:"not null;default:false"`
	DefaultValue string
	CreatedAt    time.Time `gorm:"not null"`
}

RcloneCommandFlag represents a flag that can be used with an rclone command

func (*RcloneCommandFlag) GetUsageExample added in v0.2.0

func (flag *RcloneCommandFlag) GetUsageExample() string

GetUsageExample returns a human-readable usage example for a flag

type Role added in v0.2.0

type Role struct {
	gorm.Model
	Name        string      `gorm:"size:255;not null;unique"`
	Description string      `gorm:"type:text"`
	Permissions Permissions `gorm:"type:text"`
	Users       []User      `gorm:"many2many:user_roles;"`
}

Role represents a role in the system with associated permissions

func (*Role) AddPermission added in v0.2.0

func (r *Role) AddPermission(permission string)

AddPermission adds a permission to the role if it doesn't already exist

func (*Role) AfterCreate added in v0.2.0

func (r *Role) AfterCreate(tx *gorm.DB) error

AfterCreate is a GORM hook that runs after creating the role

func (*Role) AfterUpdate added in v0.2.0

func (r *Role) AfterUpdate(tx *gorm.DB) error

AfterUpdate is a GORM hook that runs after updating the role

func (*Role) AssignToUser added in v0.2.0

func (r *Role) AssignToUser(tx *gorm.DB, userID uint, assignedByID uint) error

AssignToUser assigns this role to a user

func (*Role) AuditLog added in v0.2.0

func (r *Role) AuditLog(tx *gorm.DB, action string, userID uint) error

AuditLog creates an audit log entry for role changes

func (*Role) BeforeDelete added in v0.2.0

func (r *Role) BeforeDelete(tx *gorm.DB) error

BeforeDelete is a GORM hook that runs before deleting the role

func (*Role) BeforeSave added in v0.2.0

func (r *Role) BeforeSave(tx *gorm.DB) error

BeforeSave is a GORM hook that runs before saving the role

func (*Role) GetPermissions added in v0.2.0

func (r *Role) GetPermissions() []string

GetPermissions returns the role's permissions

func (*Role) HasPermission added in v0.2.0

func (r *Role) HasPermission(permission string) bool

HasPermission checks if the role has a specific permission

func (*Role) IsSystemRole added in v0.2.0

func (r *Role) IsSystemRole() bool

IsSystemRole checks if this is a system-defined role that shouldn't be modified

func (*Role) RemovePermission added in v0.2.0

func (r *Role) RemovePermission(permission string)

RemovePermission removes a permission from the role

func (*Role) SetPermissions added in v0.2.0

func (r *Role) SetPermissions(permissions []string)

SetPermissions sets the role's permissions

func (*Role) UnassignFromUser added in v0.2.0

func (r *Role) UnassignFromUser(tx *gorm.DB, userID uint, unassignedByID uint) error

UnassignFromUser removes this role from a user

func (*Role) Validate added in v0.2.0

func (r *Role) Validate() error

Validate performs validation on the role

type TransferConfig

type TransferConfig struct {
	ID             uint   `gorm:"primarykey"`
	Name           string `gorm:"not null" form:"name"`
	SourceType     string `gorm:"not null" form:"source_type"`
	SourcePath     string `gorm:"not null" form:"source_path"`
	SourceHost     string `form:"source_host"`
	SourcePort     int    `gorm:"default:22" form:"source_port"`
	SourceUser     string `form:"source_user"`
	SourcePassword string `form:"source_password" gorm:"-"` // Not stored in DB, only used for form
	SourceKeyFile  string `form:"source_key_file"`
	// S3 source fields
	SourceBucket    string `form:"source_bucket"`
	SourceRegion    string `form:"source_region"`
	SourceAccessKey string `form:"source_access_key"`
	SourceSecretKey string `form:"source_secret_key" gorm:"-"` // Not stored in DB, only used for form
	SourceEndpoint  string `form:"source_endpoint"`
	// SMB source fields
	SourceShare  string `form:"source_share"`
	SourceDomain string `form:"source_domain"`
	// FTP source fields
	SourcePassiveMode *bool `gorm:"default:true" form:"source_passive_mode"` // Already a pointer, no change needed here
	// OneDrive and Google Drive source fields
	SourceClientID     string `form:"source_client_id"`
	SourceClientSecret string `form:"source_client_secret" gorm:"-"` // Not stored in DB, only used for form
	SourceDriveID      string `form:"source_drive_id"`               // For OneDrive
	SourceTeamDrive    string `form:"source_team_drive"`             // For Google Drive
	// Google Photos source fields
	SourceReadOnly        *bool `form:"source_read_only"`        // For Google Photos
	SourceStartYear       int   `form:"source_start_year"`       // For Google Photos
	SourceIncludeArchived *bool `form:"source_include_archived"` // For Google Photos
	// General fields
	FilePattern     string `gorm:"default:'*'" form:"file_pattern"`
	OutputPattern   string `form:"output_pattern"` // Pattern for output filenames with date variables
	DestinationType string `gorm:"not null" form:"destination_type"`
	DestinationPath string `gorm:"not null" form:"destination_path"`
	DestHost        string `form:"dest_host"`
	DestPort        int    `gorm:"default:22" form:"dest_port"`
	DestUser        string `form:"dest_user"`
	DestPassword    string `form:"dest_password" gorm:"-"` // Not stored in DB, only used for form
	DestKeyFile     string `form:"dest_key_file"`
	// S3 destination fields
	DestBucket    string `form:"dest_bucket"`
	DestRegion    string `form:"dest_region"`
	DestAccessKey string `form:"dest_access_key"`
	DestSecretKey string `form:"dest_secret_key" gorm:"-"` // Not stored in DB, only used for form
	DestEndpoint  string `form:"dest_endpoint"`
	// SMB destination fields
	DestShare  string `form:"dest_share"`
	DestDomain string `form:"dest_domain"`
	// FTP destination fields
	DestPassiveMode *bool `gorm:"default:true" form:"dest_passive_mode"`
	// OneDrive and Google Drive destination fields
	DestClientID     string `form:"dest_client_id"`
	DestClientSecret string `form:"dest_client_secret" gorm:"-"` // Not stored in DB, only used for form
	DestDriveID      string `form:"dest_drive_id"`               // For OneDrive
	DestTeamDrive    string `form:"dest_team_drive"`             // For Google Drive
	// Google Photos destination fields
	DestReadOnly        *bool `form:"dest_read_only"`        // For Google Photos
	DestStartYear       int   `form:"dest_start_year"`       // For Google Photos
	DestIncludeArchived *bool `form:"dest_include_archived"` // For Google Photos
	// Security fields
	UseBuiltinAuthSource     *bool `form:"use_builtin_auth_source"` // For Google and other OAuth services
	UseBuiltinAuthDest       *bool `form:"use_builtin_auth_dest"`   // For Google and other OAuth services
	GoogleDriveAuthenticated *bool // Whether Google Drive auth is completed
	// General fields
	ArchivePath    string `form:"archive_path"`
	ArchiveEnabled *bool  `gorm:"default:false" form:"archive_enabled"`
	RcloneFlags    string `form:"rclone_flags"`
	// Rclone command fields
	CommandID              uint   `gorm:"default:1" form:"command_id"` // Default to 'copy' command ID (1)
	CommandFlags           string `form:"command_flags"`               // JSON string of selected flags
	CommandFlagValues      string `form:"command_flag_values"`         // JSON string of flag values by ID
	DeleteAfterTransfer    *bool  `gorm:"default:false" form:"delete_after_transfer"`
	SkipProcessedFiles     *bool  `gorm:"default:true" form:"skip_processed_files"`
	MaxConcurrentTransfers int    `gorm:"default:4" form:"max_concurrent_transfers"` // Number of concurrent file transfers
	CreatedBy              uint
	User                   User `gorm:"foreignkey:CreatedBy"`
	CreatedAt              time.Time
	UpdatedAt              time.Time
}

TransferConfig holds the configuration for a data transfer operation

func (*TransferConfig) GetArchiveEnabled added in v0.1.10

func (tc *TransferConfig) GetArchiveEnabled() bool

GetArchiveEnabled returns the value of ArchiveEnabled with a default if nil

func (*TransferConfig) GetDeleteAfterTransfer added in v0.1.10

func (tc *TransferConfig) GetDeleteAfterTransfer() bool

GetDeleteAfterTransfer returns the value of DeleteAfterTransfer with a default if nil

func (*TransferConfig) GetDestPassiveMode added in v0.1.10

func (tc *TransferConfig) GetDestPassiveMode() bool

GetDestPassiveMode returns the value of DestPassiveMode with a default if nil

func (*TransferConfig) GetGoogleAuthenticated added in v0.1.10

func (tc *TransferConfig) GetGoogleAuthenticated() bool

GetGoogleAuthenticated is an alias for GetGoogleDriveAuthenticated for better semantics when working with Google Photos

func (*TransferConfig) GetGoogleDriveAuthenticated added in v0.1.10

func (tc *TransferConfig) GetGoogleDriveAuthenticated() bool

GetGoogleDriveAuthenticated returns whether the transfer config has been authenticated with Google Drive

func (*TransferConfig) GetSkipProcessedFiles added in v0.1.8

func (tc *TransferConfig) GetSkipProcessedFiles() bool

GetSkipProcessedFiles returns the value of SkipProcessedFiles with a default if nil

func (*TransferConfig) GetSourcePassiveMode added in v0.1.10

func (tc *TransferConfig) GetSourcePassiveMode() bool

GetSourcePassiveMode returns the value of SourcePassiveMode with a default if nil

func (*TransferConfig) GetUseBuiltinAuthDest added in v0.1.11

func (tc *TransferConfig) GetUseBuiltinAuthDest() bool

GetUseBuiltinAuthDest returns the value of UseBuiltinAuthDest with a default if nil

func (*TransferConfig) GetUseBuiltinAuthSource added in v0.1.11

func (tc *TransferConfig) GetUseBuiltinAuthSource() bool

GetUseBuiltinAuthSource returns the value of UseBuiltinAuthSource with a default if nil

func (*TransferConfig) SetArchiveEnabled added in v0.1.10

func (tc *TransferConfig) SetArchiveEnabled(value bool)

SetArchiveEnabled sets the ArchiveEnabled field

func (*TransferConfig) SetDeleteAfterTransfer added in v0.1.10

func (tc *TransferConfig) SetDeleteAfterTransfer(value bool)

SetDeleteAfterTransfer sets the DeleteAfterTransfer field

func (*TransferConfig) SetDestPassiveMode added in v0.1.10

func (tc *TransferConfig) SetDestPassiveMode(value bool)

SetDestPassiveMode sets the DestPassiveMode field

func (*TransferConfig) SetGoogleAuthenticated added in v0.1.10

func (tc *TransferConfig) SetGoogleAuthenticated(value bool)

SetGoogleAuthenticated is an alias for SetGoogleDriveAuthenticated for better semantics when working with Google Photos

func (*TransferConfig) SetGoogleDriveAuthenticated added in v0.1.10

func (tc *TransferConfig) SetGoogleDriveAuthenticated(value bool)

SetGoogleDriveAuthenticated sets the Google Drive authentication status

func (*TransferConfig) SetSkipProcessedFiles added in v0.1.8

func (tc *TransferConfig) SetSkipProcessedFiles(value bool)

SetSkipProcessedFiles sets the SkipProcessedFiles field

func (*TransferConfig) SetSourcePassiveMode added in v0.1.10

func (tc *TransferConfig) SetSourcePassiveMode(value bool)

SetSourcePassiveMode sets the SourcePassiveMode field

func (*TransferConfig) SetUseBuiltinAuthDest added in v0.1.11

func (tc *TransferConfig) SetUseBuiltinAuthDest(value bool)

SetUseBuiltinAuthDest sets the UseBuiltinAuthDest field

func (*TransferConfig) SetUseBuiltinAuthSource added in v0.1.11

func (tc *TransferConfig) SetUseBuiltinAuthSource(value bool)

SetUseBuiltinAuthSource sets the UseBuiltinAuthSource field

type User

type User struct {
	ID                  uint   `gorm:"primarykey"`
	Email               string `gorm:"unique;not null"`
	PasswordHash        string `gorm:"not null"`
	IsAdmin             *bool  `gorm:"default:false"`
	LastPasswordChange  time.Time
	FailedLoginAttempts int   `gorm:"default:0"`
	AccountLocked       *bool `gorm:"default:false"`
	LockoutUntil        *time.Time
	Theme               string `gorm:"default:'light'"`
	TwoFactorSecret     string `gorm:"type:varchar(32)"`
	TwoFactorEnabled    bool   `gorm:"default:false"`
	BackupCodes         string `gorm:"type:text"` // Comma-separated backup codes
	Roles               []Role `gorm:"many2many:user_roles"`
	CreatedAt           time.Time
	UpdatedAt           time.Time
}

User represents a user account in the system

func (*User) AssignRole added in v0.2.0

func (u *User) AssignRole(tx *gorm.DB, roleID uint, assignedByID uint) error

AssignRole assigns a role to the user

func (*User) CheckPassword added in v0.2.0

func (u *User) CheckPassword(password string) bool

CheckPassword verifies if the provided password matches the stored hash

func (*User) GetAccountLocked added in v0.1.10

func (u *User) GetAccountLocked() bool

GetAccountLocked returns the value of AccountLocked with a default if nil

func (*User) GetIsAdmin added in v0.1.10

func (u *User) GetIsAdmin() bool

GetIsAdmin returns the value of IsAdmin with a default if nil

func (*User) GetRoles added in v0.2.0

func (u *User) GetRoles(tx *gorm.DB) ([]Role, error)

GetRoles returns all roles assigned to the user Note: This requires preloading Roles when fetching the user

func (*User) HasPermission added in v0.2.0

func (u *User) HasPermission(permission string) bool

HasPermission checks if the user has a specific permission through any of their roles

func (*User) HasRole added in v0.2.0

func (u *User) HasRole(roleName string) bool

HasRole checks if the user has a specific role

func (*User) SetAccountLocked added in v0.1.10

func (u *User) SetAccountLocked(value bool)

SetAccountLocked sets the AccountLocked field

func (*User) SetIsAdmin added in v0.1.10

func (u *User) SetIsAdmin(value bool)

SetIsAdmin sets the IsAdmin field

func (*User) SetPassword added in v0.2.0

func (u *User) SetPassword(password string) error

SetPassword sets the user's password with secure hashing

func (*User) UnassignRole added in v0.2.0

func (u *User) UnassignRole(tx *gorm.DB, roleID uint, unassignedByID uint) error

UnassignRole removes a role from the user

type UserNotification added in v0.2.0

type UserNotification struct {
	ID        uint             `json:"id" gorm:"primaryKey"`
	UserID    uint             `json:"user_id" gorm:"index"`
	Type      NotificationType `json:"type"`
	Title     string           `json:"title"`
	Message   string           `json:"message"`
	Link      string           `json:"link"`
	JobID     uint             `json:"job_id,omitempty"`
	JobRunID  uint             `json:"job_run_id,omitempty"`
	ConfigID  uint             `json:"config_id,omitempty"`
	IsRead    bool             `json:"is_read" gorm:"default:false"`
	CreatedAt time.Time        `json:"created_at"`
}

UserNotification represents a notification shown to users in the UI

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL