Merge pull request #20131 from nextcloud/backport/19699-20032/stable17

[stable17] Fix PDF and video viewers on public links
This commit is contained in:
Roeland Jago Douma 2020-03-24 20:29:39 +01:00 committed by GitHub
commit 9df9737111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 8 deletions

View File

@ -46,6 +46,7 @@ use OCP\AppFramework\Http\Template\ExternalShareMenuAction;
use OCP\AppFramework\Http\Template\LinkMenuAction;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\Defaults;
use OCP\Files\Folder;
use OCP\IL10N;
use OCP\Template;
use OCP\Share;
@ -528,10 +529,6 @@ class ShareController extends AuthPublicShareController {
throw new NotFoundException();
}
if ($share->getHideDownload()) {
return new NotFoundResponse();
}
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
$originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
@ -561,11 +558,17 @@ class ShareController extends AuthPublicShareController {
if ($node instanceof \OCP\Files\File) {
// Single file download
$this->singleFileDownloaded($share, $share->getNode());
} else if (!empty($files_list)) {
$this->fileListDownloaded($share, $files_list, $node);
} else {
// The folder is downloaded
$this->singleFileDownloaded($share, $share->getNode());
try {
if (!empty($files_list)) {
$this->fileListDownloaded($share, $files_list, $node);
} else {
// The folder is downloaded
$this->singleFileDownloaded($share, $share->getNode());
}
} catch (NotFoundException $e) {
return new NotFoundResponse();
}
}
}
@ -617,8 +620,13 @@ class ShareController extends AuthPublicShareController {
* @param Share\IShare $share
* @param array $files_list
* @param \OCP\Files\Folder $node
* @throws NotFoundException when trying to download a folder or multiple files of a "hide download" share
*/
protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) {
if ($share->getHideDownload() && count($files_list) > 1) {
throw new NotFoundException('Downloading more than 1 file');
}
foreach ($files_list as $file) {
$subNode = $node->get($file);
$this->singleFileDownloaded($share, $subNode);
@ -630,8 +638,12 @@ class ShareController extends AuthPublicShareController {
* create activity if a single file was downloaded from a link share
*
* @param Share\IShare $share
* @throws NotFoundException when trying to download a folder of a "hide download" share
*/
protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) {
if ($share->getHideDownload() && $node instanceof Folder) {
throw new NotFoundException('Downloading a folder');
}
$fileId = $node->getId();