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

Configure Feed

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

PostView_Embed images!!

+113
+111
shims/lex/app/bsky/feed/defs/embed.go
··· 1 1 package appbskyfeeddefs 2 + 3 + import ( 4 + "context" 5 + 6 + appbsky "github.com/bluesky-social/indigo/api/bsky" 7 + "github.com/bluesky-social/indigo/atproto/syntax" 8 + "tangled.org/whey.party/red-dwarf-server/microcosm" 9 + "tangled.org/whey.party/red-dwarf-server/shims/utils" 10 + ) 11 + 12 + func PostView_Embed(ctx context.Context, postaturi string, feedPost *appbsky.FeedPost, sl *microcosm.MicrocosmClient, cs *microcosm.MicrocosmClient, imgcdn string) (*appbsky.FeedDefs_PostView_Embed, error) { 13 + if feedPost.Embed == nil { 14 + return nil, nil 15 + } 16 + 17 + aturi, err := syntax.ParseATURI(postaturi) 18 + if err != nil { 19 + return nil, err 20 + } 21 + 22 + // determine type 23 + if feedPost.Embed.EmbedImages != nil { 24 + //embedType = "EmbedImages" 25 + 26 + // thumb: `https://${cdn}/img/feed_thumbnail/plain/${did}/${link}@jpeg`, 27 + // fullsize: `https://${cdn}/img/feed_fullsize/plain/${did}/${link}@jpeg`, 28 + var images []*appbsky.EmbedImages_ViewImage 29 + for _, rawimg := range feedPost.Embed.EmbedImages.Images { 30 + 31 + var feed_thumbnail string 32 + var feed_fullsize string 33 + if rawimg.Image != nil { 34 + u := utils.MakeImageCDN(utils.DID(aturi.Authority().String()), imgcdn, "feed_thumbnail", rawimg.Image.Ref.String()) 35 + feed_thumbnail = u 36 + uf := utils.MakeImageCDN(utils.DID(aturi.Authority().String()), imgcdn, "feed_fullsize", rawimg.Image.Ref.String()) 37 + feed_fullsize = uf 38 + } 39 + img := appbsky.EmbedImages_ViewImage{ 40 + // // alt: Alt text description of the image, for accessibility. 41 + // Alt string `json:"alt" cborgen:"alt"` 42 + Alt: rawimg.Alt, 43 + // AspectRatio *EmbedDefs_AspectRatio `json:"aspectRatio,omitempty" cborgen:"aspectRatio,omitempty"` 44 + AspectRatio: rawimg.AspectRatio, 45 + // // fullsize: Fully-qualified URL where a large version of the image can be fetched. May or may not be the exact original blob. For example, CDN location provided by the App View. 46 + // Fullsize string `json:"fullsize" cborgen:"fullsize"` 47 + Fullsize: feed_fullsize, 48 + // // thumb: Fully-qualified URL where a thumbnail of the image can be fetched. For example, CDN location provided by the App View. 49 + // Thumb string `json:"thumb" cborgen:"thumb"` 50 + Thumb: feed_thumbnail, 51 + } 52 + images = append(images, &img) 53 + } 54 + return &appbsky.FeedDefs_PostView_Embed{ 55 + // EmbedImages_View *EmbedImages_View 56 + EmbedImages_View: &appbsky.EmbedImages_View{ 57 + LexiconTypeID: "app.bsky.embed.images#view", 58 + Images: images, 59 + }, 60 + // EmbedVideo_View *EmbedVideo_View 61 + // EmbedExternal_View *EmbedExternal_View 62 + // EmbedRecord_View *EmbedRecord_View 63 + // EmbedRecordWithMedia_View *EmbedRecordWithMedia_View 64 + }, nil 65 + } 66 + if feedPost.Embed.EmbedVideo != nil { 67 + return nil, nil 68 + //embedType = "EmbedVideo" 69 + return &appbsky.FeedDefs_PostView_Embed{ 70 + // EmbedImages_View *EmbedImages_View 71 + // EmbedVideo_View *EmbedVideo_View 72 + // EmbedExternal_View *EmbedExternal_View 73 + // EmbedRecord_View *EmbedRecord_View 74 + // EmbedRecordWithMedia_View *EmbedRecordWithMedia_View 75 + }, nil 76 + } 77 + if feedPost.Embed.EmbedExternal != nil { 78 + return nil, nil 79 + //embedType = "EmbedExternal" 80 + return &appbsky.FeedDefs_PostView_Embed{ 81 + // EmbedImages_View *EmbedImages_View 82 + // EmbedVideo_View *EmbedVideo_View 83 + // EmbedExternal_View *EmbedExternal_View 84 + // EmbedRecord_View *EmbedRecord_View 85 + // EmbedRecordWithMedia_View *EmbedRecordWithMedia_View 86 + }, nil 87 + } 88 + if feedPost.Embed.EmbedRecord != nil { 89 + return nil, nil 90 + //embedType = "EmbedRecord" 91 + return &appbsky.FeedDefs_PostView_Embed{ 92 + // EmbedImages_View *EmbedImages_View 93 + // EmbedVideo_View *EmbedVideo_View 94 + // EmbedExternal_View *EmbedExternal_View 95 + // EmbedRecord_View *EmbedRecord_View 96 + // EmbedRecordWithMedia_View *EmbedRecordWithMedia_View 97 + }, nil 98 + } 99 + if feedPost.Embed.EmbedRecordWithMedia != nil { 100 + return nil, nil 101 + //embedType = "EmbedRecordWithMedia" 102 + return &appbsky.FeedDefs_PostView_Embed{ 103 + // EmbedImages_View *EmbedImages_View 104 + // EmbedVideo_View *EmbedVideo_View 105 + // EmbedExternal_View *EmbedExternal_View 106 + // EmbedRecord_View *EmbedRecord_View 107 + // EmbedRecordWithMedia_View *EmbedRecordWithMedia_View 108 + }, nil 109 + } 110 + 111 + return nil, nil 112 + }
+2
shims/lex/app/bsky/feed/defs/postview.go
··· 39 39 if err := json.Unmarshal(*postRecordResponse.Value, &postRecord); err != nil { 40 40 return nil, nil, err 41 41 } 42 + postView_Embed, err := PostView_Embed(ctx, postaturi, &postRecord, sl, cs, imgcdn) 42 43 43 44 profile, _, _ := appbskyactordefs.ProfileViewBasic(ctx, repoDID, sl, imgcdn) 44 45 ··· 120 121 // // debug: Debug information for internal development 121 122 // Debug *interface{} `json:"debug,omitempty" cborgen:"debug,omitempty"` 122 123 // Embed *FeedDefs_PostView_Embed `json:"embed,omitempty" cborgen:"embed,omitempty"` 124 + Embed: postView_Embed, 123 125 // IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` 124 126 IndexedAt: postRecord.CreatedAt, 125 127 // Labels []*comatproto.LabelDefs_Label `json:"labels,omitempty" cborgen:"labels,omitempty"`