feat(chat): 完善附件预览与订单提取交互
- 优化聊天附件上传、预览及 PDF.js 加载 - 完善订单文档画布与审核预览体验 - 优化订单提取运行状态及发送流程 - 增强会话附件接口与相关测试覆盖 - 更新 Nginx 配置、技术文档及四语言文案
This commit is contained in:
1 parent
104afa3844
commit
9d2fa522fa
29 files changed
+584
-140
No files matched your search
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* shared/utils/pdfjs.ts
|
||||
* 用途:统一加载 pdfjs-dist,并以正确 MIME 启动 module Worker。
|
||||
* 依赖:pdfjs-dist、Vite `?url` 产物。
|
||||
* 逻辑:nginx 曾把 .mjs 以 application/octet-stream + immutable 长期缓存;
|
||||
* Chrome 对 module Worker 硬性校验 MIME,硬刷新也常仍命中错误缓存。
|
||||
* 因此用 cache:'reload' 拉最新字节,再以 text/javascript Blob 建 Worker,
|
||||
* 通过 GlobalWorkerOptions.workerPort 交给 pdf.js 5(始终 type:'module')。
|
||||
*/
|
||||
type PdfJsModule = typeof import('pdfjs-dist');
|
||||
|
||||
let pdfjsLoader: Promise<PdfJsModule> | null = null;
|
||||
|
||||
/**
|
||||
* 动态加载 PDF.js,并保证 Worker 以 JavaScript MIME 启动。
|
||||
*/
|
||||
export async function loadPdfJs(): Promise<PdfJsModule> {
|
||||
if (!pdfjsLoader) {
|
||||
pdfjsLoader = (async () => {
|
||||
const [pdfjs, workerMod] = await Promise.all([
|
||||
import('pdfjs-dist'),
|
||||
import('pdfjs-dist/build/pdf.worker.min.mjs?url'),
|
||||
]);
|
||||
const workerUrl = String(workerMod.default || '');
|
||||
if (!workerUrl) {
|
||||
throw new Error('PDF.js worker URL is unavailable');
|
||||
}
|
||||
const response = await fetch(workerUrl, { cache: 'reload' });
|
||||
if (!response.ok) {
|
||||
throw new Error(`PDF worker HTTP ${response.status}`);
|
||||
}
|
||||
const source = await response.text();
|
||||
const blobUrl = URL.createObjectURL(new Blob([source], { type: 'text/javascript' }));
|
||||
const worker = new Worker(blobUrl, { type: 'module' });
|
||||
pdfjs.GlobalWorkerOptions.workerPort = worker;
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = workerUrl;
|
||||
return pdfjs;
|
||||
})();
|
||||
}
|
||||
return pdfjsLoader;
|
||||
}
|
||||
|
||||
/** 测试用:重置单例。 */
|
||||
export function resetPdfJsLoaderForTests(): void {
|
||||
pdfjsLoader = null;
|
||||
}
|
||||
Reference in new issue
Block a user