Compare commits

2 Commits
Author SHA1 Message Date
Gabriel20xx 170a25188b Resolve imported thumbnail mappings 2026-09-18 15:58:57 +02:00
Gabriel20xx 389dd8649d Extend core config for ContentScanner sync 2026-09-18 15:54:39 +02:00
3 changed files with 39 additions and 4 deletions

No files matched your search

+19 -2
View File
@@ -28,6 +28,10 @@ type Info struct {
// configuration. Consumers with independent databases can use it to read settings such as the
// configured mount mappings.
ProjectConfiguratorURL string `json:"projectConfiguratorUrl"`
// ContentScannerURL and ContentScannerSecret let services with independent databases import
// the scanner's successfully discovered media without connecting to its PostgreSQL database.
ContentScannerURL string `json:"contentScannerUrl,omitempty"`
ContentScannerSecret string `json:"contentScannerSecret,omitempty"`
// CarrierNodeURL is the primary CarrierNode instance's URL (CarrierNodeURLs[0], if any) - kept
// for the services that only ever talk to one CarrierNode instance via
@@ -78,6 +82,12 @@ func (s *Store) ComfyUIURL() string { return s.Get().ComfyUIURL }
// ProjectConfiguratorURL is a convenience accessor for Get().ProjectConfiguratorURL.
func (s *Store) ProjectConfiguratorURL() string { return s.Get().ProjectConfiguratorURL }
// ContentScannerURL is a convenience accessor for Get().ContentScannerURL.
func (s *Store) ContentScannerURL() string { return s.Get().ContentScannerURL }
// ContentScannerSecret is the credential the scanner expects on internal sync requests.
func (s *Store) ContentScannerSecret() string { return s.Get().ContentScannerSecret }
// CarrierNodeURL is a convenience accessor for Get().CarrierNodeURL - the natural closure to wire
// as a single-instance carriernodeclient.Client's BaseURL: carriernodeclient.New(secret, func(ctx
// context.Context) string { return store.CarrierNodeURL() }).
@@ -116,6 +126,12 @@ func (s *Store) Set(next Info) {
if url := strings.TrimRight(strings.TrimSpace(next.ProjectConfiguratorURL), "/"); url != "" {
s.info.ProjectConfiguratorURL = url
}
if url := strings.TrimRight(strings.TrimSpace(next.ContentScannerURL), "/"); url != "" {
s.info.ContentScannerURL = url
}
if secret := strings.TrimSpace(next.ContentScannerSecret); secret != "" {
s.info.ContentScannerSecret = secret
}
if secret := strings.TrimSpace(next.CarrierNodeSecret); secret != "" {
s.info.CarrierNodeSecret = secret
}
@@ -173,10 +189,11 @@ func Handler(secret string, store *Store) http.HandlerFunc {
return
}
store.Set(input)
// Do not echo the CarrierNode credential to the caller. The push is
// authenticated, but the credential is needed only by the recipient.
// Do not echo service credentials to the caller. The push is authenticated, but
// these credentials are needed only by the recipient.
info := store.Get()
info.CarrierNodeSecret = ""
info.ContentScannerSecret = ""
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "info": info})
}
}
+9 -2
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
@@ -127,7 +128,10 @@ func equalStrings(got, want []string) bool {
func TestHandlerAppliesPushedInfo(t *testing.T) {
store := NewStore(Info{})
handler := Handler("s3cret", store)
body, _ := json.Marshal(Info{AuthGuardURL: "http://auth.example.com", CarrierNodeURL: "http://carrier.example.com", CarrierNodeSecret: "carrier-secret"})
body, _ := json.Marshal(Info{
AuthGuardURL: "http://auth.example.com", CarrierNodeURL: "http://carrier.example.com", CarrierNodeSecret: "carrier-secret",
ContentScannerURL: "http://scanner.example.com/", ContentScannerSecret: "scanner-secret",
})
req := httptest.NewRequest(http.MethodPut, "/api/core-services/internal", bytes.NewReader(body))
req.Header.Set("X-Internal-Auth", "s3cret")
@@ -138,7 +142,10 @@ func TestHandlerAppliesPushedInfo(t *testing.T) {
t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String())
}
got := store.Get()
if got.AuthGuardURL != "http://auth.example.com" || got.CarrierNodeURL != "http://carrier.example.com" || got.CarrierNodeSecret != "carrier-secret" {
if got.AuthGuardURL != "http://auth.example.com" || got.CarrierNodeURL != "http://carrier.example.com" || got.CarrierNodeSecret != "carrier-secret" || got.ContentScannerURL != "http://scanner.example.com" || got.ContentScannerSecret != "scanner-secret" {
t.Fatalf("store = %+v, want pushed values applied", got)
}
if strings.Contains(rec.Body.String(), "scanner-secret") {
t.Fatal("response echoed the ContentScanner secret")
}
}
+11
View File
@@ -200,6 +200,17 @@ func (c *Core) thumbnailMediaIdentifier(w http.ResponseWriter, r *http.Request,
return
}
}
var thumbnailID string
if err := c.db.QueryRow(r.Context(), `
SELECT t.id::text
FROM thumbnails t
JOIN media m ON m.id = t.media_id OR t.source_path = COALESCE(NULLIF(m.file_path, ''), m.media_key)
WHERE m.media_key=$1 OR CAST(m.id AS TEXT)=$1
ORDER BY t.created_at DESC
LIMIT 1`, id).Scan(&thumbnailID); err == nil && SafeRelative(thumbnailID) {
c.carrierNode.Proxy(w, r, "/thumbnails/"+thumbnailID+".jpg")
return
}
record, err := c.findMedia(r.Context(), id)
if err != nil || !isImagePath(record.FilePath) {
writeError(w, http.StatusNotFound, "thumbnail not found")