|
8 | 8 |
|
9 | 9 | blueskyapi "github.com/Preloading/MastodonTwitterAPI/bluesky" |
10 | 10 | "github.com/Preloading/MastodonTwitterAPI/bridge" |
| 11 | + "github.com/Preloading/MastodonTwitterAPI/db_controller" |
11 | 12 | "github.com/gofiber/fiber/v2" |
12 | 13 | ) |
13 | 14 |
|
@@ -44,6 +45,16 @@ func status_update(c *fiber.Ctx) error { |
44 | 45 | return c.Status(fiber.StatusInternalServerError).SendString("Failed to update status") |
45 | 46 | } |
46 | 47 |
|
| 48 | + db_controller.StoreAnalyticData(db_controller.AnalyticData{ |
| 49 | + DataType: "status_update", |
| 50 | + IPAddress: c.IP(), |
| 51 | + UserAgent: c.Get("User-Agent"), |
| 52 | + Language: c.Get("Accept-Language"), |
| 53 | + TwitterClient: c.Get("X-Twitter-Client"), |
| 54 | + TwitterClientVersion: c.Get("X-Twitter-Client-Version"), |
| 55 | + Timestamp: time.Now(), |
| 56 | + }) |
| 57 | + |
47 | 58 | if thread.Thread.Parent == nil { |
48 | 59 | return EncodeAndSend(c, TranslatePostToTweet(thread.Thread.Post, "", "", nil, nil, *oauthToken, *pds)) |
49 | 60 | } else { |
@@ -91,6 +102,16 @@ func retweet(c *fiber.Ctx) error { |
91 | 102 | retweet.IDStr = strconv.FormatInt(retweet.ID, 10) |
92 | 103 | originalPost.Thread.Post.Viewer.Repost = blueskyRepostURI |
93 | 104 |
|
| 105 | + db_controller.StoreAnalyticData(db_controller.AnalyticData{ |
| 106 | + DataType: "retweeted", |
| 107 | + IPAddress: c.IP(), |
| 108 | + UserAgent: c.Get("User-Agent"), |
| 109 | + Language: c.Get("Accept-Language"), |
| 110 | + TwitterClient: c.Get("X-Twitter-Client"), |
| 111 | + TwitterClientVersion: c.Get("X-Twitter-Client-Version"), |
| 112 | + Timestamp: time.Now(), |
| 113 | + }) |
| 114 | + |
94 | 115 | return EncodeAndSend(c, bridge.Retweet{ |
95 | 116 | Tweet: retweet, |
96 | 117 | RetweetedStatus: func() bridge.Tweet { // TODO: make this respond with proper retweet data |
@@ -139,6 +160,16 @@ func favourite(c *fiber.Ctx) error { |
139 | 160 | newTweet = TranslatePostToTweet(post.Thread.Post, post.Thread.Parent.Post.URI, post.Thread.Parent.Post.Author.DID, &post.Thread.Parent.Post.Record.CreatedAt, nil, *oauthToken, *pds) |
140 | 161 | } |
141 | 162 |
|
| 163 | + db_controller.StoreAnalyticData(db_controller.AnalyticData{ |
| 164 | + DataType: "favorited", |
| 165 | + IPAddress: c.IP(), |
| 166 | + UserAgent: c.Get("User-Agent"), |
| 167 | + Language: c.Get("Accept-Language"), |
| 168 | + TwitterClient: c.Get("X-Twitter-Client"), |
| 169 | + TwitterClientVersion: c.Get("X-Twitter-Client-Version"), |
| 170 | + Timestamp: time.Now(), |
| 171 | + }) |
| 172 | + |
142 | 173 | return EncodeAndSend(c, newTweet) |
143 | 174 | } |
144 | 175 |
|
@@ -176,6 +207,16 @@ func Unfavourite(c *fiber.Ctx) error { // yes i am canadian |
176 | 207 | newTweet = TranslatePostToTweet(post.Thread.Post, post.Thread.Parent.Post.URI, post.Thread.Parent.Post.Author.DID, &post.Thread.Parent.Post.Record.CreatedAt, nil, *oauthToken, *pds) |
177 | 208 | } |
178 | 209 |
|
| 210 | + db_controller.StoreAnalyticData(db_controller.AnalyticData{ |
| 211 | + DataType: "unfavorite", |
| 212 | + IPAddress: c.IP(), |
| 213 | + UserAgent: c.Get("User-Agent"), |
| 214 | + Language: c.Get("Accept-Language"), |
| 215 | + TwitterClient: c.Get("X-Twitter-Client"), |
| 216 | + TwitterClientVersion: c.Get("X-Twitter-Client-Version"), |
| 217 | + Timestamp: time.Now(), |
| 218 | + }) |
| 219 | + |
179 | 220 | return EncodeAndSend(c, newTweet) |
180 | 221 | } |
181 | 222 |
|
@@ -225,6 +266,16 @@ func DeleteTweet(c *fiber.Ctx) error { |
225 | 266 | return c.Status(fiber.StatusInternalServerError).SendString("Failed to delete post") |
226 | 267 | } |
227 | 268 |
|
| 269 | + db_controller.StoreAnalyticData(db_controller.AnalyticData{ |
| 270 | + DataType: "deleted_post", |
| 271 | + IPAddress: c.IP(), |
| 272 | + UserAgent: c.Get("User-Agent"), |
| 273 | + Language: c.Get("Accept-Language"), |
| 274 | + TwitterClient: c.Get("X-Twitter-Client"), |
| 275 | + TwitterClientVersion: c.Get("X-Twitter-Client-Version"), |
| 276 | + Timestamp: time.Now(), |
| 277 | + }) |
| 278 | + |
228 | 279 | postToDelete.Thread.Post.URI = postId |
229 | 280 | postToDelete.Thread.Post.Author.DID = *user_did |
230 | 281 |
|
|
0 commit comments