Skip to content

Commit 0267ae9

Browse files
committed
feat: mirror request user/show
1 parent b2eed4a commit 0267ae9

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

twitterv1/twitterv1.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"encoding/xml"
77
"fmt"
8+
"strings"
89

910
blueskyapi "github.com/Preloading/TwitterAPIBridge/bluesky"
1011
"github.com/Preloading/TwitterAPIBridge/config"
@@ -109,6 +110,21 @@ func InitServer(config *config.Config) {
109110

110111
// Users
111112
app.Get("/1/users/show.:filetype", user_info)
113+
app.Get("/1/users/show/*", func(c *fiber.Ctx) error {
114+
path := c.Params("*")
115+
lastDotIndex := strings.LastIndex(path, ".")
116+
117+
if lastDotIndex == -1 {
118+
// No file extension found
119+
c.Locals("handle", path)
120+
c.Locals("filetype", "json") // Default to JSON
121+
} else {
122+
c.Locals("handle", path[:lastDotIndex])
123+
c.Locals("filetype", path[lastDotIndex+1:])
124+
}
125+
126+
return user_info(c)
127+
})
112128
app.Get("/1/users/lookup.:filetype", UsersLookup)
113129
app.Post("/1/users/lookup.:filetype", UsersLookup)
114130
app.Get("/1/friendships/lookup.:filetype", UserRelationships)
@@ -182,6 +198,9 @@ func MobileClientApiDecider(c *fiber.Ctx) error {
182198

183199
func EncodeAndSend(c *fiber.Ctx, data interface{}) error {
184200
encodeType := c.Params("filetype")
201+
if encodeType == "" {
202+
encodeType = c.Locals("filetype").(string)
203+
}
185204
switch encodeType {
186205
case "xml":
187206
// Encode the data to XML

twitterv1/user.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
// https://web.archive.org/web/20120508075505/https://dev.twitter.com/docs/api/1/get/users/show
1414
func user_info(c *fiber.Ctx) error {
1515
actor := c.Query("screen_name")
16+
if ac := c.Locals("handle"); ac != nil {
17+
actor = ac.(string)
18+
}
1619

1720
if actor == "" {
1821
userIDStr := c.Query("user_id")

0 commit comments

Comments
 (0)