tangled
alpha
login
or
join now
whey.party
/
red-dwarf-server
13
fork
atom
collection of golang services under the Red Dwarf umbrella
server.reddwarf.app
bluesky
reddwarf
microcosm
appview
13
fork
atom
overview
issues
pulls
pipelines
getFeedGenerators
whey.party
3 months ago
bf267449
d74fabe0
+135
2 changed files
expand all
collapse all
unified
split
main.go
public
getConfig.json
+95
main.go
···
1
1
package main
2
2
3
3
import (
4
4
+
"bytes"
4
5
"context"
5
6
"encoding/json"
6
7
"flag"
···
8
9
"io"
9
10
"log"
10
11
"net/http"
12
12
+
"os"
13
13
+
"sync"
11
14
"time"
12
15
13
16
did "github.com/whyrusleeping/go-did"
···
22
25
// "github.com/bluesky-social/indigo/atproto/atclient"
23
26
// comatproto "github.com/bluesky-social/indigo/api/atproto"
24
27
appbsky "github.com/bluesky-social/indigo/api/bsky"
28
28
+
"github.com/bluesky-social/indigo/atproto/syntax"
29
29
+
25
30
// "github.com/bluesky-social/indigo/atproto/atclient"
26
31
// "github.com/bluesky-social/indigo/atproto/identity"
27
32
// "github.com/bluesky-social/indigo/atproto/syntax"
···
280
285
Views: labelers,
281
286
})
282
287
})
288
288
+
289
289
+
router.GET("/xrpc/app.bsky.feed.getFeedGenerators",
290
290
+
func(c *gin.Context) {
291
291
+
feeds := c.QueryArray("feeds")
292
292
+
ctx := c.Request.Context()
293
293
+
294
294
+
type result struct {
295
295
+
view *appbsky.FeedDefs_GeneratorView
296
296
+
}
297
297
+
298
298
+
results := make([]result, len(feeds))
299
299
+
300
300
+
var wg sync.WaitGroup
301
301
+
wg.Add(len(feeds))
302
302
+
303
303
+
for i, raw := range feeds {
304
304
+
go func(i int, raw string) {
305
305
+
defer wg.Done()
306
306
+
307
307
+
aturi, err := syntax.ParseATURI(raw)
308
308
+
if err != nil {
309
309
+
return
310
310
+
}
311
311
+
312
312
+
did := aturi.Authority().String()
313
313
+
collection := aturi.Collection().String()
314
314
+
rkey := aturi.RecordKey().String()
315
315
+
316
316
+
repoDID, err := utils.NewDID(did)
317
317
+
if err != nil {
318
318
+
return
319
319
+
}
320
320
+
321
321
+
// fetch profile and record in parallel too (optional)
322
322
+
// but to keep it simple, do serial inside this goroutine
323
323
+
profile, _, _ := appbskyactordefs.ProfileView(ctx, repoDID, sl, BSKYIMAGECDN_URL)
324
324
+
325
325
+
rec, err := agnostic.RepoGetRecord(ctx, sl, "", collection, did, rkey)
326
326
+
if err != nil || rec.Value == nil {
327
327
+
return
328
328
+
}
329
329
+
330
330
+
var genRec appbsky.FeedGenerator
331
331
+
if err := json.Unmarshal(*rec.Value, &genRec); err != nil {
332
332
+
return
333
333
+
}
334
334
+
335
335
+
var avatar *string
336
336
+
if genRec.Avatar != nil {
337
337
+
u := utils.MakeImageCDN(repoDID, BSKYIMAGECDN_URL, "avatar", genRec.Avatar.Ref.String())
338
338
+
avatar = &u
339
339
+
}
340
340
+
341
341
+
results[i].view = &appbsky.FeedDefs_GeneratorView{
342
342
+
LexiconTypeID: "app.bsky.feed.defs#generatorView",
343
343
+
AcceptsInteractions: genRec.AcceptsInteractions,
344
344
+
Avatar: avatar,
345
345
+
Cid: *rec.Cid,
346
346
+
ContentMode: genRec.ContentMode,
347
347
+
Creator: profile,
348
348
+
Description: genRec.Description,
349
349
+
DescriptionFacets: genRec.DescriptionFacets,
350
350
+
Did: did,
351
351
+
DisplayName: genRec.DisplayName,
352
352
+
IndexedAt: genRec.CreatedAt,
353
353
+
Uri: rec.Uri,
354
354
+
}
355
355
+
}(i, raw)
356
356
+
}
357
357
+
358
358
+
wg.Wait()
359
359
+
360
360
+
// build final slice
361
361
+
out := make([]*appbsky.FeedDefs_GeneratorView, 0, len(results))
362
362
+
for _, r := range results {
363
363
+
if r.view != nil {
364
364
+
out = append(out, r.view)
365
365
+
}
366
366
+
}
367
367
+
368
368
+
c.JSON(http.StatusOK, &appbsky.FeedGetFeedGenerators_Output{
369
369
+
Feeds: out,
370
370
+
})
371
371
+
})
372
372
+
373
373
+
yourJSONBytes, _ := os.ReadFile("./public/getConfig.json")
374
374
+
router.GET("/xrpc/app.bsky.unspecced.getConfig", func(c *gin.Context) {
375
375
+
c.DataFromReader(200, -1, "application/json",
376
376
+
bytes.NewReader(yourJSONBytes), nil)
377
377
+
})
283
378
284
379
router.GET("/", func(c *gin.Context) {
285
380
log.Println("hello worldio !")
+40
public/getConfig.json
···
1
1
+
{
2
2
+
"checkEmailConfirmed": true,
3
3
+
"topicsEnabled": true,
4
4
+
"liveNow": [
5
5
+
{
6
6
+
"did": "did:plc:7sfnardo5xxznxc6esxc5ooe",
7
7
+
"domains": [
8
8
+
"www.nba.com",
9
9
+
"nba.com",
10
10
+
"nba.smart.link",
11
11
+
"espn.com",
12
12
+
"www.espn.com"
13
13
+
]
14
14
+
},
15
15
+
{ "did": "did:plc:gx6fyi3jcfxd7ammq2t7mzp2", "domains": ["twitch.tv"] },
16
16
+
{ "did": "did:plc:mc2hhszsfk6iwapfdwrwoj7i", "domains": ["twitch.tv"] },
17
17
+
{ "did": "did:plc:sb54dpdfefflykmf5bcfvr7t", "domains": ["youtube.com"] },
18
18
+
{ "did": "did:plc:dqav4a4ue5cyzgckv3l6fshr", "domains": ["twitch.tv"] },
19
19
+
{ "did": "did:plc:q6f4hsgifb3qs2e3wwdycjtf", "domains": ["twitch.tv"] },
20
20
+
{ "did": "did:plc:7tpvfx7mdbceyzj6kgboirle", "domains": ["twitch.tv"] },
21
21
+
{
22
22
+
"did": "did:plc:4adlzwqtkv4dirxjwq4c3tlm",
23
23
+
"domains": ["stream.place", "skylight.social"]
24
24
+
},
25
25
+
{
26
26
+
"did": "did:plc:2zmxikig2sj7gqaezl5gntae",
27
27
+
"domains": ["stream.place", "skylight.social"]
28
28
+
},
29
29
+
{
30
30
+
"did": "did:plc:jsbkvuuviqj4xooqwcbaftav",
31
31
+
"domains": ["stream.place", "skylight.social"]
32
32
+
},
33
33
+
{
34
34
+
"did": "did:plc:76iqtegcbbr4pbcxomka5pat",
35
35
+
"domains": ["stream.place", "skylight.social"]
36
36
+
},
37
37
+
{ "did": "did:plc:r2mpjf3gz2ygfaodkzzzfddg", "domains": ["youtube.com"] },
38
38
+
{ "did": "did:plc:wvwvlbeizca367klhhyudf2n", "domains": ["youtube.com"] }
39
39
+
]
40
40
+
}