fix: add generateUUID fallback for crypto.randomUUID in PackGeneratorService and document the solution.

This commit is contained in:
2025-12-14 21:45:38 +01:00
parent da643b787f
commit 0a8f78df3a
3 changed files with 28 additions and 1 deletions

View File

@@ -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);
});
}
}