Sign in and out of the hub from the client: the proxy answers t5de-proxy.local
CI / build (push) Successful in 28s
CI / build (push) Successful in 28s
A manager runs the hub connection, so signing in or out takes effect while the client runs; the client's T5DE settings page asks it for the status and to sign in (showing the code and opening the hub's page) or out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
5b4e44c4e7
commit
5eca0b57a6
4 files changed
+368
-23
No files matched your search
+28
-22
@@ -17,7 +17,6 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -33,6 +32,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.t5de.dev/t5de/t5de-proxy/internal/buildinfo"
|
||||
"git.t5de.dev/t5de/t5de-proxy/internal/control"
|
||||
"git.t5de.dev/t5de/t5de-proxy/internal/fetch"
|
||||
"git.t5de.dev/t5de/t5de-proxy/internal/hub"
|
||||
"git.t5de.dev/t5de/t5de-proxy/internal/parent"
|
||||
@@ -138,30 +138,36 @@ func run(logger *log.Logger, listen, ready string, parentPID int, trace bool, pa
|
||||
handler.Interceptor, handler.IMQFilter = prods, prods
|
||||
logger.Printf("community products from %s", strings.Join(packs, ", "))
|
||||
}
|
||||
if saved, err := hub.Load(filepath.Join(data, "hub.json")); err == nil {
|
||||
client := hub.New(filepath.Join(data, "hub.json"), saved, logger)
|
||||
// The hub connection, which the client's T5DE settings can sign in and out (internal/control).
|
||||
manager := &control.Manager{Path: filepath.Join(data, "hub.json"), DefaultHub: envOr("T5DE_HUB", defaultHub),
|
||||
Log: logger, OpenBrowser: openBrowser}
|
||||
manager.Attach = func(client *hub.Client) {
|
||||
fetcher := fetch.New(client, hubProducts, logger.Printf)
|
||||
if prods != nil {
|
||||
prods.Observer = client
|
||||
client.OnChat = prods.Others
|
||||
fetcher.OnReady = prods.Ready
|
||||
fetcher.OnLibrary = prods.RefreshInventory
|
||||
prods.Want = fetcher.Want
|
||||
prods.HubDir, prods.Owned = hubProducts, fetcher.Owned
|
||||
prods.OnHide = func(id string) {
|
||||
if fetch.IsHubID(id) {
|
||||
go func() {
|
||||
if err := client.Call(context.Background(), "DELETE", "/api/v1/library/"+id, nil, nil); err != nil {
|
||||
logger.Printf("hub: removing %s from the library: %v", id, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
client.OnLibrary = func() { fetcher.SyncLibrary(context.Background()) }
|
||||
if prods == nil {
|
||||
return
|
||||
}
|
||||
prods.Observer = client
|
||||
client.OnChat = prods.Others
|
||||
fetcher.OnReady = prods.Ready
|
||||
fetcher.OnLibrary = prods.RefreshInventory
|
||||
prods.Want = fetcher.Want
|
||||
prods.HubDir, prods.Owned = hubProducts, fetcher.Owned
|
||||
prods.OnHide = func(id string) {
|
||||
if fetch.IsHubID(id) {
|
||||
go func() {
|
||||
if err := client.Call(context.Background(), "DELETE", "/api/v1/library/"+id, nil, nil); err != nil {
|
||||
logger.Printf("hub: removing %s from the library: %v", id, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
client.OnLibrary = func() { fetcher.SyncLibrary(context.Background()) }
|
||||
go client.Run(context.Background())
|
||||
} else if !errors.Is(err, hub.ErrSignedOut) {
|
||||
logger.Printf("hub: %v", err)
|
||||
}
|
||||
manager.Start()
|
||||
if prods != nil {
|
||||
handler.Interceptor = proxy.Interceptors{manager, prods}
|
||||
} else {
|
||||
handler.Interceptor = manager
|
||||
}
|
||||
server := &http.Server{
|
||||
Handler: handler,
|
||||
|
||||
Reference in new issue
Block a user