8000 [Notifier] [Twitter] Fix post INIT upload by matyo91 · Pull Request #58658 · symfony/symfony · GitHub 8000
[go: up one dir, main page]

Skip to content

[Notifier] [Twitter] Fix post INIT upload #58658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public function testTweetImage()
$transport = $this->createTransport(new MockHttpClient((function () {
yield function (string $method, string $url, array $options) {
$this->assertSame('POST', $method);
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json?command=INIT&total_bytes=185&media_type=image/gif&media_category=tweet_image', $url);
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json', $url);
$this->assertArrayHasKey('body', $options);
$this->assertSame($options['body'], 'command=INIT&total_bytes=185&media_type=image%2Fgif&media_category=tweet_image');
$this->assertArrayHasKey('authorization', $options['normalized_headers']);

return new MockResponse('{"media_id_string":"gif123"}');
Expand Down Expand Up @@ -127,15 +129,19 @@ public function testTweetVideo()
$transport = $this->createTransport(new MockHttpClient((function () {
yield function (string $method, string $url, array $options) {
$this->assertSame('POST', $method);
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json?command=INIT&total_bytes=185&media_type=image/gif&media_category=tweet_video', $url);
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json', $url);
$this->assertArrayHasKey('body', $options);
$this->assertSame($options['body'], 'command=INIT&total_bytes=185&media_type=image%2Fgif&media_category=tweet_video');
$this->assertArrayHasKey('authorization', $options['normalized_headers']);

return new MockResponse('{"media_id_string":"gif123"}');
};

yield function (string $method, string $url, array $options) {
$this->assertSame('POST', $method);
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json?command=INIT&total_bytes=185&media_type=image/gif&media_category=subtitles', $url);
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json', $url);
$this->assertArrayHasKey('body', $options);
$this->assertSame($options['body'], 'command=INIT&total_bytes=185&media_type=image%2Fgif&media_category=subtitles');
$this->assertArrayHasKey('authorization', $options['normalized_headers']);

return new MockResponse('{"media_id_string":"sub234"}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,32 +160,32 @@ private function uploadMedia(array $media): array
'category' => $category,
'owners' => $extraOwners,
]) {
$query = [
$body = [
'command' => 'INIT',
'total_bytes' => $file->getSize(),
'media_type' => $file->getContentType(),
];

if ($category) {
$query['media_category'] = $category;
$body['media_category'] = $category;
}

if ($extraOwners) {
$query['additional_owners'] = implode(',', $extraOwners);
$body['additional_owners'] = implode(',', $extraOwners);
}

$pool[++$i] = $this->request('POST', '/1.1/media/upload.json', [
'query' => $query,
'body' => $body,
'user_data' => [$i, null, 0, fopen($file->getPath(), 'r'), $alt, $subtitles],
]);

if ($subtitles) {
$query['total_bytes'] = $subtitles->getSize();
$query['media_type'] = $subtitles->getContentType();
$query['media_category'] = 'subtitles';
$body['total_bytes'] = $subtitles->getSize();
$body['media_type'] = $subtitles->getContentType();
$body['media_category'] = 'subtitles';

$pool[++$i] = $this->request('POST', '/1.1/media/upload.json', [
'query' => $query,
'body' => $body,
'user_data' => [$i, null, 0, fopen($subtitles->getPath(), 'r'), null, $subtitles],
]);
}
Expand Down
Loading
0