From d06f2cdb08bfa6f05cf7cec2c408a258fa926b09 Mon Sep 17 00:00:00 2001 From: Danshil Kokil Mungur Date: Mon, 14 Mar 2022 15:19:11 +0400 Subject: [PATCH] fix(plex): correctly generate uuid for safari (#2614) --- src/utils/plex.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/utils/plex.ts b/src/utils/plex.ts index b34e9733c..5459a1cbd 100644 --- a/src/utils/plex.ts +++ b/src/utils/plex.ts @@ -20,6 +20,19 @@ export interface PlexPin { code: string; } +const uuidv4 = (): string => { + return ((1e7).toString() + -1e3 + -4e3 + -8e3 + -1e11).replace( + /[018]/g, + function (c) { + return ( + parseInt(c) ^ + (window.crypto.getRandomValues(new Uint8Array(1))[0] & + (15 >> (parseInt(c) / 4))) + ).toString(16); + } + ); +}; + class PlexOAuth { private plexHeaders?: PlexHeaders; @@ -37,11 +50,7 @@ class PlexOAuth { let clientId = localStorage.getItem('overseerrPlexClientId'); if (!clientId) { - const uuid = crypto.randomUUID && crypto.randomUUID(); - if (!uuid) { - throw new Error('Could not generate client ID'); - } - + const uuid = uuidv4(); localStorage.setItem('overseerrPlexClientId', uuid); clientId = uuid; }