Documentation
¶
Index ¶
- Constants
- func AutoMigrate()
- func CleanupExpiredLinks() error
- func Close() error
- func CreateStatsTable()
- func DeleteAPIKey(accessKeyID string) error
- func DeleteShareableLink(token string) error
- func DisableAPIKey(accessKeyID string) error
- func GenerateKeyPair() (accessKeyID, secretKey string, err error)
- func GenerateToken() (string, error)
- func GetDB() *gorm.DB
- func Increment(field string)
- func IncrementAccessCount(token string) error
- func IncrementDownloads()
- func IncrementRequests()
- func IncrementUploads()
- func Init()
- func InitializeStats()
- func IsStarred(filePath string) bool
- func ResetStats()
- func StarFile(filePath string) error
- func UnstarFile(filePath string) error
- func UpdateLastUsed(accessKeyID string) error
- func ValidateLinkPassword(link *ShareableLink, password string) bool
- func WithTransaction(fn func(tx *gorm.DB) error) error
- type APIKey
- type Config
- type OrphanCleaner
- type Saga
- type SagaStep
- type ServerStats
- type ShareableLink
- type StarredFile
Constants ¶
const CleanupInterval = 1 * time.Hour
CleanupInterval is how often the orphan cleanup job runs.
Variables ¶
This section is empty.
Functions ¶
func AutoMigrate ¶
func AutoMigrate()
func CleanupExpiredLinks ¶
func CleanupExpiredLinks() error
CleanupExpiredLinks removes all expired shareable links
func CreateStatsTable ¶
func CreateStatsTable()
func DeleteAPIKey ¶
DeleteAPIKey deletes an API key by access key ID
func DeleteShareableLink ¶
DeleteShareableLink deletes a shareable link by token
func DisableAPIKey ¶
DisableAPIKey disables an API key without deleting it
func GenerateKeyPair ¶
GenerateKeyPair creates a new access key ID and secret key
func GenerateToken ¶
GenerateToken creates a unique random token for shareable links
func IncrementAccessCount ¶
IncrementAccessCount increments the access count for a shareable link
func IncrementDownloads ¶
func IncrementDownloads()
IncrementDownloads increments the download count by 1
func IncrementRequests ¶
func IncrementRequests()
IncrementRequests increments the request count by 1
func Init ¶
func Init()
Init explicitly initializes the database. Must be called after config flags (like --db-path) have been applied. Safe to call multiple times; only the first call takes effect.
func InitializeStats ¶
func InitializeStats()
InitializeStats creates an initial stats record if one doesn't exist
func ResetStats ¶
func ResetStats()
ResetStats resets the server stats to zero and updates the start time to now
func UnstarFile ¶
UnstarFile removes a file from the starred files list
func UpdateLastUsed ¶
UpdateLastUsed updates the last used timestamp for an API key
func ValidateLinkPassword ¶
func ValidateLinkPassword(link *ShareableLink, password string) bool
ValidateLinkPassword verifies a password for a password-protected link
Types ¶
type APIKey ¶
type APIKey struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:255;not null" json:"name"`
AccessKeyID string `gorm:"column:access_key_id;uniqueIndex;size:24;not null" json:"accessKeyId"`
SecretKey string `gorm:"column:secret_key;size:64;not null" json:"-"` // Stored for HMAC verification
Permissions string `gorm:"type:text" json:"permissions"` // JSON permissions
BucketScope string `gorm:"column:bucket_scope;size:255" json:"bucketScope,omitempty"`
ExpiresAt *time.Time `gorm:"column:expires_at" json:"expiresAt,omitempty"`
LastUsedAt *time.Time `gorm:"column:last_used_at" json:"lastUsedAt,omitempty"`
CreatedAt time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"createdAt"`
Disabled bool `gorm:"default:false" json:"disabled"`
}
APIKey represents an API key for S3-like API access
func CreateAPIKey ¶
func CreateAPIKey(name string, permissions string, bucketScope string, expiresIn *time.Duration) (*APIKey, string, error)
CreateAPIKey creates a new API key and returns the secret (only shown once)
func GetAPIKeyByAccessID ¶
GetAPIKeyByAccessID retrieves an API key by its access key ID
func ListAPIKeys ¶
ListAPIKeys returns all API keys (without secrets)
type OrphanCleaner ¶
type OrphanCleaner struct {
// contains filtered or unexported fields
}
OrphanCleaner periodically removes DB records that reference filesystem paths that no longer exist.
func NewOrphanCleaner ¶
func NewOrphanCleaner(sharedDir string) *OrphanCleaner
NewOrphanCleaner creates a new cleaner. Call Start() to begin.
func (*OrphanCleaner) RunOnce ¶
func (oc *OrphanCleaner) RunOnce()
RunOnce performs a single cleanup pass. Can be called directly for testing.
func (*OrphanCleaner) Start ¶
func (oc *OrphanCleaner) Start()
Start launches the background cleanup goroutine.
func (*OrphanCleaner) Stop ¶
func (oc *OrphanCleaner) Stop()
Stop signals the background goroutine to exit.
type Saga ¶
type Saga struct {
// contains filtered or unexported fields
}
Saga orchestrates a sequence of steps where each step has a compensating action. If any step fails, all previously completed steps are rolled back in reverse order (the "saga pattern").
Use this when you need to coordinate changes across different systems that don't share a single transaction boundary — for example, writing a DB record AND a file to disk.
type SagaStep ¶
type SagaStep struct {
Name string // human-readable label for logging
Action func() error // forward action (e.g. DB insert, FS write)
Compensate func() error // rollback action (e.g. DB delete, FS remove)
}
SagaStep represents a single forward action with a compensating rollback.
type ServerStats ¶
type ServerStats struct {
ID uint `gorm:"primaryKey" json:"id"`
Downloads int `gorm:"column:downloads;default:0" json:"downloads"`
Requests int `gorm:"column:requests;default:0" json:"requests"`
Uploads int `gorm:"column:uploads;default:0" json:"uploads"`
StartTime time.Time `gorm:"column:start_time;default:CURRENT_TIMESTAMP" json:"startTime"`
}
func (ServerStats) TableName ¶
func (ServerStats) TableName() string
type ShareableLink ¶
type ShareableLink struct {
}
ShareableLink represents a shareable link for a file or folder
func CreateShareableLink ¶
func CreateShareableLink(path string, password string, expiresIn *time.Duration) (*ShareableLink, error)
CreateShareableLink creates a new shareable link for a file or folder
func GetShareableLinkByToken ¶
func GetShareableLinkByToken(token string) (*ShareableLink, error)
GetShareableLinkByToken retrieves a shareable link by its token
func ListShareableLinks ¶
func ListShareableLinks() ([]ShareableLink, error)
ListShareableLinks returns all shareable links
func (ShareableLink) TableName ¶
func (ShareableLink) TableName() string
type StarredFile ¶
type StarredFile struct {
ID uint `gorm:"primaryKey" json:"id"`
FilePath string `gorm:"column:file_path;uniqueIndex;not null" json:"filePath"`
CreatedAt time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"createdAt"`
}
StarredFile represents a starred file in the database
func GetStarredFiles ¶
func GetStarredFiles() ([]StarredFile, error)
GetStarredFiles retrieves all starred files
func (StarredFile) TableName ¶
func (StarredFile) TableName() string