Skip to content

Commit 1cd2f43

Browse files
refactor(zip): 统一压缩生成选项
1 parent 4cb19d4 commit 1cd2f43

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/services/exportService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
*/
44

55
import { db } from '@/db/schema';
6-
import JSZip from 'jszip';
6+
import JSZip, { type JSZipGeneratorOptions } from 'jszip';
77
import { saveAs } from 'file-saver';
88
import { storage, STORAGE_KEYS } from '@/utils/storage';
99
import { importService } from './importService';
1010
import type { ImportOptions, ImportProgressCallback } from '@/types/import';
1111

12+
export const zipGenOptions: JSZipGeneratorOptions<'blob'> = { type: 'blob', compression: 'DEFLATE', compressionOptions: { level: 5 } };
13+
1214
export class ExportService {
1315
/**
1416
* 导出单个项目为 JSON
@@ -126,7 +128,7 @@ export class ExportService {
126128
)
127129
);
128130

129-
const blob = await zip.generateAsync({ type: 'blob' });
131+
const blob = await zip.generateAsync(zipGenOptions);
130132
saveAs(blob, `prompt-studio-backup-${Date.now()}.zip`);
131133
}
132134

src/services/webdavService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { importService } from './importService';
1010
import { ImportOptions, ImportProgressCallback } from '@/types/import';
1111
import { useI18nStore } from '@/store/i18nStore';
1212
import { translations } from '@/i18n/locales';
13+
import { zipGenOptions } from './exportService';
1314

1415
export interface WebDAVConfig {
1516
url: string;
@@ -145,7 +146,7 @@ export class WebDAVService {
145146
);
146147

147148
// 2. 生成 ZIP
148-
const blob = await zip.generateAsync({ type: 'blob' });
149+
const blob = await zip.generateAsync(zipGenOptions);
149150

150151
// 3. 上传到 WebDAV
151152
const filename = `prompt-studio-backup-${Date.now()}.zip`;

0 commit comments

Comments
 (0)