diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index 050a126..dcc1d3c 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -67,6 +67,7 @@ func (tc *TwitterClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2. uploadMediaParams := &payload.UploadMediaQuery{ MediaCategory: MSG_TYPE_TO_MEDIA_CATEGORY[content.MsgType], + MediaType: content.Info.MimeType, } if content.Info.MimeType == "image/gif" { uploadMediaParams.MediaCategory = "dm_gif" diff --git a/pkg/twittermeow/client_test.go b/pkg/twittermeow/client_test.go index 092d2f0..8aeee90 100644 --- a/pkg/twittermeow/client_test.go +++ b/pkg/twittermeow/client_test.go @@ -186,7 +186,7 @@ func uploadAndSendImageTest(initialInboxData *response.XInboxData) { } uploadQuery := &payload.UploadMediaQuery{ - MediaType: payload.MEDIA_TYPE_IMAGE_JPEG, + MediaType: "image/jpeg", MediaCategory: payload.MEDIA_CATEGORY_DM_IMAGE, } @@ -252,7 +252,7 @@ func uploadAndSendGifTest(initialInboxData *response.XInboxData) { uploadQuery := &payload.UploadMediaQuery{ SourceURL: "https://media1.giphy.com/media/v1.Y2lkPWU4MjZjOWZjYzdkYTk5YWM3ODE2MjczYTlkYWFiZjY2MDkxYTIyZDJmMjVlMDAwYiZlcD12MV9naWZzX2NhdGVnb3JpZXNfY2F0ZWdvcnlfdGFnJmN0PWc/z3HFoEzXCMykr4L0TB/giphy.gif", - MediaType: payload.MEDIA_TYPE_IMAGE_GIF, + MediaType: "image/gif", MediaCategory: payload.MEDIA_CATEGORY_DM_GIF, } mediaResult, err := cli.UploadMedia(uploadQuery, nil) @@ -294,7 +294,7 @@ func uploadAndSendVideoTest(initialInboxData *response.XInboxData) { } uploadQuery := &payload.UploadMediaQuery{ - MediaType: payload.MEDIA_TYPE_VIDEO_MP4, + MediaType: "video/mp4", MediaCategory: payload.MEDIA_CATEGORY_DM_VIDEO, } diff --git a/pkg/twittermeow/data/payload/form.go b/pkg/twittermeow/data/payload/form.go index 00622a4..785d53f 100644 --- a/pkg/twittermeow/data/payload/form.go +++ b/pkg/twittermeow/data/payload/form.go @@ -154,14 +154,6 @@ const ( MEDIA_CATEGORY_DM_GIF MediaCategory = "dm_gif" ) -type MediaType string - -const ( - MEDIA_TYPE_IMAGE_JPEG MediaType = "image/jpeg" - MEDIA_TYPE_IMAGE_GIF MediaType = "image/gif" - MEDIA_TYPE_VIDEO_MP4 MediaType = "video/mp4" -) - type UploadMediaQuery struct { Command string `url:"command,omitempty"` TotalBytes int `url:"total_bytes,omitempty"` @@ -170,7 +162,7 @@ type UploadMediaQuery struct { VideoDurationMS float32 `url:"video_duration_ms,omitempty"` OriginalMD5 string `url:"original_md5,omitempty"` SegmentIndex int `url:"segment_index,omitempty"` - MediaType MediaType `url:"media_type,omitempty"` + MediaType string `url:"media_type,omitempty"` MediaCategory MediaCategory `url:"media_category,omitempty"` } diff --git a/pkg/twittermeow/headers.go b/pkg/twittermeow/headers.go index 9f97d01..738341e 100644 --- a/pkg/twittermeow/headers.go +++ b/pkg/twittermeow/headers.go @@ -24,22 +24,23 @@ const SecCHPrefersColorScheme = "light" const UDID = OSName + "/" + BrowserName var BaseHeaders = http.Header{ - "accept": []string{"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"}, - "accept-language": []string{"en-US,en;q=0.9"}, - "user-agent": []string{UserAgent}, - "sec-ch-ua": []string{SecCHUserAgent}, - "sec-ch-ua-platform": []string{SecCHPlatform}, - "sec-ch-ua-mobile": []string{SecCHMobile}, - "referer": []string{endpoints.BASE_URL + "/"}, - "origin": []string{endpoints.BASE_URL}, - //"sec-ch-prefers-color-scheme": []string{SecCHPrefersColorScheme}, - //"sec-ch-ua-full-version-list": []string{SecCHFullVersionList}, - //"sec-ch-ua-model": []string{SecCHModel}, - //"sec-ch-ua-platform-version": []string{SecCHPlatformVersion}, + "Accept": []string{"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"}, + "Accept-Language": []string{"en-US,en;q=0.9"}, + "User-Agent": []string{UserAgent}, + "Sec-Ch-Ua": []string{SecCHUserAgent}, + "Sec-Ch-Ua-Platform": []string{SecCHPlatform}, + "Sec-Ch-Ua-Mobile": []string{SecCHMobile}, + "Referer": []string{endpoints.BASE_URL + "/"}, + "Origin": []string{endpoints.BASE_URL}, + //"Sec-Ch-Prefers-Color-Scheme": []string{SecCHPrefersColorScheme}, + //"Sec-Ch-Ua-Full-Version-List": []string{SecCHFullVersionList}, + //"Sec-Ch-Ua-Model": []string{SecCHModel}, + //"Sec-Ch-Ua-Platform-Version": []string{SecCHPlatformVersion}, } type HeaderOpts struct { WithAuthBearer bool + WithNonAuthBearer bool WithCookies bool WithXGuestToken bool WithXTwitterHeaders bool @@ -60,11 +61,11 @@ func (c *Client) buildHeaders(opts HeaderOpts) http.Header { opts.Extra["cookie"] = c.cookies.String() } - if opts.WithAuthBearer { + if opts.WithAuthBearer || opts.WithNonAuthBearer { authTokens := c.session.GetAuthTokens() // check if client is authenticated here var bearerToken string - if c.isAuthenticated() { + if c.isAuthenticated() && !opts.WithNonAuthBearer { bearerToken = authTokens.authenticated } else { bearerToken = authTokens.notAuthenticated diff --git a/pkg/twittermeow/media.go b/pkg/twittermeow/media.go index 164384f..5f637e0 100644 --- a/pkg/twittermeow/media.go +++ b/pkg/twittermeow/media.go @@ -34,11 +34,17 @@ func (c *Client) UploadMedia(params *payload.UploadMediaQuery, mediaBytes []byte url := fmt.Sprintf("%s?%s", endpoints.UPLOAD_MEDIA_URL, string(encodedQuery)) headerOpts := HeaderOpts{ - WithAuthBearer: true, - WithXCsrfToken: true, - WithCookies: true, - Origin: endpoints.BASE_URL, - Referer: endpoints.BASE_URL + "/", + WithNonAuthBearer: true, + WithXCsrfToken: true, + WithCookies: true, + Origin: endpoints.BASE_URL, + Referer: endpoints.BASE_URL + "/", + Extra: map[string]string{ + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "same-site", + "accept": "*/*", + }, } headers := c.buildHeaders(headerOpts)