Monorepo for Tangled tangled.org
2

Configure Feed

Select the types of activity you want to include in your feed.

appview/sites: lenient unmarshal for legacy bool-valued kv entries

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>

author
Anirudh Oppiliappan
date (May 16, 2026, 2:48 PM +0300) commit e2d75264 parent 320bb655 change-id wykxqnvl
+30
+30
appview/sites/sites.go
··· 35 35 IsIndex bool `json:"is_index"` 36 36 } 37 37 38 + // UnmarshalJSON makes DomainMapping tolerant of the legacy KV shape where 39 + // repos was map[string]bool (keyed by rkey, value = is_index). For each 40 + // entry it tries the new {rkey, is_index} struct first; if that fails it 41 + // falls back to a bare bool, using the map key itself as the rkey. 42 + func (m *DomainMapping) UnmarshalJSON(data []byte) error { 43 + var raw struct { 44 + Did string `json:"did"` 45 + Repos map[string]json.RawMessage `json:"repos"` 46 + } 47 + if err := json.Unmarshal(data, &raw); err != nil { 48 + return err 49 + } 50 + m.Did = raw.Did 51 + m.Repos = make(map[string]RepoEntry, len(raw.Repos)) 52 + for name, val := range raw.Repos { 53 + var entry RepoEntry 54 + if err := json.Unmarshal(val, &entry); err == nil { 55 + m.Repos[name] = entry 56 + continue 57 + } 58 + // legacy shape: value is a bare bool; map key is the rkey 59 + var isIndex bool 60 + if err := json.Unmarshal(val, &isIndex); err != nil { 61 + return fmt.Errorf("unsupported repo entry for %q: %w", name, err) 62 + } 63 + m.Repos[name] = RepoEntry{Rkey: name, IsIndex: isIndex} 64 + } 65 + return nil 66 + } 67 + 38 68 // getOrNewMapping fetches the existing KV entry for domain, or returns a 39 69 // fresh empty mapping for the given did if none exists yet. 40 70 func getOrNewMapping(ctx context.Context, cf *cloudflare.Client, domain, did string) (DomainMapping, error) {