From 25cc5bb2812af71d2aa1156c9d5037e2e9b07e63 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 29 Nov 2022 14:36:14 -0800 Subject: [PATCH] Use persistent client id for live photo --- src/main.ts | 18 ++++++++++++++---- src/services/Utils.ts | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 66b1ff08..fc1c85b3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,6 +29,7 @@ declare global { var vidjs: typeof import("video.js").default; var Plyr: typeof import("plyr"); var videoClientId: string; + var videoClientIdPersistent: string; } // Allow global access to the router @@ -49,10 +50,19 @@ __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"); +const getClientId = () => + Math.random().toString(36).substring(2, 15).padEnd(12, "0"); +globalThis.videoClientId = getClientId(); +globalThis.videoClientIdPersistent = localStorage.getItem( + "videoClientIdPersistent" +); +if (!globalThis.videoClientIdPersistent) { + globalThis.videoClientIdPersistent = getClientId(); + localStorage.setItem( + "videoClientIdPersistent", + globalThis.videoClientIdPersistent + ); +} Vue.use(VueVirtualScroller); diff --git a/src/services/Utils.ts b/src/services/Utils.ts index 0354d66f..6420edf2 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=${videoClientId}`; + if (transcode) url += `&transcode=${videoClientIdPersistent}`; return url; }