https://web.archive.org/web/20120508224719/https://dev.twitter.com/docs/api/1/post/statuses/update
(c *fiber.Ctx)
| 69 | |
| 70 | // https://web.archive.org/web/20120508224719/https://dev.twitter.com/docs/api/1/post/statuses/update |
| 71 | func status_update_with_media(c *fiber.Ctx) error { |
| 72 | my_did, pds, _, oauthToken, err := GetAuthFromReq(c) |
| 73 | |
| 74 | if err != nil { |
| 75 | return MissingAuth(c, err) |
| 76 | } |
| 77 | |
| 78 | status := c.FormValue("status") |
| 79 | |
| 80 | // The docs say it's an array, but I can only upload one imageData.... so idk |
| 81 | imageData, err := c.FormFile("media") |
| 82 | if err != nil { |
| 83 | fmt.Println("Error:", err) |
| 84 | return ReturnError(c, "Please upload an image", 195, fiber.StatusForbidden) |
| 85 | } |
| 86 | |
| 87 | // read the image file content |
| 88 | file, err := imageData.Open() |
| 89 | if err != nil { |
| 90 | fmt.Println("Error:", err) |
| 91 | return ReturnError(c, "An invalid image was uploaded", 195, fiber.StatusForbidden) |
| 92 | } |
| 93 | defer file.Close() |
| 94 | |
| 95 | imageBytes, err := io.ReadAll(file) |
| 96 | if err != nil { |
| 97 | fmt.Println("Error:", err) |
| 98 | return ReturnError(c, "Failed to process image", 131, fiber.StatusInternalServerError) |
| 99 | } |
| 100 | |
| 101 | // Get image resolution |
| 102 | imageConfig, _, err := image.DecodeConfig(bytes.NewReader(imageBytes)) |
| 103 | if err != nil { |
| 104 | fmt.Println("Error:", err) |
| 105 | return ReturnError(c, "Failed to process image", 131, fiber.StatusInternalServerError) |
| 106 | } |
| 107 | |
| 108 | // upload our new profile picture |
| 109 | imageBlob, err := blueskyapi.UploadBlob(*pds, *oauthToken, imageBytes, c.Get("Content-Type")) |
| 110 | if err != nil { |
| 111 | fmt.Println("Error:", err) |
| 112 | return HandleBlueskyError(c, err.Error(), "com.atproto.repo.uploadBlob", status_update_with_media) |
| 113 | } |
| 114 | |
| 115 | // Status parsing! |
| 116 | mentions := findHandleInstances(status) |
| 117 | links := findUrlInstances(status) |
| 118 | tags := findTagInstances(status) |
| 119 | |
| 120 | // trim_user := c.FormValue("trim_user") // Unused |
| 121 | encoded_in_reply_to_status_id_str := c.FormValue("in_reply_to_status_id") |
| 122 | encoded_in_reply_to_status_id_int, err := strconv.ParseInt(encoded_in_reply_to_status_id_str, 10, 64) |
| 123 | var in_reply_to_status_id *string |
| 124 | if err == nil { |
| 125 | in_reply_to_status_id, _, _, err = bridge.TwitterMsgIdToBluesky(&encoded_in_reply_to_status_id_int) |
| 126 | if err != nil { |
| 127 | return ReturnError(c, "The in_reply_to_status_id was not found", 144, fiber.StatusNotFound) |
| 128 | } |
nothing calls this directly
no test coverage detected