Skip to content

Commit 05a43d0

Browse files
committed
fix thumbanil asset not found Ci think)
1 parent eb0b2fd commit 05a43d0

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

packages/preload/src/modules/fs.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export async function readFile(path: string) {
1212
return fs.readFile(path);
1313
}
1414

15-
export async function writeFile(_path: string, content: WriteFileData, options?: WriteFileOptions) {
16-
await fs.mkdir(path.dirname(_path), { recursive: true });
17-
await fs.writeFile(_path, content, options);
15+
export async function writeFile(scenePath: string, content: WriteFileData, options?: WriteFileOptions) {
16+
await fs.mkdir(path.dirname(scenePath), { recursive: true });
17+
await fs.writeFile(scenePath, content, options);
1818
}
1919

2020
export async function exists(path: string) {

packages/preload/src/modules/scene.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export async function writeScene({ path: _path, scene }: { path: string; scene:
3232
await writeFile(getScenePath(_path), JSON.stringify(scene, null, 2), { encoding: 'utf8' });
3333
}
3434

35+
export function pathToPosix(value: string): string {
36+
return value.replace(/\\/g, '/');
37+
}
38+
39+
3540
/**
3641
* Updates the scene metadata to reference the new thumbnail path.
3742
*
@@ -46,7 +51,7 @@ export async function updateSceneThumbnail(path: string, thumbnailPath: string):
4651
...scene,
4752
display: {
4853
...scene.display,
49-
navmapThumbnail: thumbnailPath,
54+
navmapThumbnail: pathToPosix(thumbnailPath),
5055
},
5156
},
5257
});

packages/preload/src/modules/workspace.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,23 @@ export async function reimportProject(_path: string): Promise<Project | undefine
361361
* @returns {Promise<void>} A promise that resolves if everything went ok.
362362
*/
363363
export async function saveThumbnail({
364-
path: _path,
365-
thumbnail,
364+
path: scenePath,
365+
thumbnail: thumbnailContent,
366366
}: {
367367
path: string;
368368
thumbnail: string;
369369
}): Promise<void> {
370-
const scene = await getScene(_path);
370+
const scene = await getScene(scenePath);
371371
const thumbnailPath = getProjectThumbnailPath();
372+
await deepWriteFile(path.join(scenePath, thumbnailPath), thumbnailContent, { encoding: 'base64' });
373+
374+
// Check if the current thumbnail file exists
375+
// If the current thumbnail doesn't exist, update the scene.json to point to the new thumbnail
372376
const currentThumb = scene.display?.navmapThumbnail;
373-
await deepWriteFile(path.join(_path, thumbnailPath), thumbnail, { encoding: 'base64' });
374-
const currentThumbPath = path.join(_path, path.normalize(currentThumb || ''));
375-
if (!(await exists(currentThumbPath))) await updateSceneThumbnail(_path, thumbnailPath);
377+
const currentThumbPath = path.join(scenePath, path.normalize(currentThumb || ''));
378+
if (!(await exists(currentThumbPath))) {
379+
await updateSceneThumbnail(scenePath, thumbnailPath);
380+
}
376381
}
377382

378383
export async function openFolder(_path: string) {

0 commit comments

Comments
 (0)