Skip to content

Commit b2e5500

Browse files
committed
apk: Allow sorting by builddate
This requires manually fiddling with querystring until I come up with something better.
1 parent 3fb24db commit b2e5500

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

internal/apk/apk.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ func (h *handler) renderFS(w http.ResponseWriter, r *http.Request) error {
381381
if short != "" {
382382
qss += "&short=" + short
383383
}
384+
sort := qs.Get("sort")
385+
if short != "" {
386+
qss += "&sort=" + sort
387+
}
384388
p, root, err := splitFsURL(r.URL.Path)
385389
if err != nil {
386390
return err

internal/apk/index.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package apk
22

33
import (
44
"bufio"
5+
"cmp"
56
"encoding/base64"
67
"encoding/hex"
78
"fmt"
@@ -21,13 +22,14 @@ import (
2122
)
2223

2324
type apkindex struct {
24-
origin string
25-
checksum string
26-
name string
27-
version string
28-
apk string
29-
provides map[string]string
30-
depends []string
25+
origin string
26+
checksum string
27+
name string
28+
version string
29+
apk string
30+
provides map[string]string
31+
depends []string
32+
builddate int64
3133
}
3234

3335
type pkginfo struct {
@@ -646,6 +648,12 @@ func (h *handler) renderShort(w http.ResponseWriter, r *http.Request, open func(
646648
return err
647649
}
648650

651+
if r.URL.Query().Get("sort") == "t" {
652+
slices.SortFunc(pkgs, func(a, b apkindex) int {
653+
return cmp.Compare(a.builddate, b.builddate)
654+
})
655+
}
656+
649657
for _, pkg := range pkgs {
650658
if !pkg.needs(depends) {
651659
continue
@@ -779,6 +787,12 @@ func (h *handler) parseIndex(w http.ResponseWriter, r *http.Request, in io.Reade
779787
}
780788
case "D":
781789
pkg.depends = strings.Split(after, " ")
790+
case "t":
791+
i, err := strconv.ParseInt(after, 10, 64)
792+
if err != nil {
793+
return nil, nil, fmt.Errorf("cannot parse build time %s: %w", before, err)
794+
}
795+
pkg.builddate = i
782796
}
783797

784798
if before == "V" {

0 commit comments

Comments
 (0)