From 874258dae943a8216bb8b589140969811d3e4f38 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 2 Dec 2022 21:53:30 -0800 Subject: [PATCH] livephoto: allow access for folder shares --- lib/Controller/VideoController.php | 16 +++++----------- src/services/FileUtils.ts | 17 ++++++++++------- src/services/Utils.ts | 24 +++++++++++++++++++----- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/lib/Controller/VideoController.php b/lib/Controller/VideoController.php index 941b5914..854e4faf 100644 --- a/lib/Controller/VideoController.php +++ b/lib/Controller/VideoController.php @@ -95,28 +95,22 @@ class VideoController extends ApiBase /** * @NoAdminRequired * + * @PublicPage + * * @NoCSRFRequired * * Return the live video part of a live photo */ public function livephoto( - string $fileid, - string $etag = '', + int $fileid, string $liveid = '', string $format = '', string $transcode = '' ) { - $fileid = (int) $fileid; - $files = $this->rootFolder->getById($fileid); - if (0 === \count($files)) { + $file = $this->getUserFile($fileid); + if (null === $file) { return new JSONResponse(['message' => 'File not found'], Http::STATUS_NOT_FOUND); } - $file = $files[0]; - - // Check file etag - if ($etag !== $file->getEtag()) { - return new JSONResponse(['message' => 'File changed'], Http::STATUS_PRECONDITION_FAILED); - } // Check file liveid if (!$liveid) { diff --git a/src/services/FileUtils.ts b/src/services/FileUtils.ts index 8f086fc4..de4ab203 100644 --- a/src/services/FileUtils.ts +++ b/src/services/FileUtils.ts @@ -141,20 +141,23 @@ const getPreviewUrl = function ( size: number | [number, number] ) { const [x, y] = typeof size === "number" ? [size, size] : size; - const a = square ? "0" : "1"; // Get base URL - let url = generateUrl( - `/apps/memories/api/image/preview/${photo.fileid}?c=${photo.etag}&x=${x}&y=${y}&a=${a}` - ); + const url = generateUrl(`/apps/memories/api/image/preview/${photo.fileid}`); + + // Build query + const query = new URLSearchParams(); + query.set("c", photo.etag); + query.set("x", x.toString()); + query.set("y", y.toString()); + query.set("a", square ? "0" : "1"); // Public preview if (vuerouter.currentRoute.name === "folder-share") { - const token = vuerouter.currentRoute.params.token; - url += `&folder_share=${token}`; + query.set("folder_share", vuerouter.currentRoute.params.token); } - return url; + return url + "?" + query.toString(); }; export { diff --git a/src/services/Utils.ts b/src/services/Utils.ts index 6420edf2..51c2b694 100644 --- a/src/services/Utils.ts +++ b/src/services/Utils.ts @@ -241,11 +241,25 @@ export function getFolderRoutePath(basePath: string) { * Get URL to live photo video part */ export function getLivePhotoVideoUrl(p: IPhoto, transcode: boolean) { - let url = generateUrl( - `/apps/memories/api/video/livephoto/${p.fileid}?etag=${p.etag}&liveid=${p.liveid}` - ); - if (transcode) url += `&transcode=${videoClientIdPersistent}`; - return url; + // Get base url + const url = generateUrl(`/apps/memories/api/video/livephoto/${p.fileid}`); + + // Build query string + const query = new URLSearchParams(); + query.set("etag", p.etag); + query.set("liveid", p.liveid); + + // Transcode if allowed + if (transcode) { + query.set("transcode", videoClientIdPersistent); + } + + // Add auth token for public share + if (vuerouter.currentRoute.name === "folder-share") { + query.set("folder_share", vuerouter.currentRoute.params.token); + } + + return url + "?" + query.toString(); } /**