mirror of
https://github.com/friendica/friendica
synced 2024-12-23 04:40:15 +00:00
AVoid throwing an error / store the size of pages
This commit is contained in:
parent
4dd64b1a5d
commit
7fdf244bae
3 changed files with 8 additions and 4 deletions
|
@ -193,7 +193,7 @@ class Media
|
||||||
$media['mimetype'] = $curlResult->getContentType() ?? '';
|
$media['mimetype'] = $curlResult->getContentType() ?? '';
|
||||||
}
|
}
|
||||||
if (empty($media['size'])) {
|
if (empty($media['size'])) {
|
||||||
$media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? 0);
|
$media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? strlen($curlResult->getBodyString() ?? ''));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Logger::notice('Could not fetch head', ['media' => $media]);
|
Logger::notice('Could not fetch head', ['media' => $media]);
|
||||||
|
@ -363,6 +363,7 @@ class Media
|
||||||
private static function addPage(array $media): array
|
private static function addPage(array $media): array
|
||||||
{
|
{
|
||||||
$data = ParseUrl::getSiteinfoCached($media['url']);
|
$data = ParseUrl::getSiteinfoCached($media['url']);
|
||||||
|
$media['size'] = $data['size'] ?? null;
|
||||||
$media['preview'] = $data['images'][0]['src'] ?? null;
|
$media['preview'] = $data['images'][0]['src'] ?? null;
|
||||||
$media['preview-height'] = $data['images'][0]['height'] ?? null;
|
$media['preview-height'] = $data['images'][0]['height'] ?? null;
|
||||||
$media['preview-width'] = $data['images'][0]['width'] ?? null;
|
$media['preview-width'] = $data['images'][0]['width'] ?? null;
|
||||||
|
|
|
@ -61,11 +61,13 @@ class HttpClient implements ICanSendHttpRequests
|
||||||
|
|
||||||
$host = parse_url($url, PHP_URL_HOST);
|
$host = parse_url($url, PHP_URL_HOST);
|
||||||
if (empty($host)) {
|
if (empty($host)) {
|
||||||
throw new \InvalidArgumentException('Unable to retrieve the host in URL: ' . $url);
|
$this->logger->notice('Unable to retrieve the host in URL', ['url' => $url]);
|
||||||
|
$this->profiler->stopRecording();
|
||||||
|
return CurlResult::createErrorCurl($this->logger, $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filter_var($host, FILTER_VALIDATE_IP) && !@dns_get_record($host . '.', DNS_A) && !@dns_get_record($host . '.', DNS_AAAA)) {
|
if (!filter_var($host, FILTER_VALIDATE_IP) && !@dns_get_record($host . '.', DNS_A) && !@dns_get_record($host . '.', DNS_AAAA)) {
|
||||||
$this->logger->debug('URL cannot be resolved.', ['url' => $url]);
|
$this->logger->info('URL cannot be resolved.', ['url' => $url]);
|
||||||
$this->profiler->stopRecording();
|
$this->profiler->stopRecording();
|
||||||
return CurlResult::createErrorCurl($this->logger, $url);
|
return CurlResult::createErrorCurl($this->logger, $url);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +77,7 @@ class HttpClient implements ICanSendHttpRequests
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($url) > 1000) {
|
if (strlen($url) > 1000) {
|
||||||
$this->logger->debug('URL is longer than 1000 characters.', ['url' => $url]);
|
$this->logger->info('URL is longer than 1000 characters.', ['url' => $url]);
|
||||||
$this->profiler->stopRecording();
|
$this->profiler->stopRecording();
|
||||||
return CurlResult::createErrorCurl($this->logger, substr($url, 0, 200));
|
return CurlResult::createErrorCurl($this->logger, substr($url, 0, 200));
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,6 +245,7 @@ class ParseUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = $curlResult->getBodyString();
|
$body = $curlResult->getBodyString();
|
||||||
|
$siteinfo['size'] = mb_strlen($body);
|
||||||
|
|
||||||
$charset = '';
|
$charset = '';
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue