diff --git a/README.md b/README.md index ce2805c..50fc341 100644 --- a/README.md +++ b/README.md @@ -123,9 +123,9 @@ Reddit's Data API terms need Reddit's approval for commercial use. Supermarket i ## Signing in to X, LinkedIn and Reddit -Sign-ins come back to Supermarket at `http://localhost:8470/auth//callback`. Register these callback URLs in your apps: +Sign-ins come back to Supermarket at `http://localhost:8470/auth//callback` (X: `127.0.0.1` instead of `localhost`). Register these callback URLs in your apps: -- X developer portal, your app's *User authentication settings*: `http://localhost:8470/auth/x/callback` +- X developer portal, your app's *User authentication settings*: `http://127.0.0.1:8470/auth/x/callback`. X refuses `localhost` in callback URLs; `127.0.0.1` is the same machine, and Supermarket sends X this address. - LinkedIn developer portal, your app's *Auth* tab: `http://localhost:8470/auth/linkedin/callback` - Reddit, [reddit.com/prefs/apps](https://www.reddit.com/prefs/apps): create a **web app** with the redirect URI `http://localhost:8470/auth/reddit/callback`, and put its client ID and secret under Settings → Social accounts diff --git a/internal/web/server.go b/internal/web/server.go index 52c5857..0fda20a 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -69,6 +69,10 @@ func (s *Server) Handler() (http.Handler, error) { mux := http.NewServeMux() static, _ := fs.Sub(staticFS, "static") mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServerFS(static))) + // Browsers ask for /favicon.ico whatever the page says. + mux.HandleFunc("GET /favicon.ico", func(w http.ResponseWriter, r *http.Request) { + http.ServeFileFS(w, r, static, "favicon.ico") + }) mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "ok") }) if s.MCP != nil { mux.Handle("/mcp", s.MCP) diff --git a/internal/web/server_test.go b/internal/web/server_test.go index 371ea9f..4a87875 100644 --- a/internal/web/server_test.go +++ b/internal/web/server_test.go @@ -91,7 +91,7 @@ func TestEveryPageRenders(t *testing.T) { for _, path := range []string{"/", "/?msg=saved", "/settings/profile", "/inventory", "/inventory?relationship=partner", "/inventory/new", "/inventory/1", "/inventory/import", "/inventory/export", - "/settings/ai", "/settings/accounts", "/settings/core", "/static/app.css", "/search", "/search?q=rival", "/search?q=nothing+here", "/static/htmx.min.js", "/healthz", + "/settings/ai", "/settings/accounts", "/settings/core", "/static/app.css", "/favicon.ico", "/static/favicon.png", "/static/logo.png", "/search", "/search?q=rival", "/search?q=nothing+here", "/static/htmx.min.js", "/healthz", "/content", "/content/1", "/content/1?dismissed=1", "/inbox", "/inbox?msg=drafted", "/content/scheduled", "/content/published"} { rec := do(h, http.MethodGet, path, nil, nil) @@ -215,6 +215,18 @@ func TestAccountsKeepAndRemove(t *testing.T) { if s.Secrets.Has(secrets.AnthropicAPIKey) { t.Error("the accounts form saved an AI key") } + // From the page, a save sends back just that card, updated, not a redirect. + rec := do(h, http.MethodPost, "/settings/accounts", strings.NewReader(url.Values{ + "network": {"LinkedIn"}, secrets.LinkedInClientID: {"li"}, secrets.LinkedInClientSecret: {"ls"}}.Encode()), + map[string]string{"Content-Type": "application/x-www-form-urlencoded", "Origin": "http://localhost:8470", "HX-Request": "true"}) + card := rec.Body.String() + if rec.Code != http.StatusOK || !strings.Contains(card, `id="network-LinkedIn"`) || strings.Contains(card, "Social accounts

The keys Supermarket reads posts with, and the sign-ins it publishes with. Keys are kept in secrets.json in Supermarket's data folder, readable only by you; saved values are never shown, and an empty field keeps what's saved.

-{{/* The key fields of every card belong to this one form (form="accounts"), - so each card's Save saves them all, and the sign-in forms aren't nested. */}} -
+{{range .Networks}}{{template "network" .}}{{end}} +{{end}}{{template "settings-end"}}{{end}} -{{range .Networks}}{{$name := .Name}} -
+{{/* One network's card. Its keys form saves in place (htmx swaps the card + for the server's new copy); the sign-in form is a sibling, not nested. */}} +{{define "network"}}{{$set := .Set}}{{$name := .Name}} +

{{.Name}} {{with .Connect}}{{if .Signed}}connected{{with .Account}} as {{.}}{{end}}{{else}}not connected{{end}}{{end}}

- {{range .Fields}} -
- - {{if index $set .Name}}{{end}} -
- {{end}} - +
+ + {{range .Fields}} +
+ + {{if index $set .Name}}{{end}} +
+ {{end}} +
+ + {{if .Saved}}Saved.{{end}} +
+
{{with .Connect}}
{{end}} -{{end}}{{template "settings-end"}}{{end}} diff --git a/internal/web/templates/layout.html b/internal/web/templates/layout.html index 9a9acd1..38fc778 100644 --- a/internal/web/templates/layout.html +++ b/internal/web/templates/layout.html @@ -5,6 +5,9 @@ {{.Title}} · Supermarket + + + @@ -12,7 +15,7 @@