From 5550551e8ac7002faa1737f437d63d8c9f7c04da Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 29 Nov 2022 14:09:48 -0800 Subject: [PATCH] Use client id for live photo transcodes --- lib/Controller/VideoController.php | 4 ++-- src/components/PsVideo.ts | 6 +----- src/main.ts | 14 ++++++++++++-- src/services/Utils.ts | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/Controller/VideoController.php b/lib/Controller/VideoController.php index fd666eb4..dc31d56b 100644 --- a/lib/Controller/VideoController.php +++ b/lib/Controller/VideoController.php @@ -217,11 +217,11 @@ class VideoController extends ApiBase $blob = $liveFile->getContent(); $mime = $liveFile->getMimeType(); - if ($this->request->getParam('transcode') && !$this->config->getSystemValue('memories.no_transcode', true)) { + if (($id = $this->request->getParam('transcode')) && !$this->config->getSystemValue('memories.no_transcode', true)) { // Only Apple uses HEVC for now, so pass this to the transcoder // If this is H.264 it won't get transcoded anyway $liveVideoPath = $liveFile->getStorage()->getLocalFile($liveFile->getInternalPath()); - if ($this->getUpstream('livephoto', $liveVideoPath, 'max.mp4')) { + if ($this->getUpstream($id, $liveVideoPath, 'max.mp4')) { exit; } } diff --git a/src/components/PsVideo.ts b/src/components/PsVideo.ts index 6ce45c76..7a65d99d 100644 --- a/src/components/PsVideo.ts +++ b/src/components/PsVideo.ts @@ -12,10 +12,6 @@ const config_noTranscode = loadState( "UNSET" ) as boolean | string; -// Generate client id for this instance -// Does not need to be cryptographically secure -const clientId = Math.random().toString(36).substring(2, 15).padEnd(12, "0"); - /** * Check if slide has video content * @@ -153,7 +149,7 @@ class VideoContentSetup { // Create hls sources if enabled let sources: any[] = []; const baseUrl = generateUrl( - `/apps/memories/api/video/transcode/${clientId}/${fileid}` + `/apps/memories/api/video/transcode/${videoClientId}/${fileid}` ); if (!config_noTranscode) { diff --git a/src/main.ts b/src/main.ts index 75e2cb5e..66b1ff08 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,15 +28,16 @@ declare global { var vidjs: typeof import("video.js").default; var Plyr: typeof import("plyr"); + var videoClientId: string; } +// Allow global access to the router globalThis.vuerouter = router; +// Cache these for better performance globalThis.windowInnerWidth = window.innerWidth; globalThis.windowInnerHeight = window.innerHeight; -Vue.use(VueVirtualScroller); - // CSP config for webpack dynamic chunk loading __webpack_nonce__ = window.btoa(getRequestToken()); @@ -46,6 +47,15 @@ __webpack_nonce__ = window.btoa(getRequestToken()); // We do not want the index.php since we're loading files __webpack_public_path__ = generateFilePath("memories", "", "js/"); +// Generate client id for this instance +// Does not need to be cryptographically secure +globalThis.videoClientId = Math.random() + .toString(36) + .substring(2, 15) + .padEnd(12, "0"); + +Vue.use(VueVirtualScroller); + // https://github.com/nextcloud/photos/blob/156f280c0476c483cb9ce81769ccb0c1c6500a4e/src/main.js // TODO: remove when we have a proper fileinfo standalone library // original scripts are loaded from diff --git a/src/services/Utils.ts b/src/services/Utils.ts index c5fb4798..0354d66f 100644 --- a/src/services/Utils.ts +++ b/src/services/Utils.ts @@ -244,7 +244,7 @@ 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=1"; + if (transcode) url += `&transcode=${videoClientId}`; return url; }