Skip to content

Commit a24d0d5

Browse files
fix: Fixed preview for archive files in sub-paths
Fixes: #9
1 parent deb6e0b commit a24d0d5

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/main/api/file-info-api.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { StoreSchema, MainIpcGetter, previewTypes } from '../../shared/constants
99
import {
1010
audioMediaFormatsMatch,
1111
decompressBase64ToString,
12+
ensureForwardPath,
1213
FilePath,
1314
getZipParentFs,
1415
} from '../util';
@@ -73,7 +74,8 @@ export default function InitializeFileInfoApi(
7374
Math.min(zipPath.path.length + 1, filePath.path.length),
7475
);
7576

76-
const zipEntry = await zip.entry(localPath);
77+
// Only works with forward slashes.
78+
const zipEntry = await zip.entry(ensureForwardPath(localPath));
7779

7880
if (!zipEntry) {
7981
throw new Error(`No Compressed File at ${zipPath} with local path ${localPath}`);
@@ -94,7 +96,7 @@ export default function InitializeFileInfoApi(
9496

9597
info.previewPath = zipPath.path;
9698

97-
info.bundlePath = (await findBundlePath(filePath))?.path;
99+
info.bundlePath = (await findBundlePath(zipPath))?.path;
98100
} else if (await isArchive(filePath)) {
99101
// this is the zip bundle file itself
100102
const stat = await lstat(filePath.absolute);

src/main/api/file-system-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import {
2222
FilePath,
2323
TypedEventEmitter,
24+
ensureForwardPath,
2425
foreachAsync,
2526
getProjectDir,
2627
getZipParentFs,
@@ -609,7 +610,7 @@ async function getFileFromPath(filePath: FilePath) {
609610
if (zipPath) {
610611
const zipStats = await pathStat(zipPath);
611612
const entries = await getZipEntries(zipPath);
612-
const entryLocalPath = filePath.path.substring(zipPath.path.length + 1);
613+
const entryLocalPath = ensureForwardPath(filePath.path.substring(zipPath.path.length + 1));
613614
return getFileNodeFromZipEntry(zipPath, zipStats, entryLocalPath, entries[entryLocalPath]);
614615
}
615616

src/main/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,7 @@ export async function getZipParentFs(p: FilePath): Promise<FilePath | undefined>
299299

300300
return undefined;
301301
}
302+
303+
export function ensureForwardPath(value: string) {
304+
return value.replaceAll('\\', '/');
305+
}

0 commit comments

Comments
 (0)