Skip to content

Commit d6f8c21

Browse files
authored
Merge pull request #56 from Preloading/stories
feat: (hardcoded) stories
2 parents 0ca22aa + 34ecf30 commit d6f8c21

3 files changed

Lines changed: 160 additions & 0 deletions

File tree

bridge/bridge.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,91 @@ type FacetParsing struct {
354354
Item string
355355
}
356356

357+
type Discovery struct {
358+
Statuses []Tweet `json:"statuses" xml:"statuses"`
359+
Stories []Story `json:"stories" xml:"stories"`
360+
RelatedQueries []RelatedQuery `json:"related_queries" xml:"related_queries"`
361+
SpellingCorrections []SpellingCorrection `json:"spelling_corrections" xml:"spelling_corrections"`
362+
}
363+
364+
type Story struct {
365+
Type string `json:"type" xml:"type"` // news or topic
366+
Score float32 `json:"score" xml:"score"`
367+
Data StoryData `json:"data" xml:"data"`
368+
SocialProof SocialProof `json:"social_proof" xml:"social_proof"`
369+
}
370+
371+
type StoryData struct {
372+
Title string `json:"title" xml:"title"`
373+
Articles []NewsArticle `json:"articles" xml:"articles"`
374+
}
375+
376+
// cringe that i need these multiple
377+
378+
type StoryURL struct {
379+
DisplayURL string `json:"display_url" xml:"display_url"`
380+
ExpandedURL string `json:"expanded_url" xml:"expanded_url"`
381+
}
382+
383+
type StoryMediaInfo struct {
384+
MediaURL string `json:"media_url" xml:"media_url"`
385+
Type string `json:"type" xml:"type"`
386+
Width int `json:"width" xml:"width"`
387+
Height int `json:"height" xml:"height"`
388+
VideoInfo *StoryVideoInfo `json:"video_info,omitempty" xml:"video_info,omitempty"`
389+
}
390+
391+
// speculating, is this for proper video support?
392+
type StoryVideoInfo struct {
393+
Variants []StoryVideoVariant `json:"variants" xml:"variants"`
394+
}
395+
396+
type StoryVideoVariant struct {
397+
URL string `json:"url" xml:"url"`
398+
ContentType string `json:"content_type" xml:"content_type"`
399+
}
400+
401+
type NewsArticle struct {
402+
Title string `json:"title" xml:"title"`
403+
Url StoryURL `json:"url" xml:"url"`
404+
Description string `json:"description" xml:"description"`
405+
TweetCount int `json:"tweet_count" xml:"tweet_count"`
406+
Attribution string `json:"attribution" xml:"attribution"`
407+
Score float32 `json:"score" xml:"score"`
408+
Query string `json:"query" xml:"query"`
409+
Name string `json:"name" xml:"name"` // no clue what the difference is between name and title. i guess the article's author
410+
Media []StoryMediaInfo `json:"media" xml:"media"`
411+
}
412+
413+
type SocialProof struct {
414+
Type string `json:"social_proof_type" xml:"social_proof_type"` // social or query
415+
ReferencedBy SocialProofedReferencedBy `json:"referenced_by" xml:"referenced_by"`
416+
}
417+
418+
type SocialProofedReferencedBy struct {
419+
Statuses []Tweet `json:"statuses" xml:"statuses"`
420+
GlobalCount int `json:"global_count" xml:"global_count"`
421+
}
422+
423+
type RelatedQuery struct {
424+
Query string `json:"query" xml:"query"`
425+
}
426+
type QueryWithIndices struct {
427+
Query string `json:"query" xml:"query"`
428+
Indices []int `json:"indices" xml:"-"`
429+
Start int `json:"-" xml:"start,attr"`
430+
End int `json:"-" xml:"end,attr"`
431+
}
432+
433+
//arrays upon arrays
434+
435+
type SpellingCorrection struct {
436+
Results []SpellingCorrectionResults `json:"results" xml:"results"`
437+
}
438+
439+
type SpellingCorrectionResults struct {
440+
Value QueryWithIndices `json:"value" xml:"value"`
441+
357442
type AuthToken struct {
358443
*jwt.RegisteredClaims
359444
Version int `json:"version"` // Version of the token

twitterv1/discover.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,80 @@ func trends_woeid(c *fiber.Ctx) error {
174174
})
175175
}
176176

177+
func discovery(c *fiber.Ctx) error {
178+
// auth
179+
_, pds, _, oauthToken, err := GetAuthFromReq(c)
180+
181+
if err != nil {
182+
blankstring := ""
183+
oauthToken = &blankstring
184+
}
185+
186+
err, thread := blueskyapi.GetPost(*pds, *oauthToken, "at://did:plc:khcyntihpu7snjszuojjgjc4/app.bsky.feed.post/3lfgrcq4di22c", 0, 1)
187+
188+
if err != nil {
189+
return err
190+
}
191+
192+
var displayTweet bridge.Tweet
193+
194+
// TODO: Some things may be needed for reposts to show up correctly. thats a later problem :)
195+
if thread.Thread.Parent == nil {
196+
displayTweet = TranslatePostToTweet(thread.Thread.Post, "", "", nil, nil, *oauthToken, *pds)
197+
} else {
198+
displayTweet = TranslatePostToTweet(thread.Thread.Post, thread.Thread.Parent.Post.URI, thread.Thread.Parent.Post.Author.DID, &thread.Thread.Parent.Post.Record.CreatedAt, nil, *oauthToken, *pds)
199+
}
200+
201+
return EncodeAndSend(c, bridge.Discovery{
202+
Statuses: []bridge.Tweet{
203+
displayTweet,
204+
},
205+
Stories: []bridge.Story{
206+
{
207+
Type: "news",
208+
Score: 0.92,
209+
Data: bridge.StoryData{
210+
Title: "Thank you for using A Twitter Bridge!",
211+
Articles: []bridge.NewsArticle{
212+
{
213+
Title: "Thank you for using A Twitter Bridge!",
214+
Url: bridge.StoryURL{
215+
DisplayURL: "twitterbridge.loganserver.net",
216+
ExpandedURL: "https://twitterbridge.loganserver.net",
217+
},
218+
TweetCount: 1500,
219+
Media: []bridge.StoryMediaInfo{
220+
{
221+
Type: "image", // ?
222+
MediaURL: "https://raw.githubusercontent.com/Preloading/TwitterAPIBridge/refs/heads/main/resources/1.png",
223+
Width: 1920,
224+
Height: 1080,
225+
},
226+
},
227+
},
228+
},
229+
},
230+
SocialProof: bridge.SocialProof{
231+
Type: "social",
232+
ReferencedBy: bridge.SocialProofedReferencedBy{
233+
GlobalCount: 2500,
234+
Statuses: []bridge.Tweet{displayTweet},
235+
},
236+
},
237+
},
238+
},
239+
240+
RelatedQueries: []bridge.RelatedQuery{
241+
{
242+
Query: "Bluetweety",
243+
},
244+
{
245+
Query: "A Twitter Bridge",
246+
},
247+
},
248+
SpellingCorrections: []bridge.SpellingCorrection{},
249+
})
250+
177251
// Topics from bluesky
178252
var topicLookup = map[string]string{
179253
"animals": "Animals",

twitterv1/twitterv1.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func InitServer(config *config.Config) {
119119
app.Get("/1/users/suggestions.:filetype", SuggestedTopics)
120120
app.Get("/1/users/suggestions/:slug.:filetype", GetTopicSuggestedUsers)
121121
app.Get("/i/search.:filetype", InternalSearch)
122+
app.Get("/i/discovery.:filetype", discovery)
122123

123124
// Lists
124125
app.Get("/1/lists.:filetype", GetUsersLists)

0 commit comments

Comments
 (0)