Documentation
¶
Index ¶
- Constants
- func AddBytesDownloaded(n int64)
- func AddBytesUploaded(n int64)
- func AutoMigrate()
- func CleanupExpiredLinks() error
- func CleanupExpiredPresignedURLs() error
- func Close() error
- func CreateStatsTable()
- func DecryptSecretKey(apiKey *APIKey) (string, error)
- func DeleteAPIKey(accessKeyID string) error
- func DeletePresignedURL(token 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 IncrementPresignedURLDownloads(token string) error
- 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 PresignedURL
- 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 AddBytesDownloaded ¶ added in v0.2.1
func AddBytesDownloaded(n int64)
AddBytesDownloaded adds n bytes to the total bytes downloaded counter
func AddBytesUploaded ¶ added in v0.2.1
func AddBytesUploaded(n int64)
AddBytesUploaded adds n bytes to the total bytes uploaded counter
func AutoMigrate ¶
func AutoMigrate()
func CleanupExpiredLinks ¶
func CleanupExpiredLinks() error
CleanupExpiredLinks removes all expired shareable links
func CleanupExpiredPresignedURLs ¶ added in v0.2.0
func CleanupExpiredPresignedURLs() error
func CreateStatsTable ¶
func CreateStatsTable()
func DecryptSecretKey ¶ added in v0.2.0
DecryptSecretKey decrypts the stored encrypted secret key.
func DeleteAPIKey ¶
DeleteAPIKey deletes an API key by access key ID
func DeletePresignedURL ¶ added in v0.2.0
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 IncrementPresignedURLDownloads ¶ added in v0.2.0
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:256;not null" json:"-"` // Encrypted at rest with AES-256-GCM
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 PresignedURL ¶ added in v0.2.0
type PresignedURL struct {
ID uint `gorm:"primaryKey" json:"id"`
Token string `gorm:"column:token;uniqueIndex;size:32;not null" json:"token"`
Bucket string `gorm:"column:bucket;size:255;not null" json:"bucket"`
Key string `gorm:"column:key;size:1024;not null" json:"key"`
Method string `gorm:"column:method;size:10;not null;default:GET" json:"method"` // GET or PUT
ExpiresAt *time.Time `gorm:"column:expires_at" json:"expiresAt,omitempty"`
MaxDownloads *int `gorm:"column:max_downloads" json:"maxDownloads,omitempty"`
DownloadCount int `gorm:"column:download_count;default:0" json:"downloadCount"`
CreatedBy string `gorm:"column:created_by;size:255" json:"createdBy,omitempty"` // access_key_id
CreatedAt time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"createdAt"`
}
func CreatePresignedURL ¶ added in v0.2.0
func GetPresignedURLByToken ¶ added in v0.2.0
func GetPresignedURLByToken(token string) (*PresignedURL, error)
func ListPresignedURLs ¶ added in v0.2.0
func ListPresignedURLs() ([]PresignedURL, error)
func (PresignedURL) TableName ¶ added in v0.2.0
func (PresignedURL) TableName() string
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"`
BytesUploaded int64 `gorm:"column:bytes_uploaded;default:0" json:"bytesUploaded"`
BytesDownloaded int64 `gorm:"column:bytes_downloaded;default:0" json:"bytesDownloaded"`
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