summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-30 16:42:23 +0300
committerPaul Buetow <paul@buetow.org>2026-04-30 16:42:23 +0300
commitfea0840ea65afb2b29abb378bd3c96697e0bbf4b (patch)
tree9e18fa9d56ecae1a8c3014434eae9a5da82e3919 /internal/api
parent6662a07a58d8d64792501864893ba543581c4dd8 (diff)
task ia: fix media listing/filtering semantics (favorites bool, filesize filters, permission scoping)
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/handlers.go16
-rw-r--r--internal/api/handlers_more_test.go8
-rw-r--r--internal/api/handlers_test.go4
3 files changed, 18 insertions, 10 deletions
diff --git a/internal/api/handlers.go b/internal/api/handlers.go
index e964b92..46ab41e 100644
--- a/internal/api/handlers.go
+++ b/internal/api/handlers.go
@@ -352,10 +352,8 @@ func parseMediaListQuery(q url.Values) repository.MediaFilter {
t := model.MediaType(v)
filter.Type = &t
}
- if v := q.Get("favorites"); v != "" {
- if uid, err := strconv.ParseInt(v, 10, 64); err == nil {
- filter.Favorites = &uid
- }
+ if v := q.Get("favorites"); v == "true" || v == "1" {
+ filter.Favorites = true
}
if v := q.Get("tags"); v != "" {
filter.Tags = strings.Split(v, ",")
@@ -370,6 +368,16 @@ func parseMediaListQuery(q url.Values) repository.MediaFilter {
filter.MaxDuration = &f
}
}
+ if v := q.Get("filesize_min"); v != "" {
+ if n, err := strconv.ParseInt(v, 10, 64); err == nil {
+ filter.MinFileSize = &n
+ }
+ }
+ if v := q.Get("filesize_max"); v != "" {
+ if n, err := strconv.ParseInt(v, 10, 64); err == nil {
+ filter.MaxFileSize = &n
+ }
+ }
if v := q.Get("limit"); v != "" {
if n, err := strconv.Atoi(v); err == nil && n > 0 && n <= 1000 {
filter.Limit = n
diff --git a/internal/api/handlers_more_test.go b/internal/api/handlers_more_test.go
index 1939349..13c57cf 100644
--- a/internal/api/handlers_more_test.go
+++ b/internal/api/handlers_more_test.go
@@ -1705,13 +1705,13 @@ func Test_parseMediaListQuery_defaults(t *testing.T) {
if got.Search != want.Search || got.Sort != want.Sort || got.Limit != want.Limit || got.Offset != want.Offset {
t.Fatalf("unexpected defaults: %+v", got)
}
- if got.SetID != nil || got.Type != nil || got.Favorites != nil || got.MinDuration != nil || got.MaxDuration != nil {
+ if got.SetID != nil || got.Type != nil || got.Favorites != false || got.MinDuration != nil || got.MaxDuration != nil {
t.Fatalf("expected nil optional fields, got %+v", got)
}
}
func Test_parseMediaListQuery_allParams(t *testing.T) {
- q := mustParseQuery(t, "/api/media?search=foo&sort=name&set_id=7&type=video&favorites=3&tags=bar,baz&min_duration=10&max_duration=100&limit=50&offset=10")
+ q := mustParseQuery(t, "/api/media?search=foo&sort=name&set_id=7&type=video&favorites=true&tags=bar,baz&min_duration=10&max_duration=100&limit=50&offset=10")
got := parseMediaListQuery(q)
if got.Search != "foo" {
t.Fatalf("unexpected search: %q", got.Search)
@@ -1725,7 +1725,7 @@ func Test_parseMediaListQuery_allParams(t *testing.T) {
if got.Type == nil || *got.Type != "video" {
t.Fatalf("unexpected type: %v", got.Type)
}
- if got.Favorites == nil || *got.Favorites != 3 {
+ if got.Favorites != true {
t.Fatalf("unexpected favorites: %v", got.Favorites)
}
if len(got.Tags) != 2 || got.Tags[0] != "bar" || got.Tags[1] != "baz" {
@@ -1786,7 +1786,7 @@ func Test_parseMediaListQuery_limitClampingAndNegativeOffset(t *testing.T) {
if tt.invalidKey == "set_id" && got.SetID != nil {
t.Fatalf("expected set_id nil for bad value, got %v", got.SetID)
}
- if tt.invalidKey == "favorites" && got.Favorites != nil {
+ if tt.invalidKey == "favorites" && got.Favorites != false {
t.Fatalf("expected favorites nil for bad value, got %v", got.Favorites)
}
if tt.invalidKey == "min_duration" && got.MinDuration != nil {
diff --git a/internal/api/handlers_test.go b/internal/api/handlers_test.go
index 89aa177..8c2161c 100644
--- a/internal/api/handlers_test.go
+++ b/internal/api/handlers_test.go
@@ -577,8 +577,8 @@ func TestServer_MediaList(t *testing.T) {
},
{
name: "with query params",
- query: "?set_id=1&type=video&search=foo&tags=bar,baz&favorites=2&min_duration=10&max_duration=100&sort=name&limit=5&offset=10",
- filter: repository.MediaFilter{SetID: intPtr(1), Type: (*model.MediaType)(func() *string { s := "video"; return &s }()), Search: "foo", Tags: []string{"bar", "baz"}, Favorites: intPtr(2), MinDuration: floatPtr(10), MaxDuration: floatPtr(100), Sort: "name", Limit: 5, Offset: 10},
+ query: "?set_id=1&type=video&search=foo&tags=bar,baz&favorites=true&min_duration=10&max_duration=100&sort=name&limit=5&offset=10",
+ filter: repository.MediaFilter{SetID: intPtr(1), Type: (*model.MediaType)(func() *string { s := "video"; return &s }()), Search: "foo", Tags: []string{"bar", "baz"}, Favorites: true, MinDuration: floatPtr(10), MaxDuration: floatPtr(100), Sort: "name", Limit: 5, Offset: 10},
listResult: []model.Media{},
wantCode: http.StatusOK,
},