Monorepo for Tangled tangled.org
5

Configure Feed

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

1package compat113 2 3import ( 4 "context" 5 "fmt" 6 "net/http" 7 "strconv" 8 "strings" 9 "time" 10 11 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 12 "tangled.org/core/api/tangled" 13) 14 15const versionProbeTimeout = 5 * time.Second 16 17func KnotSupports114(ctx context.Context, host string, dev bool) bool { 18 scheme := "https" 19 if dev { 20 scheme = "http" 21 } 22 client := &indigoxrpc.Client{ 23 Host: fmt.Sprintf("%s://%s", scheme, host), 24 Client: &http.Client{Timeout: versionProbeTimeout}, 25 } 26 27 ctx, cancel := context.WithTimeout(ctx, versionProbeTimeout) 28 defer cancel() 29 30 resp, err := tangled.KnotVersion(ctx, client) 31 if err != nil || resp == nil { 32 return true 33 } 34 return atLeast114(resp.Version) 35} 36 37func atLeast114(v string) bool { 38 v = strings.TrimSpace(v) 39 v = strings.TrimPrefix(v, "v") 40 if strings.HasPrefix(v, "(devel)") { 41 return true 42 } 43 if v == "" { 44 return false 45 } 46 parts := strings.SplitN(v, ".", 3) 47 if len(parts) < 2 { 48 return false 49 } 50 major, err := strconv.Atoi(parts[0]) 51 if err != nil { 52 return false 53 } 54 minorRaw := strings.SplitN(parts[1], "-", 2)[0] 55 minor, err := strconv.Atoi(minorRaw) 56 if err != nil { 57 return false 58 } 59 return major > 1 || (major == 1 && minor >= 14) 60}