diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-07 15:41:49 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-07 15:41:49 +0300 |
| commit | 3f70adb2c24d558be645aacb11a97d5f95f69b76 (patch) | |
| tree | ed9c75d0f7af72376aa9b90cb7a28efbad3251b2 /internal/api | |
| parent | d256dae86f876c972396b575a3743543749cdeb5 (diff) | |
i1 omit empty share thumbnail URL
Diffstat (limited to 'internal/api')
| -rw-r--r-- | internal/api/handlers_more_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
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(`<script><!--SHARE_MEDIA--></script>`, 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(`<script><!--SHARE_MEDIA--></script>`, map[string]any{"bad": make(chan int)}) if err == nil { |
