Fix an error that preventing to save image files using filenames that include query parameters (for example, "image-2.png?w=671" or "image-3.png?w=1024"). Windows doesn’t allow characters like “?” in filenames, so when the tool tries to open or save such a file, it fails with an ENOENT error.

This commit is contained in:
kamran bigdely
2025-04-05 23:41:21 -07:00
parent 2f62d9c8d7
commit 7899dd944d
+8
View File
@@ -73,6 +73,14 @@ export function buildPostPath(post, overrideConfig) {
export function getFilenameFromUrl(url) {
let filename = url.split('/').slice(-1)[0];
// Remove query parameters and hash fragments from filename
filename = filename.split('?')[0].split('#')[0];
// Replace any other invalid Windows filename characters
const invalidChars = /[<>:"\/\\|?*]/g;
filename = filename.replace(invalidChars, '_');
try {
filename = decodeURIComponent(filename)
} catch (ex) {