feat: add upload policies, daily limits, and storage quotas
All checks were successful
Build and Publish Docker Image / deploy (push) Successful in 1m8s
All checks were successful
Build and Publish Docker Image / deploy (push) Successful in 1m8s
- Add environment variables to configure anonymous uploads, daily upload caps, and default user storage limits. - Update config loader to parse and validate the new settings. - Implement backend logic to track daily usage and active storage per user. - Update README and `.env.example` to document the new settings and admin panels.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDeleteTokenVerification(t *testing.T) {
|
||||
@@ -59,6 +60,39 @@ func TestDeleteBoxWithTokenRemovesMetadataAndFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserActiveStorageUsedIgnoresExpiredBoxes(t *testing.T) {
|
||||
service := newTestUploadService(t)
|
||||
active, err := service.CreateBox(testFileHeaders(t, "file", "active.txt", "active"), UploadOptions{MaxDays: 1, OwnerID: "user-1"})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateBox active returned error: %v", err)
|
||||
}
|
||||
expired, err := service.CreateBox(testFileHeaders(t, "file", "expired.txt", "expired"), UploadOptions{MaxDays: 1, OwnerID: "user-1"})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateBox expired returned error: %v", err)
|
||||
}
|
||||
expiredBox, err := service.GetBox(expired.BoxID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetBox returned error: %v", err)
|
||||
}
|
||||
expiredBox.ExpiresAt = time.Now().UTC().Add(-time.Hour)
|
||||
if err := service.SaveBox(expiredBox); err != nil {
|
||||
t.Fatalf("SaveBox returned error: %v", err)
|
||||
}
|
||||
|
||||
activeBox, err := service.GetBox(active.BoxID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetBox active returned error: %v", err)
|
||||
}
|
||||
want := activeBox.Files[0].Size
|
||||
got, err := service.UserActiveStorageUsed("user-1")
|
||||
if err != nil {
|
||||
t.Fatalf("UserActiveStorageUsed returned error: %v", err)
|
||||
}
|
||||
if got != want {
|
||||
t.Fatalf("UserActiveStorageUsed = %d, want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func newTestUploadService(t *testing.T) *UploadService {
|
||||
t.Helper()
|
||||
service, err := NewUploadService(1024*1024, t.TempDir(), "http://example.test", slog.New(slog.NewTextHandler(io.Discard, nil)))
|
||||
|
||||
Reference in New Issue
Block a user