Documentation
¶
Index ¶
- Constants
- func AddBytesDownloaded(n int64)
- func AddBytesUploaded(n int64)
- func AutoMigrate()
- func CleanupExpiredLinks() error
- func CleanupExpiredPresignedURLs() error
- func CleanupOldWebhookEvents(maxAge time.Duration) int
- func Close() error
- func CreateStatsTable()
- func CreateWebhookEvent(eventType, resourceType, resourcePath, actor, payloadJSON string) error
- func DecryptSecretKey(apiKey *APIKey) (string, error)
- func DeleteAPIKey(accessKeyID string) error
- func DeletePresignedURL(token string) error
- func DeleteShareableLink(token string) error
- func DeleteWebhook(id uint) error
- func DisableAPIKey(accessKeyID string) error
- func GenerateKeyPair() (accessKeyID, secretKey string, err error)
- func GenerateToken() (string, error)
- func GenerateWebhookSecret() (string, error)
- func GetDB() *gorm.DB
- func GetWebhookSecret(wh *Webhook) (string, error)
- 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 RotateWebhookSecret(id uint) (string, error)
- func SetDeliveryNextAttempt(id uint, nextAt time.Time) error
- func StarFile(filePath string) error
- func UnstarFile(filePath string) error
- func UpdateDelivery(id uint, status string, httpStatus int, errMsg string, durationMs int) error
- func UpdateLastUsed(accessKeyID string) error
- func UpdateWebhook(id uint, updates map[string]any) 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
- type Webhook
- type WebhookDelivery
- type WebhookEvent
Constants ¶
const ( DeliveryPending = "pending" DeliveryDelivering = "delivering" DeliveryDelivered = "delivered" DeliveryFailed = "failed" DeliveryDeadLetter = "dead_letter" )
Webhook delivery status 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 CleanupOldWebhookEvents ¶ added in v0.2.7
CleanupOldWebhookEvents removes events older than the given duration.
func CreateStatsTable ¶
func CreateStatsTable()
func CreateWebhookEvent ¶ added in v0.2.7
CreateWebhookEvent persists an event and fans out pending deliveries.
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 DeleteWebhook ¶ added in v0.2.7
DeleteWebhook deletes a webhook and its deliveries.
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 GenerateWebhookSecret ¶ added in v0.2.7
GenerateWebhookSecret creates a random 32-byte hex secret for webhook signing.
func GetWebhookSecret ¶ added in v0.2.7
GetWebhookSecret decrypts and returns the webhook secret.
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 RotateWebhookSecret ¶ added in v0.2.7
RotateWebhookSecret generates a new secret for a webhook and returns it.
func SetDeliveryNextAttempt ¶ added in v0.2.7
SetDeliveryNextAttempt sets the next retry time.
func UnstarFile ¶
UnstarFile removes a file from the starred files list
func UpdateDelivery ¶ added in v0.2.7
UpdateDelivery updates delivery status after an attempt.
func UpdateLastUsed ¶
UpdateLastUsed updates the last used timestamp for an API key
func UpdateWebhook ¶ added in v0.2.7
UpdateWebhook updates mutable webhook fields.
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
type Webhook ¶ added in v0.2.7
type Webhook struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:255;not null" json:"name"`
TargetURL string `gorm:"column:target_url;size:2048;not null" json:"targetUrl"`
SecretEncrypted string `gorm:"column:secret_encrypted;size:512;not null" json:"-"`
Enabled bool `gorm:"default:true" json:"enabled"`
EventTypes string `gorm:"column:event_types;type:text;not null" json:"eventTypes"` // JSON array
BucketScope string `gorm:"column:bucket_scope;size:255" json:"bucketScope,omitempty"`
CreatedAt time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updatedAt"`
LastDeliveryAt *time.Time `gorm:"column:last_delivery_at" json:"lastDeliveryAt,omitempty"`
LastError string `gorm:"column:last_error;size:1024" json:"lastError,omitempty"`
}
Webhook represents a registered webhook destination.
func CreateWebhook ¶ added in v0.2.7
CreateWebhook creates a new webhook and returns the plaintext secret (shown once).
func GetWebhook ¶ added in v0.2.7
GetWebhook returns a single webhook by ID.
func ListWebhooks ¶ added in v0.2.7
ListWebhooks returns all webhooks (without secrets).
type WebhookDelivery ¶ added in v0.2.7
type WebhookDelivery struct {
ID uint `gorm:"primaryKey" json:"id"`
WebhookID uint `gorm:"column:webhook_id;not null;index:idx_wh_evt,unique" json:"webhookId"`
EventID string `gorm:"column:event_id;size:36;not null;index:idx_wh_evt,unique" json:"eventId"`
Status string `gorm:"column:status;size:20;not null;default:pending;index" json:"status"` // pending, delivering, delivered, failed, dead_letter
AttemptCount int `gorm:"column:attempt_count;default:0" json:"attemptCount"`
NextAttemptAt *time.Time `gorm:"column:next_attempt_at;index" json:"nextAttemptAt,omitempty"`
LastHTTPStatus int `gorm:"column:last_http_status" json:"lastHttpStatus,omitempty"`
LastError string `gorm:"column:last_error;size:1024" json:"lastError,omitempty"`
LastDurationMs int `gorm:"column:last_duration_ms" json:"lastDurationMs,omitempty"`
CreatedAt time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updatedAt"`
DeliveredAt *time.Time `gorm:"column:delivered_at" json:"deliveredAt,omitempty"`
}
WebhookDelivery tracks delivery attempts for an event to a webhook.
func GetDeliveriesForWebhook ¶ added in v0.2.7
func GetDeliveriesForWebhook(webhookID uint, limit int) ([]WebhookDelivery, error)
GetDeliveriesForWebhook returns recent deliveries for a webhook.
func GetPendingDeliveries ¶ added in v0.2.7
func GetPendingDeliveries(limit int) ([]WebhookDelivery, error)
GetPendingDeliveries returns deliveries due for processing.
func (WebhookDelivery) TableName ¶ added in v0.2.7
func (WebhookDelivery) TableName() string
type WebhookEvent ¶ added in v0.2.7
type WebhookEvent struct {
ID string `gorm:"primaryKey;size:36" json:"id"` // UUID
EventType string `gorm:"column:event_type;size:64;not null;index" json:"eventType"`
ResourceType string `gorm:"column:resource_type;size:32;not null" json:"resourceType"` // bucket, object, share, presign
ResourcePath string `gorm:"column:resource_path;size:1280" json:"resourcePath"` // bucket/key
Actor string `gorm:"column:actor;size:255" json:"actor"` // access_key_id or "session"
PayloadJSON string `gorm:"column:payload_json;type:text" json:"payloadJson"`
CreatedAt time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP;index" json:"createdAt"`
}
WebhookEvent represents a recorded event.
func (WebhookEvent) TableName ¶ added in v0.2.7
func (WebhookEvent) TableName() string