mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-07 20:59:37 -05:00
[server][core][fs] Separate out trash functions into separate files
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user