Skip to content

Commit

Permalink
Move image URL fixing to where the URL is used
Browse files Browse the repository at this point in the history
The change I made in #513 fixed the URLs after they were used
to fetch the images! This moves that same logic to the location
in which it'll actually work. Sorry for the noise!

Bug: T354242
  • Loading branch information
samwilson authored Aug 15, 2024
1 parent 716f373 commit bb33d8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
19 changes: 8 additions & 11 deletions src/BookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,6 @@ public function getMetadata( string $title, bool $isMetadata, DOMDocument $doc )

$pictures = $this->getPicturesData( $pictures );
}
// Clean up the image URLs if they're protocol relative or only a path. This would probably be better in
// PageParser, but it doesn't have access to the domain name.
foreach ( $pictures as $pic ) {
$url = $pic->url;
if ( str_starts_with( $url, '//' ) ) {
$url = 'https:' . $url;
} elseif ( str_starts_with( $url, '/' ) ) {
$url = 'https://' . $this->api->getDomainName() . $url;
}
$pic->url = $url;
}
$book->pictures = $pictures;

return $book;
Expand Down Expand Up @@ -226,6 +215,14 @@ protected function getPicturesData( array $pictures ) {
$requests = function () use ( $client, $pictures ) {
foreach ( $pictures as $picture ) {
$url = $picture->url;
// Clean up the image URLs if they're protocol relative or only a path. This would probably be better in
// PageParser, but it doesn't have access to the domain name.
if ( str_starts_with( $url, '//' ) ) {
$url = 'https:' . $url;
} elseif ( str_starts_with( $url, '/' ) ) {
$url = 'https://' . $this->api->getDomainName() . $url;
}
$picture->url = $url;
yield function () use ( $client, $url ) {
// We could use the 'sink' option here, but for https://github.com/Kevinrob/guzzle-cache-middleware/issues/82
// @phan-suppress-next-line PhanUndeclaredMethod Magic method not declared in the interface
Expand Down
3 changes: 2 additions & 1 deletion tests/Cli/BookCliTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class BookCliTest extends TestCase {
public function bookProvider() {
return [
[ 'The_Kiss_and_its_History', 'en' ],
[ 'Les_Fleurs_du_mal', 'fr' ]
[ 'Les_Fleurs_du_mal', 'fr' ],
[ 'Stelae_of_Naukratis', 'mul' ],
];
}

Expand Down

0 comments on commit bb33d8e

Please # to comment.