[server][core][fs] Separate out trash functions into separate files

This commit is contained in:
Abhishek Shroff
2025-03-23 22:04:11 +05:30
parent ab065b3e2c
commit 19a390675f
8 changed files with 337 additions and 308 deletions
+16 -1
View File
@@ -1,6 +1,8 @@
package serve
import (
"time"
"github.com/fvbock/endless"
"github.com/shroff/phylum/server/internal/api/publink"
apiv1 "github.com/shroff/phylum/server/internal/api/v1"
@@ -11,6 +13,8 @@ import (
"github.com/spf13/viper"
)
const trashRetainDuration = 30 * 24 * time.Hour
func SetupCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "serve",
@@ -23,7 +27,7 @@ func SetupCommand() *cobra.Command {
webdav.SetupHandler(engine.Group(config.GetString("webdav_prefix")))
apiv1.Setup(engine.Group("/api/v1"))
publink.Setup(engine.Group("/publink"))
fs.SetupTrashCompactor()
setupTrashCompactor()
server := endless.NewServer(config.GetString("listen"), engine)
server.BeforeBegin = func(addr string) {
@@ -60,3 +64,14 @@ func SetupCommand() *cobra.Command {
return cmd
}
func setupTrashCompactor() {
ticker := time.NewTimer(24 * time.Hour)
go func() {
for {
<-ticker.C
fs.TrashCompact(trashRetainDuration)
}
}()
fs.TrashCompact(trashRetainDuration)
}