Add owner inbox UI with address release

Web: "My listings" (listings, requests of a listing, conversation) in
three panes on wide screens and one at a time on phones, and a sheet or
dialog to release the exact address. Sign-in uses a link printed by
`node run` (token in the URL fragment, kept in sessionStorage only).

API: GET /api/v1/mine (own listings with request counts and whether an
address is saved); inbox rows gain last_dir, needs_reply, preview,
effort and grant_until, and can be filtered by listing.

Docs: PROTOCOL.md and README describe the owner UI and login.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 20:02:51 +01:00
co-authored by Claude Sonnet 5.5
parent 3b0351c774
commit 8edae3ae56
17 changed files with 2400 additions and 49 deletions
+17
View File
@@ -0,0 +1,17 @@
package main
import "testing"
func TestLoginURL(t *testing.T) {
for addr, want := range map[string]string{
"127.0.0.1:8080": "http://127.0.0.1:8080/#/login/tok",
"0.0.0.0:8080": "http://127.0.0.1:8080/#/login/tok", // a wildcard cannot be opened
"[::]:9000": "http://127.0.0.1:9000/#/login/tok",
"[::1]:8080": "http://[::1]:8080/#/login/tok",
"192.0.2.7:80": "http://192.0.2.7:80/#/login/tok",
} {
if got := loginURL(addr, "tok"); got != want {
t.Errorf("loginURL(%q) = %q, want %q", addr, got, want)
}
}
}
+21
View File
@@ -136,6 +136,13 @@ func cmdRun(args []string) error {
log.Warn("the HTTP API is reachable from other machines; put it behind TLS if it is public")
}
if token != "" {
// Printed to the terminal, not logged: the token must not end up in a
// log file. It sits in the URL fragment, which a browser never sends to
// a server; the page moves it into sessionStorage and removes it.
fmt.Fprintf(os.Stderr, "\nOwner login (answer your inbox in the browser):\n %s\n\n", loginURL(ln.Addr().String(), token))
}
go announce(ctx, log, node, st, dev.Cert.Author)
<-ctx.Done()
@@ -176,3 +183,17 @@ func announce(ctx context.Context, log *slog.Logger, node *p2p.Node, st *store.S
timer.Reset(announceInterval)
}
}
// loginURL is the link that signs the owner in to the web UI.
func loginURL(listenAddr, token string) string {
host, port, err := net.SplitHostPort(listenAddr)
if err != nil {
return "http://" + listenAddr + "/#/login/" + token
}
// A wildcard address (0.0.0.0, ::) is not something a browser can open.
if ip := net.ParseIP(host); ip == nil || ip.IsUnspecified() {
host = "127.0.0.1"
}
// JoinHostPort brackets IPv6 addresses.
return "http://" + net.JoinHostPort(host, port) + "/#/login/" + token
}