Skip to content

Commit 9df9737

Browse files
authored
Merge pull request #20131 from nextcloud/backport/19699-20032/stable17
[stable17] Fix PDF and video viewers on public links
2 parents 22a0a33 + 4f39738 commit 9df9737

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

apps/files_sharing/lib/Controller/ShareController.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
use OCP\AppFramework\Http\Template\LinkMenuAction;
4747
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
4848
use OCP\Defaults;
49+
use OCP\Files\Folder;
4950
use OCP\IL10N;
5051
use OCP\Template;
5152
use OCP\Share;
@@ -528,10 +529,6 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS
528529
throw new NotFoundException();
529530
}
530531

531-
if ($share->getHideDownload()) {
532-
return new NotFoundResponse();
533-
}
534-
535532
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
536533
$originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
537534

@@ -561,11 +558,17 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS
561558
if ($node instanceof \OCP\Files\File) {
562559
// Single file download
563560
$this->singleFileDownloaded($share, $share->getNode());
564-
} else if (!empty($files_list)) {
565-
$this->fileListDownloaded($share, $files_list, $node);
566561
} else {
567-
// The folder is downloaded
568-
$this->singleFileDownloaded($share, $share->getNode());
562+
try {
563+
if (!empty($files_list)) {
564+
$this->fileListDownloaded($share, $files_list, $node);
565+
} else {
566+
// The folder is downloaded
567+
$this->singleFileDownloaded($share, $share->getNode());
568+
}
569+
} catch (NotFoundException $e) {
570+
return new NotFoundResponse();
571+
}
569572
}
570573
}
571574

@@ -617,8 +620,13 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS
617620
* @param Share\IShare $share
618621
* @param array $files_list
619622
* @param \OCP\Files\Folder $node
623+
* @throws NotFoundException when trying to download a folder or multiple files of a "hide download" share
620624
*/
621625
protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) {
626+
if ($share->getHideDownload() && count($files_list) > 1) {
627+
throw new NotFoundException('Downloading more than 1 file');
628+
}
629+
622630
foreach ($files_list as $file) {
623631
$subNode = $node->get($file);
624632
$this->singleFileDownloaded($share, $subNode);
@@ -630,8 +638,12 @@ protected function fileListDownloaded(Share\IShare $share, array $files_list, \O
630638
* create activity if a single file was downloaded from a link share
631639
*
632640
* @param Share\IShare $share
641+
* @throws NotFoundException when trying to download a folder of a "hide download" share
633642
*/
634643
protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) {
644+
if ($share->getHideDownload() && $node instanceof Folder) {
645+
throw new NotFoundException('Downloading a folder');
646+
}
635647

636648
$fileId = $node->getId();
637649

0 commit comments

Comments
 (0)