diff --git a/server/main.go b/server/main.go index b7bd5b7..9186ab1 100644 --- a/server/main.go +++ b/server/main.go @@ -392,6 +392,7 @@ func startCleanupScheduler() { go func() { for range ticker.C { cleanupChunks() + cleanupOldFiles() } }() } @@ -405,3 +406,13 @@ func cleanupChunks() { fmt.Printf("error cleaning up chunks: %v\n", err) } } + +func cleanupOldFiles() { + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + defer cancel() + + _, err := db.ExecContext(ctx, "DELETE FROM files WHERE created_at < NOW() - INTERVAL '1 day'") + if err != nil { + fmt.Printf("error cleaning up old files: %v\n", err) + } +}