Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(files_sharing): fallback self.crypto.randomUUID
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv committed Jun 21, 2025
commit edb52be36e516f918b78e20f97e38e776133785f
25 changes: 23 additions & 2 deletions lib/guest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class GuestUser implements NextcloudUser {

constructor() {
if (!browserStorage.getItem('guestUid')) {
browserStorage.setItem('guestUid', self.crypto.randomUUID())
browserStorage.setItem('guestUid', randomUUID())
}

this._displayName = browserStorage.getItem('guestNickname') || ''
this.uid = browserStorage.getItem('guestUid') || self.crypto.randomUUID()
this.uid = browserStorage.getItem('guestUid') || randomUUID()
this.isAdmin = false

subscribe('user:info:changed', (guest) => {
Expand Down Expand Up @@ -73,3 +73,24 @@ export function setGuestNickname(nickname: string): void {

getGuestUser().displayName = nickname
}

/**
* Generate a random UUID (version 4) if the crypto API is not available.
* If the crypto API is available, it uses the less secure `randomUUID` method.
* Crypto API is available in modern browsers on secure contexts (HTTPS).
*
* @return {string} A random UUID.
*/
function randomUUID(): string {
// Use the crypto API if available
if (self?.crypto?.randomUUID) {
return self.crypto.randomUUID()
}

// Generate a random UUID (version 4)
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0
const v = c === 'x' ? r : (r & 0x3 | 0x8)
return v.toString(16)
})
}