mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-05 19:59:29 -05:00
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package publink
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/shroff/phylum/server/internal/command/common"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func setupListCommand() *cobra.Command {
|
|
cmd := cobra.Command{
|
|
Use: "list <path>",
|
|
Short: "List Publinks",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
f := common.UserFileSystem(cmd)
|
|
pathOrUUID := args[0]
|
|
r, err := f.ResourceByPathWithRoot(pathOrUUID)
|
|
if err != nil {
|
|
fmt.Println("cannot list publinks for '" + pathOrUUID + "': " + err.Error())
|
|
os.Exit(1)
|
|
}
|
|
links, err := r.ListPublinks()
|
|
if err != nil {
|
|
fmt.Println("cannot list publinks for '" + pathOrUUID + "': " + err.Error())
|
|
os.Exit(1)
|
|
}
|
|
for _, l := range links {
|
|
fmt.Print(l.ID)
|
|
fmt.Printf(": accessed %d", l.Accessed)
|
|
if l.AccessLimit > 0 {
|
|
fmt.Printf("/%d", l.AccessLimit)
|
|
}
|
|
fmt.Print(" times")
|
|
if l.PasswordHash != "" {
|
|
fmt.Print(", password protected")
|
|
}
|
|
if l.Expires != 0 {
|
|
expires := time.UnixMilli(l.Expires)
|
|
if expires.Before(time.Now()) {
|
|
fmt.Print(", EXPIRED ")
|
|
} else {
|
|
fmt.Print(", expires")
|
|
}
|
|
fmt.Print(expires.Format(time.RFC1123))
|
|
}
|
|
fmt.Println()
|
|
}
|
|
},
|
|
}
|
|
return &cmd
|
|
}
|