One self-hosted app for your shows, movies and music.
HolyArrs 1.0.2
CoderLuii08a8c7681240
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 91d9370..ab91a0a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,18 @@All notable changes to HolyArrs are listed here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow [Semantic Versioning](https://semver.org/).+## 1.0.2++### Changed++- The metadata server's address is now `api.holyarrs.com`. The old one keeps working. ([#164](https://github.com/HolyArrs/HolyArrs/issues/164))++### Fixed++- First-run setup can be read in light mode. ([#161](https://github.com/HolyArrs/HolyArrs/issues/161))+- An install the metadata server no longer knows gets a new key by itself. ([#162](https://github.com/HolyArrs/HolyArrs/issues/162))+- Moving over: the screens now say your media files are never moved. ([#163](https://github.com/HolyArrs/HolyArrs/issues/163))+## 1.0.1### Addeddiff --git a/VERSION b/VERSIONindex 7dea76e..6d7de6e 100644--- a/VERSION+++ b/VERSION@@ -1 +1 @@-1.0.1+1.0.2diff --git a/app/backend/cmd/holyarrs/main.go b/app/backend/cmd/holyarrs/main.goindex 881b872..5327a68 100644--- a/app/backend/cmd/holyarrs/main.go+++ b/app/backend/cmd/holyarrs/main.go@@ -455,7 +455,7 @@ func serve(ctx context.Context, c config, o runOpts) error {library.UseSubtitleNames(subtitles.Names{})lib := &library.Service{Store: s, Queue: q, Metadata: md, Live: hub, SavePath: c.SavePath, ArtistImages: pictures,ImageServer: hosted.Service.Base() + "/v1/img",- Artwork: &library.ArtworkCache{Dir: filepath.Join(c.ConfigDir, "artwork"), Allowed: []string{metadata.ImageBase + "/", hosted.Service.Base() + "/v1/img/"},+ Artwork: &library.ArtworkCache{Dir: filepath.Join(c.ConfigDir, "artwork"), Allowed: []string{metadata.ImageBase + "/", hosted.Service.Base() + "/v1/img/", metadata.OldPictures(hosted.Service.Base())},HTTP: artworkHTTP, Fallback: library.TMDBPassThrough(hosted.Service.Base())}}// TMDB copies are kept at most six months (TMDB's rule).go lib.Artwork.KeepTMDBFresh(ctx)diff --git a/app/backend/internal/metadata/hosted.go b/app/backend/internal/metadata/hosted.goindex 624208e..ace4396 100644--- a/app/backend/internal/metadata/hosted.go+++ b/app/backend/internal/metadata/hosted.go@@ -15,7 +15,11 @@ import (// DefaultServiceURL is the HolyArrs metadata server every install uses by// default. It is the one place the address lives; EnvServiceURL overrides it.-const DefaultServiceURL = "https://holyarrs-api.coderluii.dev"+const DefaultServiceURL = "https://api.holyarrs.com"++// OldServiceURL is the server's first address. It answers until version 2,+// and the server still writes picture addresses with it.+const OldServiceURL = "https://holyarrs-api.coderluii.dev"// EnvServiceURL names the metadata server address override.const EnvServiceURL = "HOLYARRS_METADATA_URL"diff --git a/app/backend/internal/metadata/hosted_service.go b/app/backend/internal/metadata/hosted_service.goindex 324ac53..021e088 100644--- a/app/backend/internal/metadata/hosted_service.go+++ b/app/backend/internal/metadata/hosted_service.go@@ -11,6 +11,7 @@ import ("strconv""strings""sync"+ "time""github.com/HolyArrs/holyarrs/app/backend/internal/core/database"@@ -61,7 +62,7 @@ func NewHosted(v *secrets.Vault) (*Hosted, error) {// One pooled HTTP/2 transport for every call to the server: text// answers here, and the server's pictures through the artwork client.tr := &Gate{Next: NewServerTransport(d.DialContext)}- cl := &http.Client{Transport: tr, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}+ cl := &http.Client{Transport: keyCheck{next: tr, refused: dropUnknownKey(v)}, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}h := &Hosted{HTTP: cl, Transport: tr, Gate: tr}access := installationAccess(v, func(ctx context.Context) (string, error) { return h.Service.Register(ctx) })service, err := NewService(ServiceOptions{URL: ServiceURL(), HTTP: cl, Access: access, AllowLocal: local})@@ -106,8 +107,8 @@ func (h *Hosted) TMDB() *TMDB {// installationAccess reads the install's credential: from the file named by// HOLYARRS_METADATA_SERVICE_TOKEN_FILE (read on each call), else from the// vault. A fresh install has none yet: it registers once with the server and-// keeps the answer. A refused credential is never replaced by registering-// again, so a revocation sticks.+// keeps the answer. A credential the server no longer knows is dropped by+// dropUnknownKey, and the next call registers again.func installationAccess(v *secrets.Vault, register func(context.Context) (string, error)) func(context.Context) (string, error) {if path := os.Getenv("HOLYARRS_METADATA_SERVICE_TOKEN_FILE"); path != "" {return func(context.Context) (string, error) {@@ -147,3 +148,54 @@ func installationAccess(v *secrets.Vault, register func(context.Context) (stringreturn tok, nil}}++// keyCheck watches the server's answers: a 401 to a call that carried the+// install's credential means the server does not know it (any more).+type keyCheck struct {+ next http.RoundTripper+ refused func(tok string)+}++func (k keyCheck) RoundTrip(req *http.Request) (*http.Response, error) {+ resp, err := k.next.RoundTrip(req)+ if err == nil && resp.StatusCode == http.StatusUnauthorized && k.refused != nil {+ if tok, ok := strings.CutPrefix(req.Header.Get("Authorization"), "Bearer "); ok && tok != "" {+ k.refused(tok)+ }+ }+ return resp, err+}++// unknownKeyWait is the least time between two dropped credentials. The+// server gives an address only a few registrations an hour.+const unknownKeyWait = 30 * time.Minute++// dropUnknownKey forgets the stored credential when the server refused+// exactly that one, so the next call registers a new one. The server drops+// credentials on its own (idle ones, or to make room); without this the+// install would stay refused for good. A credential from the token file is+// the owner's to change and is left alone.+func dropUnknownKey(v *secrets.Vault) func(string) {+ if v == nil || os.Getenv("HOLYARRS_METADATA_SERVICE_TOKEN_FILE") != "" {+ return nil+ }+ var mu sync.Mutex+ var last time.Time+ return func(tok string) {+ mu.Lock()+ defer mu.Unlock()+ if !last.IsZero() && time.Since(last) < unknownKeyWait {+ return+ }+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)+ defer cancel()+ if cur, err := v.Setting(ctx, installationGroup, installationKey); err != nil || cur != tok {+ return+ }+ if err := v.SetSetting(ctx, installationGroup, installationKey, "", database.System); err != nil {+ return+ }+ last = time.Now()+ log.Printf("metadata: the server no longer knows this install; registering again")+ }+}diff --git a/app/backend/internal/metadata/hosted_test.go b/app/backend/internal/metadata/hosted_test.goindex 4792910..4a90456 100644--- a/app/backend/internal/metadata/hosted_test.go+++ b/app/backend/internal/metadata/hosted_test.go@@ -12,7 +12,7 @@ import (func TestServiceURLDefaultAndOverride(t *testing.T) {t.Setenv(EnvServiceURL, "")- if ServiceURL() != "https://holyarrs-api.coderluii.dev" {+ if ServiceURL() != "https://api.holyarrs.com" {t.Fatal(ServiceURL())}t.Setenv(EnvServiceURL, " https://meta.example.test/ ")diff --git a/app/backend/internal/metadata/picture_host.go b/app/backend/internal/metadata/picture_host.gonew file mode 100644index 0000000..e8ad6bc--- /dev/null+++ b/app/backend/internal/metadata/picture_host.go@@ -0,0 +1,58 @@+package metadata++import (+ "bytes"+ "io"+ "net/http"+ "strconv"+ "strings"+)++// pictureHost makes the server's answers name pictures on the address this+// install talks to. The server still writes them with its first address;+// the rest of the app only takes pictures under its own.+type pictureHost struct {+ next http.RoundTripper+ old, own string+}++func (p pictureHost) RoundTrip(req *http.Request) (*http.Response, error) {+ next := p.next+ if next == nil {+ next = http.DefaultTransport+ }+ resp, err := next.RoundTrip(req)+ if err != nil || !strings.Contains(resp.Header.Get("Content-Type"), "json") {+ return resp, err+ }+ // Answers are small; one too big to hold is passed on as it came.+ const most = 32 << 20+ head, rerr := io.ReadAll(io.LimitReader(resp.Body, most+1))+ if rerr != nil || len(head) > most {+ resp.Body = struct {+ io.Reader+ io.Closer+ }{io.MultiReader(bytes.NewReader(head), resp.Body), resp.Body}+ if rerr != nil {+ _ = resp.Body.Close()+ return nil, rerr+ }+ return resp, nil+ }+ _ = resp.Body.Close()+ body := bytes.ReplaceAll(head, []byte(p.old), []byte(p.own))+ resp.Body = io.NopCloser(bytes.NewReader(body))+ resp.ContentLength = int64(len(body))+ resp.Header.Set("Content-Length", strconv.Itoa(len(body)))+ return resp, nil+}++// OldPictures is the first address's picture store when base is the+// official server (a dead address otherwise): pictures saved before the address+// changed still load from it.+func OldPictures(base string) string {+ if base != DefaultServiceURL {+ return "https://invalid.invalid/"+ }+ return OldServiceURL + "/v1/img/"+}diff --git a/app/backend/internal/metadata/picture_host_test.go b/app/backend/internal/metadata/picture_host_test.gonew file mode 100644index 0000000..883f281--- /dev/null+++ b/app/backend/internal/metadata/picture_host_test.go@@ -0,0 +1,42 @@+package metadata++import (+ "io"+ "net/http"+ "strings"+ "testing"+)++type fixedAnswer struct{ ctype, body string }++func (f fixedAnswer) RoundTrip(*http.Request) (*http.Response, error) {+ return &http.Response{StatusCode: 200, ContentLength: -1, Header: http.Header{"Content-Type": {f.ctype}}, Body: io.NopCloser(strings.NewReader(f.body))}, nil+}++// Picture addresses on the first address come back on the install's own;+// anything that is not JSON is left alone.+func TestPictureHostSwapsOldAddress(t *testing.T) {+ old, own := OldServiceURL+"/v1/img/", DefaultServiceURL+"/v1/img/"+ read := func(ctype, body string) string {+ resp, err := pictureHost{next: fixedAnswer{ctype, body}, old: old, own: own}.RoundTrip(&http.Request{})+ if err != nil {+ t.Fatal(err)+ }+ b, _ := io.ReadAll(resp.Body)+ if resp.ContentLength >= 0 && int(resp.ContentLength) != len(b) {+ t.Fatalf("length says %d, body is %d", resp.ContentLength, len(b))+ }+ return string(b)+ }+ in := `{"logo":"` + old + `logo/603/500.png","site":"` + OldServiceURL + `/v1/other"}`+ want := `{"logo":"` + own + `logo/603/500.png","site":"` + OldServiceURL + `/v1/other"}`+ if got := read("application/json; charset=utf-8", in); got != want {+ t.Fatalf("got %s", got)+ }+ if got := read("image/webp", in); got != in {+ t.Fatalf("a picture was changed: %s", got)+ }+ if OldPictures(DefaultServiceURL) != old || strings.Contains(OldPictures("https://my.server"), "holyarrs") {+ t.Fatal("old pictures are only allowed on the official server")+ }+}diff --git a/app/backend/internal/metadata/service.go b/app/backend/internal/metadata/service.goindex a40eff2..fca00c4 100644--- a/app/backend/internal/metadata/service.go+++ b/app/backend/internal/metadata/service.go@@ -105,6 +105,9 @@ func NewService(o ServiceOptions) (*Service, error) {cl := *o.HTTPcl.Jar = nilcl.Timeout = 18 * time.Second+ if u.String() == DefaultServiceURL {+ cl.Transport = pictureHost{next: cl.Transport, old: OldServiceURL + "/v1/img/", own: DefaultServiceURL + "/v1/img/"}+ }cl.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }u.Path = ""return &Service{base: u.String(), access: o.Access, http: &cl}, nildiff --git a/app/backend/internal/metadata/unknown_key_test.go b/app/backend/internal/metadata/unknown_key_test.gonew file mode 100644index 0000000..35343c7--- /dev/null+++ b/app/backend/internal/metadata/unknown_key_test.go@@ -0,0 +1,52 @@+package metadata++import (+ "context"+ "net/http"+ "testing"+)++type statusAnswer int++func (s statusAnswer) RoundTrip(*http.Request) (*http.Response, error) {+ return &http.Response{StatusCode: int(s), Body: http.NoBody, Header: http.Header{}}, nil+}++// A credential the server no longer knows is dropped once, and the next+// call registers a new one. Other answers, and other credentials, change+// nothing.+func TestUnknownKeyRegistersAgain(t *testing.T) {+ t.Setenv("HOLYARRS_METADATA_SERVICE_TOKEN_FILE", "")+ v := testVault(t)+ ctx := context.Background()+ refused := dropUnknownKey(v)+ n := 0+ access := installationAccess(v, func(context.Context) (string, error) {+ n+++ return []string{"first-credential-000000", "second-credential-00000", "third-credential-000000"}[n-1], nil+ })+ call := func(status int, tok string) {+ req, _ := http.NewRequest(http.MethodGet, "https://example.org/v1/x", nil)+ req.Header.Set("Authorization", "Bearer "+tok)+ if _, err := (keyCheck{next: statusAnswer(status), refused: refused}).RoundTrip(req); err != nil {+ t.Fatal(err)+ }+ }+ first, _ := access(ctx)+ call(200, first)+ call(429, first)+ call(401, "someone-elses-credential")+ if tok, _ := access(ctx); tok != first || n != 1 {+ t.Fatalf("dropped without a refusal: %q after %d registrations", tok, n)+ }+ call(401, first)+ second, _ := access(ctx)+ if second == first || n != 2 {+ t.Fatalf("no new credential after a refusal: %q after %d registrations", second, n)+ }+ // Refused again straight away: it waits, so a broken server is not flooded.+ call(401, second)+ if tok, _ := access(ctx); tok != second || n != 2 {+ t.Fatalf("registered again without waiting: %q after %d", tok, n)+ }+}diff --git a/app/backend/internal/updates/list.go b/app/backend/internal/updates/list.goindex 1a8d79c..cd91853 100644--- a/app/backend/internal/updates/list.go+++ b/app/backend/internal/updates/list.go@@ -15,7 +15,7 @@ import (// Where the update list is read.const (// DefaultURL is the metadata server's copy.- DefaultURL = "https://holyarrs-api.coderluii.dev/v1/manifest.json"+ DefaultURL = "https://api.holyarrs.com/v1/manifest.json"// PagesURL is the GitHub Pages copy, tried when the server fails.// Empty until the Pages copy is published.PagesURL = ""diff --git a/app/frontend/src/lib/migrate/ChooseStep.svelte b/app/frontend/src/lib/migrate/ChooseStep.svelteindex ba0678e..8b4d598 100644--- a/app/frontend/src/lib/migrate/ChooseStep.svelte+++ b/app/frontend/src/lib/migrate/ChooseStep.svelte@@ -258,6 +258,7 @@{#if tiles.length === 0}<div class="tile"><span class="sub">Nothing switched on</span></div>{/if}</div>{#if restLine}<p class="sub also">{restLine}</p>{/if}+ <p class="sub also" data-testid="move-files-stay">Titles and settings only. Your files stay where they are.</p>{/if}{#if needFolders.length}diff --git a/app/frontend/src/lib/migrate/ReadStep.svelte b/app/frontend/src/lib/migrate/ReadStep.svelteindex d9503f8..429fb7b 100644--- a/app/frontend/src/lib/migrate/ReadStep.svelte+++ b/app/frontend/src/lib/migrate/ReadStep.svelte@@ -65,7 +65,7 @@<EmptyStateicon="upload"title="Bring your old apps over"- text="Read Sonarr, Radarr and the others. Nothing moves until you say so."+ text="Read Sonarr, Radarr and the others. Your media files are never moved."action={{ label: 'Add an app', icon: 'plus', onclick: onadd }}/>{:else}diff --git a/app/frontend/src/routes/welcome/+page.svelte b/app/frontend/src/routes/welcome/+page.svelteindex 4b6a3ef..629ac36 100644--- a/app/frontend/src/routes/welcome/+page.svelte+++ b/app/frontend/src/routes/welcome/+page.svelte@@ -248,7 +248,7 @@media: { h: 'Where’s your media?', p: 'Turn on what you collect and add its folder.' },downloader: { h: 'Which app downloads?', p: 'Connect the one you use.' },source: { h: 'Where should we search?', p: 'Link Prowlarr or Jackett and your sites come with it.' },- import: { h: 'Bring your apps', p: 'We only read them. Nothing moves until you say so.' },+ import: { h: 'Bring your apps', p: 'We only read them. Your media files are never moved.' },done: { h: 'You’re set', p: 'Find something on Home and we’ll get it.' }};const head = $derived(@@ -265,7 +265,8 @@<svelte:head><title>{head.h} · HolyArrs</title></svelte:head>{#if firstRun}<SigninBackdrop /><div class="dim" aria-hidden="true"></div>{/if}-<div class="welcome" class:over-art={firstRun}>+<!-- First run sits on a dark picture with white text, so its cards and sheets use the dark colours in any theme. -->+<div class="welcome" class:over-art={firstRun} data-theme={firstRun ? 'dark' : undefined}><!-- First run keeps the sign-in look: the same moving backdrop behind one glass panel. --><div class="sheet" class:glass={firstRun} class:light={theme.value === 'light'} data-signin-panel={firstRun ? '' : undefined}><div class="brand"><img src={to(mark)} alt={firstRun ? 'HolyArrs' : ''} width={firstRun ? 28 : 32} height={firstRun ? 28 : 32} />{#if !firstRun}<span>HolyArrs</span>{/if}</div>diff --git a/docs/library/metadata.md b/docs/library/metadata.mdindex b1abbd4..035696e 100644--- a/docs/library/metadata.md+++ b/docs/library/metadata.md@@ -53,7 +53,7 @@ Never sent: your files, folder paths or file names; your library, downloads or h| Variable | Does | Default ||---|---|---|-| `HOLYARRS_METADATA_URL` | Points HolyArrs at another metadata server. Restart after changing | `https://holyarrs-api.coderluii.dev` |+| `HOLYARRS_METADATA_URL` | Points HolyArrs at another metadata server. Restart after changing | `https://api.holyarrs.com` || `HOLYARRS_TMDB_KEY` | Your own TMDB read token. Movie and show lookups go to TMDB directly | Empty || `HOLYARRS_DEEZER_URL=off` | Turns off artist top songs | On |diff --git a/docs/reference/env-vars.md b/docs/reference/env-vars.mdindex b069f05..c537a67 100644--- a/docs/reference/env-vars.md+++ b/docs/reference/env-vars.md@@ -74,7 +74,7 @@ A bad setup stops HolyArrs from starting. Steps are in [Sign-in and passwords](.| Variable | What it does | Default || --- | --- | --- |-| `HOLYARRS_METADATA_URL` | The metadata server address. | `https://holyarrs-api.coderluii.dev` |+| `HOLYARRS_METADATA_URL` | The metadata server address. | `https://api.holyarrs.com` || `HOLYARRS_TMDB_KEY` | Your own TMDB read access token. Set, TMDB reads go straight to TMDB instead of the metadata server. | none || `HOLYARRS_METADATA_SERVICE_TOKEN_FILE` | File holding this install's metadata server credential, read on each call. Unset, the credential lives in the vault. | none |