summaryrefslogtreecommitdiff
path: root/app/controllers/client_list.go
blob: f6531da70ac936e7614822336fe153366d107ee1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package controllers

import (
	"io/fs"
	"net/http"
	"time"

	"github.com/labstack/echo/v4"
)

type clientEntry struct {
	Filename     string
	LastModified time.Time
	ByteSize     int64
}

func ListClients(clients fs.FS) echo.HandlerFunc {
	return func(c echo.Context) error {
		out := struct{ Models []clientEntry }{[]clientEntry{}}

		fs.WalkDir(clients, "clients", func(path string, d fs.DirEntry, err error) error {
			if path == "clients/keep" || d.IsDir() {
				return nil
			}
			fi, err := d.Info()
			if err != nil {
				return err
			}
			out.Models = append(out.Models, clientEntry{
				Filename:     d.Name(),
				LastModified: fi.ModTime(),
				ByteSize:     fi.Size(),
			})
			return nil
		})

		return c.Render(http.StatusOK, "client_index.tpl", out)
	}
}