feat(project): optimize image imports and converter
- Optimize imported scene preview images (smart WebP/JPEG/PNG, preserve alpha, keep pixel size) - Update converter to re-encode existing image assets with same algorithm - Improve import/export progress overlay and reduce presentation slide stutter Made-with: Cursor
This commit is contained in:
@@ -5,12 +5,18 @@ import yauzl from 'yauzl';
|
||||
|
||||
import type { Project } from '../../shared/types';
|
||||
|
||||
export function unzipToDir(zipPath: string, outDir: string): Promise<void> {
|
||||
export function unzipToDir(
|
||||
zipPath: string,
|
||||
outDir: string,
|
||||
onProgress?: (done: number, total: number) => void,
|
||||
): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
yauzl.open(zipPath, { lazyEntries: true }, (err, zip) => {
|
||||
if (err) return reject(err);
|
||||
const zipFile = zip;
|
||||
let settled = false;
|
||||
const total = zipFile.entryCount || 0;
|
||||
let done = 0;
|
||||
|
||||
const safeClose = (): void => {
|
||||
try {
|
||||
@@ -37,6 +43,14 @@ export function unzipToDir(zipPath: string, outDir: string): Promise<void> {
|
||||
zipFile.readEntry();
|
||||
zipFile.on('entry', (entry: yauzl.Entry) => {
|
||||
if (settled) return;
|
||||
done += 1;
|
||||
if (onProgress && total > 0) {
|
||||
try {
|
||||
onProgress(done, total);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
const filePath = path.join(outDir, entry.fileName);
|
||||
if (entry.fileName.endsWith('/')) {
|
||||
fssync.mkdirSync(filePath, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user