From 3f70adb2c24d558be645aacb11a97d5f95f69b76 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 7 May 2026 15:41:49 +0300 Subject: i1 omit empty share thumbnail URL --- internal/api/handlers_more_test.go | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'internal/api') diff --git a/internal/api/handlers_more_test.go b/internal/api/handlers_more_test.go index 8333ccc..5d210f2 100644 --- a/internal/api/handlers_more_test.go +++ b/internal/api/handlers_more_test.go @@ -1151,6 +1151,35 @@ func TestServer_SharePage(t *testing.T) { t.Fatalf("unexpected stream_url %q", body.StreamURL) } }) + + t.Run("json omits empty thumbnail url", func(t *testing.T) { + ms := &service.MockMediaService{ + GetSharedMediaFunc: func(ctx context.Context, token string) (*service.GetSharedMediaResult, error) { + return &service.GetSharedMediaResult{ + Media: &service.SharedMediaView{ID: 1, FileName: "share.mp3", Type: model.MediaTypeAudio, Duration: 120}, + HasThumb: false, + StreamURL: "/s/abc/stream", + DownloadURL: "/s/abc/download", + ThumbURL: "", + }, nil + }, + } + srv := newTestServer(t, buildSessionStore(1), nil, nil, cfg, ms, ms, ms, ms, ms, ms, nil, nil, nil, fs) + req := httptest.NewRequest(http.MethodGet, "/s/abc", nil) + req.Header.Set("Accept", "application/json") + rr := httptest.NewRecorder() + srv.ServeHTTP(rr, req) + if rr.Code != http.StatusOK { + t.Fatalf("expected %d, got %d", http.StatusOK, rr.Code) + } + var body map[string]any + if err := json.Unmarshal(rr.Body.Bytes(), &body); err != nil { + t.Fatalf("expected JSON body: %v", err) + } + if _, ok := body["thumb_url"]; ok { + t.Fatalf("expected thumb_url to be omitted, got %s", rr.Body.String()) + } + }) } func TestInjectShareMedia(t *testing.T) { @@ -1164,6 +1193,22 @@ func TestInjectShareMedia(t *testing.T) { } }) + t.Run("omits empty thumbnail url", func(t *testing.T) { + html, err := injectShareMedia(``, service.GetSharedMediaResult{ + Media: &service.SharedMediaView{ID: 1, FileName: "share.mp3", Type: model.MediaTypeAudio}, + HasThumb: false, + StreamURL: "/s/abc/stream", + DownloadURL: "/s/abc/download", + ThumbURL: "", + }) + if err != nil { + t.Fatalf("expected no error, got %v", err) + } + if strings.Contains(html, "thumb_url") { + t.Fatalf("expected no thumb_url in injected JSON, got %q", html) + } + }) + t.Run("returns marshal error", func(t *testing.T) { _, err := injectShareMedia(``, map[string]any{"bad": make(chan int)}) if err == nil { -- cgit v1.2.3