Add poster image support to Matrix download listings
Some checks failed
Test action / kaas (push) Failing after 2s
Some checks failed
Test action / kaas (push) Failing after 2s
- Fetch and display poster images for tracked items in Matrix - Show monitored/unmonitored icons in listings - Limit displayed items to 12, with count and overflow message - Add tests for image fetching and formatting - Enable Grafana datasources - Fix Sonarr/Radarr URL config bug
This commit is contained in:
parent
e07257e137
commit
100a218aed
9 changed files with 432 additions and 59 deletions
80
packages/arrtrix/pkg/arrclient/client_test.go
Normal file
80
packages/arrtrix/pkg/arrclient/client_test.go
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
package arrclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestImageURLPrefersPosterAndResolvesRelativePath(t *testing.T) {
|
||||
baseURL, err := url.Parse("https://radarr.example")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse base URL: %v", err)
|
||||
}
|
||||
|
||||
client := &httpClient{baseURL: baseURL}
|
||||
imageURL := client.imageURL([]mediaImage{
|
||||
{CoverType: "fanart", URL: "/MediaCover/1/fanart.jpg"},
|
||||
{CoverType: "poster", URL: "/MediaCover/1/poster.jpg"},
|
||||
})
|
||||
if imageURL != "https://radarr.example/MediaCover/1/poster.jpg" {
|
||||
t.Fatalf("unexpected image URL %q", imageURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageURLFallsBackToRemoteURL(t *testing.T) {
|
||||
baseURL, err := url.Parse("https://sonarr.example")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse base URL: %v", err)
|
||||
}
|
||||
|
||||
client := &httpClient{baseURL: baseURL}
|
||||
imageURL := client.imageURL([]mediaImage{
|
||||
{CoverType: "poster", RemoteURL: "https://images.example/poster.jpg"},
|
||||
})
|
||||
if imageURL != "https://images.example/poster.jpg" {
|
||||
t.Fatalf("unexpected remote image URL %q", imageURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchImageUsesAPIKeyForSameHost(t *testing.T) {
|
||||
headers := make(chan string, 1)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
headers <- r.Header.Get("X-Api-Key")
|
||||
w.Header().Set("Content-Type", "image/jpeg")
|
||||
_, _ = w.Write([]byte("jpeg-bytes"))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client, err := newHTTPClient(server.URL, "secret")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create client: %v", err)
|
||||
}
|
||||
|
||||
asset, err := client.FetchImage(context.Background(), ManagedItem{
|
||||
ID: 42,
|
||||
Title: "Dune Part Two",
|
||||
ImageURL: server.URL + "/MediaCover/42/poster.jpg",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to fetch image: %v", err)
|
||||
}
|
||||
if asset == nil {
|
||||
t.Fatal("expected media asset")
|
||||
}
|
||||
if got := <-headers; got != "secret" {
|
||||
t.Fatalf("expected API key header, got %q", got)
|
||||
}
|
||||
if got := string(asset.Data); got != "jpeg-bytes" {
|
||||
t.Fatalf("unexpected media bytes %q", got)
|
||||
}
|
||||
if asset.MimeType != "image/jpeg" {
|
||||
t.Fatalf("unexpected mime type %q", asset.MimeType)
|
||||
}
|
||||
if !strings.HasPrefix(asset.FileName, "Dune-Part-Two-42") || !strings.HasSuffix(asset.FileName, ".jpg") {
|
||||
t.Fatalf("unexpected filename %q", asset.FileName)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue