[Bug] 非 HTTPS 部署下导出「可编辑 PPTX」点击无反应:crypto.randomUUID 仅在安全上下文可用

Author: zgybkjcn-a11yCreated Sep 12, 2026Updated Sep 12, 2026

Deployment Method / 部署方式

Docker Compose (docker-compose.yml)

Issue Description / 问题描述

frontend/src/pages/SlidePreview.tsxhandleExport(main 分支 L1662,v0.9.0-rc.7 同样存在):

typescript
const backendTaskId = type === 'editable-pptx' ? crypto.randomUUID() : undefined;

try {
  ...

crypto.randomUUID() 只在安全上下文(HTTPS / localhost)存在。通过 http://<服务器IP>:<端口> 或未配 TLS 的域名访问自部署实例时它是 undefined,直接调用抛 TypeError: crypto.randomUUID is not a function

关键在于这一行在 try 之前执行,异常进不了 catch,没有任何 toast 报错 —— 用户看到的现象就是「导出 → 可编辑 PPTX 点击后完全没反应」,只有浏览器控制台有 TypeError。

Steps to Reproduce / 复现步骤

  1. Docker Compose 部署,用 http://<IP>:<port> 访问(非 localhost)
  2. 生成项目进入预览页
  3. 导出 → 可编辑 PPTX
  4. 无任何反应;控制台报 TypeError: crypto.randomUUID is not a function

Expected Behavior / 期望行为

非安全上下文下也能正常发起导出。

建议修复

降级到所有上下文都可用的 crypto.getRandomValues 生成 RFC 4122 v4 UUID(已开 PR,见下方链接):

typescript
const generateUuid = (): string => {
  if (typeof crypto.randomUUID === 'function') return crypto.randomUUID();
  const bytes = crypto.getRandomValues(new Uint8Array(16));
  bytes[6] = (bytes[6] & 0x0f) | 0x40;
  bytes[8] = (bytes[8] & 0x3f) | 0x80;
  const hex = Array.from(bytes, b => b.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)}`;
};
const backendTaskId = type === 'editable-pptx' ? generateUuid() : undefined;

Version / 版本

v0.9.0-rc.7 (9277bfc) 与 main (199cf9e) 均存在