fix: 用 data URL 下载,和原插件方式一致
This commit is contained in:
+10
-11
@@ -104,23 +104,22 @@ async function exportPptx() {
|
||||
// 4. 生成 PPTX
|
||||
setProgress(90, '正在打包...');
|
||||
const blob = await WebToPPT.schemaToPptxBlob(schema);
|
||||
console.log('[WebToPPT] blob size:', blob.size, 'type:', blob.type);
|
||||
|
||||
// 5. 下载
|
||||
// 5. 下载(用 data URL,和原插件一致)
|
||||
setProgress(95, '正在下载...');
|
||||
const url = URL.createObjectURL(blob);
|
||||
const buffer = await blob.arrayBuffer();
|
||||
const bytes = new Uint8Array(buffer);
|
||||
let binary = '';
|
||||
for (let i = 0; i < bytes.length; i += 0x8000) {
|
||||
binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
||||
}
|
||||
const dataUrl = 'data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64,' + btoa(binary);
|
||||
|
||||
const title = jsonData.source?.title || 'webpage';
|
||||
const safeTitle = title.replace(/[\\/:*?"<>|]+/g, '-').replace(/\s+/g, '-').slice(0, 64) || 'webpage';
|
||||
const filename = `web-to-ppt/${safeTitle}-${Date.now()}.pptx`;
|
||||
|
||||
try {
|
||||
const dlId = await chrome.downloads.download({ url, filename });
|
||||
console.log('[WebToPPT] download started, id:', dlId);
|
||||
} catch (dlErr) {
|
||||
console.error('[WebToPPT] download failed:', dlErr);
|
||||
throw dlErr;
|
||||
}
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
||||
await chrome.downloads.download({ url: dataUrl, filename });
|
||||
|
||||
setProgress(100, `已导出:${filename}`);
|
||||
setResult('success', '导出完成');
|
||||
|
||||
Reference in New Issue
Block a user