From 9dcf900e9104b4f23bfec1f00b37f6dd850ce40f Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 22 Nov 2022 11:19:33 +0100 Subject: [PATCH 1/3] Don't count range download in download limit Signed-off-by: Carl Schwan --- apps/files_sharing/lib/Controller/ShareController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index eef2f5f32bc75..b99688a94e9ef 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -431,7 +431,9 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS } $this->emitAccessShareHook($share); - $this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD); + if (!isset($_SERVER['HTTP_RANGE'])) { + $this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD); + } $server_params = [ 'head' => $this->request->getMethod() === 'HEAD' ]; From 4f84b32e2a81052585e758fc5ed9237bb7cb9579 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 22 Nov 2022 13:47:02 +0100 Subject: [PATCH 2/3] Ensure download is counted for non video files Signed-off-by: Carl Schwan --- .../lib/Controller/ShareController.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index b99688a94e9ef..b4835eaf4a2d9 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -373,11 +373,14 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath()); + $isVideo = false; // Single file share if ($share->getNode() instanceof \OCP\Files\File) { + $node = $share->getNode(); // Single file download - $this->singleFileDownloaded($share, $share->getNode()); + $this->singleFileDownloaded($share, $node); + $isVideo = str_starts_with($node->getMimeType(), 'video/'); } // Directory share else { @@ -398,8 +401,10 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS $originalSharePath = $userFolder->getRelativePath($node->getPath()); if ($node instanceof \OCP\Files\File) { + $node = $share->getNode(); // Single file download - $this->singleFileDownloaded($share, $share->getNode()); + $this->singleFileDownloaded($share, $node); + $isVideo = str_starts_with($node->getMimeType(), 'video/'); } else { try { if (!empty($files_list)) { @@ -431,7 +436,9 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS } $this->emitAccessShareHook($share); - if (!isset($_SERVER['HTTP_RANGE'])) { + + // Ensure download limit is counted unless we are streaming a video + if (!isset($_SERVER['HTTP_RANGE']) || !$isVideo) { $this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD); } From 3cbfab621efa5069d0d98ab2273a36846ff96060 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 22 Nov 2022 14:04:58 +0100 Subject: [PATCH 3/3] Also take in count audio files Signed-off-by: Carl Schwan --- apps/files_sharing/lib/Controller/ShareController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index b4835eaf4a2d9..5b0b082537a0c 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -373,14 +373,14 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath()); - $isVideo = false; + $isVideoAudio = false; // Single file share if ($share->getNode() instanceof \OCP\Files\File) { $node = $share->getNode(); // Single file download $this->singleFileDownloaded($share, $node); - $isVideo = str_starts_with($node->getMimeType(), 'video/'); + $isVideoAutio = str_starts_with($node->getMimeType(), 'video/') || str_starts_with($node->getMimeType(), 'audio/'); } // Directory share else { @@ -404,7 +404,7 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS $node = $share->getNode(); // Single file download $this->singleFileDownloaded($share, $node); - $isVideo = str_starts_with($node->getMimeType(), 'video/'); + $isVideoAutio = str_starts_with($node->getMimeType(), 'video/') || str_starts_with($node->getMimeType(), 'audio/'); } else { try { if (!empty($files_list)) { @@ -437,8 +437,8 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS $this->emitAccessShareHook($share); - // Ensure download limit is counted unless we are streaming a video - if (!isset($_SERVER['HTTP_RANGE']) || !$isVideo) { + // Ensure download limit is counted unless we are streaming a video or audio file + if (!isset($_SERVER['HTTP_RANGE']) || !$isVideoAudio) { $this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD); }