Simplyfying code

This commit is contained in:
Michael 2021-07-05 04:16:02 +00:00
parent 7188ed745c
commit 844727dc19
2 changed files with 5 additions and 23 deletions

View file

@ -40,10 +40,7 @@ class Proxy extends BaseModule
{ {
/** /**
* Initializer method for this class. * Fetch remote image content
*
* Sets application instance and checks if /proxy/ path is writable.
*
*/ */
public static function rawContent(array $parameters = []) public static function rawContent(array $parameters = [])
{ {
@ -81,8 +78,7 @@ class Proxy extends BaseModule
$fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['timeout' => 10]); $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['timeout' => 10]);
$img_str = $fetchResult->getBody(); $img_str = $fetchResult->getBody();
// If there is an error then return an error if (!$fetchResult->isSuccess() || empty($img_str)) {
if ((substr($fetchResult->getReturnCode(), 0, 1) == '4') || empty($img_str)) {
Logger::info('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]); Logger::info('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]);
self::responseError(); self::responseError();
// stop. // stop.

View file

@ -87,21 +87,11 @@ class Proxy
*/ */
public static function proxifyUrl($url, $size = '') public static function proxifyUrl($url, $size = '')
{ {
// Get application instance
$a = DI::app();
// Trim URL first // Trim URL first
$url = trim($url); $url = trim($url);
// Is no http in front of it? // Quit if not an HTTP/HTTPS link or if local
/// @TODO To weak test for being a valid URL if (!in_array(parse_url($url, PHP_URL_SCHEME), ['http', 'https']) || self::isLocalImage($url)) {
if (substr($url, 0, 4) !== 'http') {
return $url;
}
// Only continue if it isn't a local image and the isn't deactivated
if (self::isLocalImage($url)) {
$url = str_replace(Strings::normaliseLink(DI::baseUrl()) . '/', DI::baseUrl() . '/', $url);
return $url; return $url;
} }
@ -175,11 +165,7 @@ class Proxy
return true; return true;
} }
// links normalised - bug #431 return Network::isLocalLink($url);
$baseurl = Strings::normaliseLink(DI::baseUrl());
$url = Strings::normaliseLink($url);
return (substr($url, 0, strlen($baseurl)) == $baseurl);
} }
/** /**