collection of golang services under the Red Dwarf umbrella server.reddwarf.app
bluesky reddwarf microcosm appview
16
fork

Configure Feed

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

basic prefs ??

+56
+29
main.go
··· 5 5 "encoding/json" 6 6 "flag" 7 7 "fmt" 8 + "io" 8 9 "log" 9 10 "net/http" 10 11 "time" ··· 16 17 appbskyactordefs "tangled.org/whey.party/red-dwarf-server/shims/lex/app/bsky/actor/defs" 17 18 "tangled.org/whey.party/red-dwarf-server/shims/utils" 18 19 "tangled.org/whey.party/red-dwarf-server/sticket" 20 + "tangled.org/whey.party/red-dwarf-server/store" 19 21 20 22 // "github.com/bluesky-social/indigo/atproto/atclient" 21 23 // comatproto "github.com/bluesky-social/indigo/api/atproto" ··· 107 109 108 110 router.GET("/ws", func(c *gin.Context) { 109 111 mailbox.HandleWS(c.Writer, c.Request) 112 + }) 113 + 114 + kv := store.NewKV() 115 + 116 + router.PUT("/xrpc/app.bsky.actor.putPreferences", func(c *gin.Context) { 117 + userDID := c.GetString("user_did") 118 + body, err := io.ReadAll(c.Request.Body) 119 + if err != nil { 120 + c.JSON(400, gin.H{"error": "invalid body"}) 121 + return 122 + } 123 + 124 + kv.Set(userDID, body) 125 + c.Status(200) 126 + 127 + }) 128 + 129 + router.GET("/xrpc/app.bsky.actor.getPreferences", func(c *gin.Context) { 130 + userDID := c.GetString("user_did") 131 + val, ok := kv.Get(userDID) 132 + if !ok { 133 + c.JSON(200, gin.H{"preferences": []any{}}) 134 + return 135 + } 136 + 137 + c.Data(200, "application/json", val) 138 + 110 139 }) 111 140 112 141 bskyappdid, _ := utils.NewDID("did:plc:z72i7hdynmk6r22z27h6tvur")
+27
store/kv.go
··· 1 + package store 2 + 3 + import "sync" 4 + 5 + type KV struct { 6 + mu sync.RWMutex 7 + m map[string][]byte 8 + } 9 + 10 + func NewKV() *KV { 11 + return &KV{ 12 + m: make(map[string][]byte), 13 + } 14 + } 15 + 16 + func (kv *KV) Get(key string) ([]byte, bool) { 17 + kv.mu.RLock() 18 + defer kv.mu.RUnlock() 19 + v, ok := kv.m[key] 20 + return v, ok 21 + } 22 + 23 + func (kv *KV) Set(key string, val []byte) { 24 + kv.mu.Lock() 25 + defer kv.mu.Unlock() 26 + kv.m[key] = val 27 + }