2023-06-17 22:58:05 +03:00
|
|
|
package consolecommands
|
2023-06-17 22:52:09 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-06-17 22:58:05 +03:00
|
|
|
func (router *Router) Cleanup(args []string) {
|
2023-06-17 22:52:09 +03:00
|
|
|
if len(args) == 0 {
|
|
|
|
fmt.Println("Expected 1 argument.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
lifetime, err := time.ParseDuration(args[0])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Could not parse duration: %s.\n", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
amount, err := router.Storage.Pastes().DeleteOlderThan(context.Background(), lifetime)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Could not delete pastes: %s.\n", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Printf("Deleted %d pastes older than %s.\n", amount, lifetime)
|
|
|
|
}
|