Skip to content

Commit 3da0a22

Browse files
committed
fix: update file paths for assets and improve error handling in canvasFactory
1 parent 55eb4c0 commit 3da0a22

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

shared/features/thumbnail/canvasFactory.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,23 @@ if (typeof document === 'undefined') {
3636
} = canvasModule;
3737

3838
const getPath = (filename: string) => {
39-
return (
40-
'file://' +
41-
path.join(
42-
__dirname,
43-
'..',
44-
'..',
45-
'..',
46-
'web',
47-
filename.split('/').join(path.sep),
48-
)
49-
);
39+
const workingDir = process.cwd();
40+
const fullPath = path.join(workingDir, filename.split('/').join(path.sep));
41+
42+
if (!Bun.file(fullPath).exists()) {
43+
throw new Error(`File not found: ${fullPath}`);
44+
} else {
45+
console.log(`File found: ${fullPath}`);
46+
}
47+
48+
return 'file://' + fullPath;
5049
};
5150

5251
const saveToImage = (canvas: NapiRs.Canvas) => canvas.encode('png');
5352

5453
const useFont = () => {
5554
GlobalFonts.registerFromPath(
56-
'file:' + getPath('/fonts/Lato-Regular.ttf').toString(),
55+
'file:' + getPath('assets/fonts/Lato-Regular.ttf').toString(),
5756
'Lato',
5857
);
5958
};
@@ -62,7 +61,7 @@ if (typeof document === 'undefined') {
6261

6362
try {
6463
noteBlockImage = nodeLoadImage(
65-
new URL(getPath('public/img/note-block-grayscale.png')),
64+
new URL(getPath('assets/img/note-block-grayscale.png')),
6665
);
6766
} catch (error) {
6867
console.error('Error loading image: ', error);

0 commit comments

Comments
 (0)