begin embedded pds with xrpc endpoints and well-known

This commit is contained in:
Evan Jarrett
2025-10-14 20:25:08 -05:00
parent 2ee8bd8786
commit 18fe0684d3
17 changed files with 1252 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"context"
"encoding/json"
"fmt"
"log"
@@ -11,6 +12,7 @@ import (
"atcr.io/pkg/atproto"
"atcr.io/pkg/hold"
"atcr.io/pkg/hold/pds"
indigooauth "github.com/bluesky-social/indigo/atproto/auth/oauth"
// Import storage drivers
@@ -31,6 +33,30 @@ func main() {
log.Fatalf("Failed to create hold service: %v", err)
}
// Initialize embedded PDS if database path is configured
var holdPDS *pds.HoldPDS
var xrpcHandler *pds.XRPCHandler
if cfg.Database.Path != "" {
// Generate did:web from public URL
holdDID := pds.GenerateDIDFromURL(cfg.Server.PublicURL)
log.Printf("Initializing embedded PDS with DID: %s", holdDID)
// Initialize PDS with carstore and keys
ctx := context.Background()
holdPDS, err = pds.NewHoldPDS(ctx, holdDID, cfg.Server.PublicURL, cfg.Database.Path, cfg.Database.KeyPath)
if err != nil {
log.Fatalf("Failed to initialize embedded PDS: %v", err)
}
// Create blob store adapter
blobStore := pds.NewHoldServiceBlobStore(service, holdDID)
// Create XRPC handler
xrpcHandler = pds.NewXRPCHandler(holdPDS, cfg.Server.PublicURL, blobStore)
log.Printf("Embedded PDS initialized successfully")
}
// Setup HTTP routes
mux := http.NewServeMux()
mux.HandleFunc("/health", service.HealthHandler)
@@ -118,6 +144,12 @@ func main() {
}
})
// Register XRPC/ATProto PDS endpoints if PDS is initialized
if xrpcHandler != nil {
log.Printf("Registering ATProto PDS endpoints")
xrpcHandler.RegisterHandlers(mux)
}
// Create server
server := &http.Server{
Addr: cfg.Server.Addr,