Skip to content

Commit

Permalink
fix(plex): correctly generate uuid for safari (#2614)
Browse files Browse the repository at this point in the history
  • Loading branch information
danshilm committed Mar 14, 2022
1 parent 086f0b6 commit d06f2cd
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/utils/plex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down

0 comments on commit d06f2cd

Please sign in to comment.