From 533a05832eefbb0755af8b4742a543db7f091474 Mon Sep 17 00:00:00 2001 From: "jif2.zhang" Date: Mon, 26 Oct 2026 01:52:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(0.2.1):=20crypto.randomUUID=20=E4=BB=85?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E4=B8=8A=E4=B8=8B=E6=96=87=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=20=E2=80=94=E2=80=94=20http=20=E6=98=8E=E6=96=87=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E4=B8=8B=E7=94=A8=20getRandomValues=20=E5=85=9C?= =?UTF-8?q?=E5=BA=95=E7=94=9F=E6=88=90=20uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/task.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/api/task.js b/src/api/task.js index 9cd736d..df37b47 100644 --- a/src/api/task.js +++ b/src/api/task.js @@ -9,7 +9,15 @@ import { filterVisible } from '../pages/task/date.js' const db = () => getPowersyncDb() -const uuid = () => crypto.randomUUID() +// crypto.randomUUID 仅在安全上下文 (https / localhost) 可用; 部署站为 http 明文, 用 getRandomValues 兜底生成 v4 +const uuid = () => { + if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') return crypto.randomUUID() + const b = crypto.getRandomValues(new Uint8Array(16)) + b[6] = (b[6] & 0x0f) | 0x40 + b[8] = (b[8] & 0x3f) | 0x80 + const h = [...b].map((x) => x.toString(16).padStart(2, '0')).join('') + return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}` +} const now = () => new Date().toISOString() const parseJson = (v, fallback) => { if (v === null || v === undefined || v === '') return fallback