fix(web): 内网 http 下写请求与复制邀请链接都会失败
CI / backend (push) Canceled after 0s

crypto.randomUUID() 与 navigator.clipboard 只在安全上下文(https / localhost)里存在,
生产入口是纯 http,于是:

- 所有 POST/PATCH/DELETE 在拼 Idempotency-Key 时直接抛 TypeError,
  登录页只显示"登录失败",GET 一切正常,所以这个坑一直没暴露
- 「复制邀请链接」永远回"浏览器不允许自动复制"

改成幂等键自己拼一个 v4(getRandomValues 不受安全上下文限制,退回 Math.random),
复制走 navigator.clipboard → document.execCommand("copy") 两级降级。

顺带说明:这是生产上"能看不能写"的真正原因,不是权限或接口问题。
This commit is contained in:
Steven
2026-10-31 04:13:13 +08:00
parent 096acb00e7
commit e3f1310cff
4 changed files with 121 additions and 8 deletions
+7 -6
View File
@@ -12,6 +12,7 @@ import {
useToast,
} from "../components/ui";
import { ApiError, api } from "../lib/client";
import { copyText } from "../lib/clipboard";
import type { Invitation, Member, Page, Workspace } from "../lib/types";
const ROLE_LABEL: Record<string, string> = {
@@ -94,14 +95,14 @@ export function WorkspacePage() {
: "";
async function copyLink() {
try {
await navigator.clipboard.writeText(inviteLink);
setCopied(true);
toast("邀请链接已复制", "success");
window.setTimeout(() => setCopied(false), 2000);
} catch {
const ok = await copyText(inviteLink);
if (!ok) {
setError("浏览器不允许自动复制,请手动选中下面这行链接");
return;
}
setCopied(true);
toast("邀请链接已复制", "success");
window.setTimeout(() => setCopied(false), 2000);
}
return (