X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=thumb.php;h=c4b40dc76fa12888d2f9414a7a02b0e9b4265d12;hp=02ac0b024dcd580e8030f1863cad7ebee407cc46;hb=b0689e79293e764d81bfffd5d76e592420e7f0f0;hpb=43d159d469e9cbe4050266c1f05a84559bd24dc1 diff --git a/thumb.php b/thumb.php index 02ac0b024d..c4b40dc76f 100644 --- a/thumb.php +++ b/thumb.php @@ -337,7 +337,16 @@ function wfStreamThumb( array $params ) { return; } - list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath ); + $thumbProxyUrl = $img->getRepo()->getThumbProxyUrl(); + + if ( strlen( $thumbProxyUrl ) ) { + wfProxyThumbnailRequest( $img, $thumbName ); + // No local fallback when in proxy mode + return; + } else { + // Generate the thumbnail locally + list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath ); + } /** @var MediaTransformOutput|MediaTransformError|bool $thumb */ @@ -377,6 +386,43 @@ function wfStreamThumb( array $params ) { } } +/** + * Proxies thumbnail request to a service that handles thumbnailing + * + * @param File $img + * @param string $thumbName + */ +function wfProxyThumbnailRequest( $img, $thumbName ) { + $thumbProxyUrl = $img->getRepo()->getThumbProxyUrl(); + + // Instead of generating the thumbnail ourselves, we proxy the request to another service + $thumbProxiedUrl = $thumbProxyUrl . $img->getThumbRel( $thumbName ); + + $req = MWHttpRequest::factory( $thumbProxiedUrl ); + $secret = $img->getRepo()->getThumbProxySecret(); + + // Pass a secret key shared with the proxied service if any + if ( strlen( $secret ) ) { + $req->setHeader( 'X-Swift-Secret', $secret ); + } + + // Send request to proxied service + $status = $req->execute(); + + // Simply serve the response from the proxied service as-is + header( 'HTTP/1.1 ' . $req->getStatus() ); + + $headers = $req->getResponseHeaders(); + + foreach ( $headers as $key => $values ) { + foreach ( $values as $value ) { + header( $key . ': ' . $value, false ); + } + } + + echo $req->getContent(); +} + /** * Actually try to generate a new thumbnail *