mirror of
https://github.com/imputnet/cobalt.git
synced 2026-02-04 04:56:43 +00:00
web: add uuid() function with fallback if randomUUID is missing
This commit is contained in:
@@ -26,3 +26,20 @@ export const ffmpegMetadataArgs = (metadata: CobaltFileMetadata) =>
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
const digit = () => '0123456789abcdef'[Math.random() * 16 | 0];
|
||||
export const uuid = () => {
|
||||
if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
|
||||
const digits = Array.from({length: 32}, digit);
|
||||
digits[12] = '4';
|
||||
digits[16] = '89ab'[Math.random() * 4 | 0];
|
||||
|
||||
return digits
|
||||
.join('')
|
||||
.match(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/)!
|
||||
.slice(1)
|
||||
.join('-');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user