aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2022-10-06 06:30:04 +0200
committerGitHub <noreply@github.com>2022-10-06 06:30:04 +0200
commit6ef03f9734626ce6f4f179ac5b878e7a2237eb11 (patch)
treeb18771b9e49eb49fdb46e3e2c44c1bc3db72e423
parent1401943e7b9f4f65e082817feed880761b1f397c (diff)
parent3c86afcce4ffcc2bb5ec897587c74a80c5a39b8e (diff)
downloadnextcloud-server-6ef03f9734626ce6f4f179ac5b878e7a2237eb11.tar.gz
nextcloud-server-6ef03f9734626ce6f4f179ac5b878e7a2237eb11.zip
Merge pull request #34401 from nextcloud/fix/file-reference-no-preview-fallback-image
File reference: fallback icon to file type if no preview
-rw-r--r--lib/private/Collaboration/Reference/File/FileReferenceProvider.php16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/private/Collaboration/Reference/File/FileReferenceProvider.php b/lib/private/Collaboration/Reference/File/FileReferenceProvider.php
index 9109cbf7377..4e6c7ea623f 100644
--- a/lib/private/Collaboration/Reference/File/FileReferenceProvider.php
+++ b/lib/private/Collaboration/Reference/File/FileReferenceProvider.php
@@ -28,6 +28,7 @@ use OC\User\NoUserException;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
use OCP\Collaboration\Reference\Reference;
+use OCP\Files\IMimeTypeDetector;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
@@ -42,12 +43,18 @@ class FileReferenceProvider implements IReferenceProvider {
private IRootFolder $rootFolder;
private ?string $userId;
private IPreview $previewManager;
+ private IMimeTypeDetector $mimeTypeDetector;
- public function __construct(IURLGenerator $urlGenerator, IRootFolder $rootFolder, IUserSession $userSession, IPreview $previewManager) {
+ public function __construct(IURLGenerator $urlGenerator,
+ IRootFolder $rootFolder,
+ IUserSession $userSession,
+ IMimeTypeDetector $mimeTypeDetector,
+ IPreview $previewManager) {
$this->urlGenerator = $urlGenerator;
$this->rootFolder = $rootFolder;
$this->userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null;
$this->previewManager = $previewManager;
+ $this->mimeTypeDetector = $mimeTypeDetector;
}
public function matchReference(string $referenceText): bool {
@@ -127,7 +134,12 @@ class FileReferenceProvider implements IReferenceProvider {
$reference->setTitle($file->getName());
$reference->setDescription($file->getMimetype());
$reference->setUrl($this->urlGenerator->getAbsoluteURL('/index.php/f/' . $fileId));
- $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 1600, 'y' => 630, 'fileId' => $fileId]));
+ if ($this->previewManager->isMimeSupported($file->getMimeType())) {
+ $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 1600, 'y' => 630, 'fileId' => $fileId]));
+ } else {
+ $fileTypeIconUrl = $this->mimeTypeDetector->mimeTypeIcon($file->getMimeType());
+ $reference->setImageUrl($fileTypeIconUrl);
+ }
$reference->setRichObject('file', [
'id' => $file->getId(),