feat: re-architect folder uploads with batching and concurrency limits, add TUS stale cleanup routine
Some checks failed
Automated Container Build / build-and-push (push) Failing after 15s

This commit is contained in:
Elijah 2026-05-23 13:41:49 -07:00
parent b668418951
commit 3e34a37c95
2 changed files with 73 additions and 38 deletions

View file

@ -12,6 +12,7 @@ import (
"strconv"
"strings"
"sync"
"time"
"git.elijahkuntz.com/Elijah/drive/config"
"git.elijahkuntz.com/Elijah/drive/database"
@ -41,11 +42,42 @@ type tusUpload struct {
}
func NewTusHandler(db *database.DB, cfg *config.Config) *TusHandler {
return &TusHandler{
h := &TusHandler{
DB: db,
Config: cfg,
uploads: make(map[string]*tusUpload),
}
go h.cleanupStaleUploads()
return h
}
func (h *TusHandler) cleanupStaleUploads() {
ticker := time.NewTicker(1 * time.Hour)
for range ticker.C {
tempDir := filepath.Join(h.Config.StorageDir, ".uploads")
entries, err := os.ReadDir(tempDir)
if err != nil {
continue
}
cutoff := time.Now().Add(-24 * time.Hour)
for _, entry := range entries {
info, err := entry.Info()
if err != nil {
continue
}
if info.ModTime().Before(cutoff) {
path := filepath.Join(tempDir, entry.Name())
os.Remove(path)
h.mu.Lock()
delete(h.uploads, entry.Name())
h.mu.Unlock()
}
}
}
}
// Options returns tus protocol capability headers.