download: limit only videos

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/653/head
Varun Patil 2023-04-24 12:24:25 -07:00
parent 0abdb57f28
commit 0a79f30861
2 changed files with 6 additions and 24 deletions

View File

@ -124,9 +124,9 @@ class DownloadController extends GenericApiController
*
* @PublicPage
*/
public function one(int $fileid, bool $resumable = true, int $numChunks = 0): Http\Response
public function one(int $fileid, bool $resumable = true): Http\Response
{
return Util::guardExDirect(function (Http\IOutput $out) use ($fileid, $resumable, $numChunks) {
return Util::guardExDirect(function (Http\IOutput $out) use ($fileid, $resumable) {
$file = $this->fs->getUserFile($fileid);
// check if http_range is sent by browser
@ -150,26 +150,9 @@ class DownloadController extends GenericApiController
$seekEnd = (empty($seekEnd)) ? ($size - 1) : min(abs((int) $seekEnd), $size - 1);
$seekStart = (empty($seekStart) || $seekEnd < abs((int) $seekStart)) ? 0 : max(abs((int) $seekStart), 0);
// If the client knows about ranges, only send a maximum of X KB
// This way we don't read the whole file for no reason
if (!empty($range)) {
// Default to 64MB
$maxLen = 64 * 1024 * 1024;
// For videos, use a max of 8MB
if ('video' === $this->request->getHeader('Sec-Fetch-Dest')) {
$maxLen = 8 * 1024 * 1024;
}
// Check if the client sent a hint for the chunk size
if ($numChunks) {
$maxLen = min(ceil($size / $numChunks), $maxLen * 3);
}
// No less than 1MB; this is just wasteful
$maxLen = max($maxLen, 1024 * 1024);
$seekEnd = min($seekEnd, $seekStart + $maxLen);
// For videos, use a max of 64MB
if (!empty($range) && 'video' === $this->request->getHeader('Sec-Fetch-Dest')) {
$seekEnd = min($seekEnd, $seekStart + 64 * 1024 * 1024);
}
// Only send partial content header if downloading a piece of the file

View File

@ -110,9 +110,8 @@ class VideoContentSetup {
}
getDirectSrc(content: VideoContent) {
const numChunks = Math.ceil((content.data.photo?.video_duration || 0) / 3) || undefined;
return {
src: API.Q(content.data.src, { numChunks }),
src: content.data.src,
type: 'video/mp4', // chrome refuses to play video/quicktime, so fool it
};
}