diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/api/server.go | 19 | ||||
| -rw-r--r-- | internal/ingest/client.go | 1 | ||||
| -rw-r--r-- | internal/ingest/service.go | 15 |
3 files changed, 32 insertions, 3 deletions
diff --git a/internal/api/server.go b/internal/api/server.go index e9e1e15..822d865 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -469,6 +469,7 @@ func (s *Server) handleGetDIDCompatibility(w http.ResponseWriter, r *http.Reques } data, err := s.ingestor.LoadCurrentPLCData(r.Context(), did) + if err != nil { if errors.Is(err, ingest.ErrDIDNotFound) { writeCompatibilityErr(w, http.StatusNotFound, "DID not registered: "+did) @@ -488,8 +489,8 @@ func (s *Server) handleGetDIDCompatibility(w http.ResponseWriter, r *http.Reques } status := http.StatusOK - deactivated := isTombstonedDIDDocument(state.DIDDocument) + if deactivated { status = http.StatusGone } @@ -738,10 +739,11 @@ func buildPLCDIDDocument(did string, plcData map[string]any, deactivated bool) p AlsoKnownAs: extractStringArray(plcData["alsoKnownAs"]), Deactivated: deactivated, } - verificationMethods := extractVerificationMethodMap(plcData["verificationMethods"]) + if len(verificationMethods) > 0 { names := make([]string, 0, len(verificationMethods)) + for name := range verificationMethods { names = append(names, name) } @@ -749,8 +751,10 @@ func buildPLCDIDDocument(did string, plcData map[string]any, deactivated bool) p sort.Strings(names) doc.VerificationMethod = make([]plcVerificationEntry, 0, len(names)) + for _, name := range names { value := verificationMethods[name] + if strings.TrimSpace(value) == "" { continue } @@ -765,8 +769,10 @@ func buildPLCDIDDocument(did string, plcData map[string]any, deactivated bool) p } services := extractServicesMap(plcData["services"]) + if len(services) > 0 { names := make([]string, 0, len(services)) + for name := range services { names = append(names, name) } @@ -774,6 +780,7 @@ func buildPLCDIDDocument(did string, plcData map[string]any, deactivated bool) p sort.Strings(names) doc.Service = make([]plcServiceEntry, 0, len(names)) + for _, name := range names { entry := services[name] typ := entry["type"] @@ -798,8 +805,10 @@ func extractStringArray(v any) []string { switch raw := v.(type) { case []string: out := make([]string, 0, len(raw)) + for _, item := range raw { item = strings.TrimSpace(item) + if item == "" { continue } @@ -810,8 +819,10 @@ func extractStringArray(v any) []string { return out case []any: out := make([]string, 0, len(raw)) + for _, item := range raw { s, _ := item.(string) + if strings.TrimSpace(s) == "" { continue } @@ -840,6 +851,7 @@ func extractVerificationMethodMap(v any) map[string]string { case map[string]any: for name, raw := range vm { key, _ := raw.(string) + if strings.TrimSpace(key) == "" { continue } @@ -858,6 +870,7 @@ func extractServicesMap(v any) map[string]map[string]string { case map[string]map[string]string: for name, entry := range services { endpoint := strings.TrimSpace(entry["endpoint"]) + if endpoint == "" { endpoint = strings.TrimSpace(entry["serviceEndpoint"]) } @@ -874,12 +887,14 @@ func extractServicesMap(v any) map[string]map[string]string { case map[string]any: for name, raw := range services { entry, ok := raw.(map[string]any) + if !ok { continue } typ, _ := entry["type"].(string) endpoint, _ := entry["endpoint"].(string) + if endpoint == "" { endpoint, _ = entry["serviceEndpoint"].(string) } diff --git a/internal/ingest/client.go b/internal/ingest/client.go index 29457cf..ad145c3 100644 --- a/internal/ingest/client.go +++ b/internal/ingest/client.go @@ -370,7 +370,6 @@ func isSpace(b byte) bool { func (c *Client) fetchFromFile(after uint64, limit uint64) ([]types.ExportRecord, error) { path := strings.TrimPrefix(c.source, "file://") - path = filepath.Clean(path) b, err := os.ReadFile(path) diff --git a/internal/ingest/service.go b/internal/ingest/service.go index 6cb7512..a6f7cd7 100644 --- a/internal/ingest/service.go +++ b/internal/ingest/service.go @@ -1057,16 +1057,19 @@ func normalizePLCDataFromOperation(did string, op map[string]any, fallbackRotati } services := normalizeServices(op) + if len(services) > 0 { data["services"] = services } verificationMethods := normalizeVerificationMethods(op) + if len(verificationMethods) > 0 { data["verificationMethods"] = verificationMethods } rotationKeys := extractStringSlice(op["rotationKeys"]) + if len(rotationKeys) == 0 { if recovery, _ := op["recoveryKey"].(string); strings.TrimSpace(recovery) != "" { rotationKeys = append(rotationKeys, recovery) @@ -1100,11 +1103,13 @@ func normalizePLCDataFromDIDDocument(did string, doc map[string]any, fallbackRot for _, rawVM := range rawVMList { vm, ok := rawVM.(map[string]any) + if !ok { continue } name := "atproto" + if id, _ := vm["id"].(string); id != "" { if idx := strings.LastIndex(id, "#"); idx >= 0 && idx < len(id)-1 { name = id[idx+1:] @@ -1126,13 +1131,16 @@ func normalizePLCDataFromDIDDocument(did string, doc map[string]any, fallbackRot for _, rawService := range rawServiceList { service, ok := rawService.(map[string]any) + if !ok { continue } name := "atproto_pds" + if id, _ := service["id"].(string); id != "" { name = strings.TrimPrefix(id, "#") + if strings.TrimSpace(name) == "" { name = "atproto_pds" } @@ -1140,6 +1148,7 @@ func normalizePLCDataFromDIDDocument(did string, doc map[string]any, fallbackRot typ, _ := service["type"].(string) endpoint, _ := service["serviceEndpoint"].(string) + if endpoint == "" { endpoint, _ = service["endpoint"].(string) } @@ -1168,12 +1177,14 @@ func normalizeServices(op map[string]any) map[string]map[string]string { if rawServices, ok := op["services"].(map[string]any); ok { for name, rawEntry := range rawServices { entry, ok := rawEntry.(map[string]any) + if !ok { continue } typ, _ := entry["type"].(string) endpoint, _ := entry["endpoint"].(string) + if endpoint == "" { endpoint, _ = entry["serviceEndpoint"].(string) } @@ -1207,6 +1218,7 @@ func normalizeVerificationMethods(op map[string]any) map[string]string { if rawVM, ok := op["verificationMethods"].(map[string]any); ok { for name, rawValue := range rawVM { value, _ := rawValue.(string) + if strings.TrimSpace(value) == "" { continue } @@ -1228,6 +1240,7 @@ func normalizeVerificationMethods(op map[string]any) map[string]string { func extractStringSlice(v any) []string { raw, ok := v.([]any) + if !ok { return nil } @@ -1236,6 +1249,7 @@ func extractStringSlice(v any) []string { for _, item := range raw { s, _ := item.(string) + if strings.TrimSpace(s) == "" { continue } @@ -1256,6 +1270,7 @@ func dedupeStrings(input []string) []string { for _, item := range input { item = strings.TrimSpace(item) + if item == "" { continue } |