fix: add generateUUID fallback for crypto.randomUUID in PackGeneratorService and document the solution.
This commit is contained in:
@@ -63,7 +63,7 @@ export class PackGeneratorService {
|
||||
}
|
||||
|
||||
const cardObj: DraftCard = {
|
||||
id: crypto.randomUUID(),
|
||||
id: this.generateUUID(),
|
||||
scryfallId: cardData.id,
|
||||
name: cardData.name,
|
||||
rarity: rarity,
|
||||
@@ -298,4 +298,15 @@ export class PackGeneratorService {
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
private generateUUID(): string {
|
||||
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
// Fallback for insecure contexts or older browsers
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user