Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File reference: use the file type icon as fallback when no preview pr…
…ovider for this type

Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
Julien Veyssier authored and backportbot-nextcloud[bot] committed Oct 6, 2022
commit 4807c23e0938e95ca13393fa8c8e837bee2e6919
16 changes: 14 additions & 2 deletions lib/private/Collaboration/Reference/File/FileReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand All @@ -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 {
Expand Down Expand Up @@ -127,7 +134,12 @@ private function fetchReference(Reference $reference): void {
$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(),
Expand Down