aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Collaboration
diff options
context:
space:
mode:
authorJulien Veyssier <julien-nc@posteo.net>2023-06-05 13:29:44 +0200
committerJulien Veyssier <julien-nc@posteo.net>2023-06-09 10:37:58 +0200
commit3621a6b4ece3951871597782672e257073fe5864 (patch)
tree168b2ffb3927735f7d0c37d69588be33cc6c045b /lib/private/Collaboration
parenta719b433a125b2f0e6948180fa0ca35ff7deb0e0 (diff)
downloadnextcloud-server-3621a6b4ece3951871597782672e257073fe5864.tar.gz
nextcloud-server-3621a6b4ece3951871597782672e257073fe5864.zip
avoid requests to opengraph image if no host detected
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'lib/private/Collaboration')
-rw-r--r--lib/private/Collaboration/Reference/LinkReferenceProvider.php37
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/private/Collaboration/Reference/LinkReferenceProvider.php b/lib/private/Collaboration/Reference/LinkReferenceProvider.php
index 448a55f9300..dbdab75abcb 100644
--- a/lib/private/Collaboration/Reference/LinkReferenceProvider.php
+++ b/lib/private/Collaboration/Reference/LinkReferenceProvider.php
@@ -151,22 +151,27 @@ class LinkReferenceProvider implements IReferenceProvider {
if ($object->images) {
try {
- $appData = $this->appDataFactory->get('core');
- try {
- $folder = $appData->getFolder('opengraph');
- } catch (NotFoundException $e) {
- $folder = $appData->newFolder('opengraph');
- }
- $response = $client->get($object->images[0]->url, [ 'timeout' => 10 ]);
- $contentType = $response->getHeader('Content-Type');
- $contentLength = $response->getHeader('Content-Length');
-
- if (in_array($contentType, self::ALLOWED_CONTENT_TYPES, true) && $contentLength < self::MAX_PREVIEW_SIZE) {
- $stream = Utils::streamFor($response->getBody());
- $bodyStream = new LimitStream($stream, self::MAX_PREVIEW_SIZE, 0);
- $reference->setImageContentType($contentType);
- $folder->newFile(md5($reference->getId()), $bodyStream->getContents());
- $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())]));
+ $host = parse_url($object->images[0]->url, PHP_URL_HOST);
+ if ($host === false || $host === null) {
+ $this->logger->warning('Could not detect host of open graph image URI for ' . $reference->getId());
+ } else {
+ $appData = $this->appDataFactory->get('core');
+ try {
+ $folder = $appData->getFolder('opengraph');
+ } catch (NotFoundException $e) {
+ $folder = $appData->newFolder('opengraph');
+ }
+ $response = $client->get($object->images[0]->url, ['timeout' => 10]);
+ $contentType = $response->getHeader('Content-Type');
+ $contentLength = $response->getHeader('Content-Length');
+
+ if (in_array($contentType, self::ALLOWED_CONTENT_TYPES, true) && $contentLength < self::MAX_PREVIEW_SIZE) {
+ $stream = Utils::streamFor($response->getBody());
+ $bodyStream = new LimitStream($stream, self::MAX_PREVIEW_SIZE, 0);
+ $reference->setImageContentType($contentType);
+ $folder->newFile(md5($reference->getId()), $bodyStream->getContents());
+ $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())]));
+ }
}
} catch (GuzzleException $e) {
$this->logger->info('Failed to fetch and store the open graph image for ' . $reference->getId(), ['exception' => $e]);