调整部分前端布局和后端增删改逻辑
This commit is contained in:
@@ -12,6 +12,17 @@ export function isDuplicateScan(value, lastValue, scannedAt, lastScannedAt, dupl
|
||||
return value === lastValue && elapsed >= 0 && elapsed <= duplicateWindowMs
|
||||
}
|
||||
|
||||
export function createIdempotencyKey() {
|
||||
return globalThis.crypto.randomUUID()
|
||||
export function createIdempotencyKey(cryptoProvider = globalThis.crypto) {
|
||||
if (typeof cryptoProvider?.randomUUID === 'function') {
|
||||
return cryptoProvider.randomUUID()
|
||||
}
|
||||
if (typeof cryptoProvider?.getRandomValues !== 'function') {
|
||||
throw new Error('当前浏览器不支持安全随机数,请使用 HTTPS 或 localhost 访问系统')
|
||||
}
|
||||
|
||||
const bytes = cryptoProvider.getRandomValues(new Uint8Array(16))
|
||||
bytes[6] = (bytes[6] & 0x0f) | 0x40
|
||||
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
||||
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')
|
||||
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user