fix(*): 客户端标识 - 兼容 HTTP 内网访问并修复创造页卡死

Fixes #86
This commit is contained in:
ddCat
2026-08-03 15:06:09 +08:00
parent 72420895b2
commit d3b044e009
9 changed files with 35 additions and 9 deletions

View File

@@ -2,6 +2,8 @@ import { convertToExcalidrawElements } from "@excalidraw/excalidraw";
import type { FileId } from "@excalidraw/excalidraw/element/types";
import type { BinaryFileData, BinaryFiles, DataURL } from "@excalidraw/excalidraw/types";
import { createClientId } from "@/lib/client-id";
const INITIAL_DRAWING_SHAPE_MAX_DIMENSION = 1200;
type DrawingImageSource = {
@@ -14,7 +16,7 @@ type DrawingImageSource = {
export function createExcalidrawDrawingFromImage(source: DrawingImageSource) {
const now = Date.now();
const fileId = crypto.randomUUID() as FileId;
const fileId = createClientId() as FileId;
const scale = Math.min(1, INITIAL_DRAWING_SHAPE_MAX_DIMENSION / Math.max(source.width, source.height));
const width = Math.max(1, Math.round(source.width * scale));
const height = Math.max(1, Math.round(source.height * scale));

6
web/src/lib/client-id.ts Normal file
View File

@@ -0,0 +1,6 @@
import { nanoid } from "nanoid";
export function createClientId() {
// randomUUID 在 HTTP 内网地址下不可用;nanoid 依赖仍可用的 getRandomValues。
return nanoid();
}