1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-10-06 09:37:36 +03:00

fix: Ensure parent directory exists before copying over the icons to generated static directory (#4865)

fix: Ensure parent directory exists before copying over the icon to generated static directory.

This fixes the issue of icons not showing up for custom nodes that use a package-name with a `/` in them.
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2022-12-12 16:41:18 +01:00 committed by GitHub
parent 61aafc9873
commit 91e9a88e3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -323,25 +323,21 @@ export class LoadNodesAndCredentialsClass implements INodesAndCredentials {
this.types.credentials = this.types.credentials.concat(types.credentials);
// Copy over all icons and set `iconUrl` for the frontend
const iconPromises: Array<Promise<void>> = [];
for (const node of types.nodes) {
if (node.icon?.startsWith('file:')) {
const icon = node.icon.substring(5);
const iconUrl = `icons/nodes/${node.name}${path.extname(icon)}`;
delete node.icon;
node.iconUrl = iconUrl;
iconPromises.push(copyFile(path.join(dir, icon), path.join(GENERATED_STATIC_DIR, iconUrl)));
}
}
for (const credential of types.credentials) {
if (credential.icon?.startsWith('file:')) {
const icon = credential.icon.substring(5);
const iconUrl = `icons/credentials/${credential.name}${path.extname(icon)}`;
delete credential.icon;
credential.iconUrl = iconUrl;
iconPromises.push(copyFile(path.join(dir, icon), path.join(GENERATED_STATIC_DIR, iconUrl)));
}
}
const iconPromises = Object.entries(types).flatMap(([typeName, typesArr]) =>
typesArr.map((type) => {
if (!type.icon?.startsWith('file:')) return;
const icon = type.icon.substring(5);
const iconUrl = `icons/${typeName}/${type.name}${path.extname(icon)}`;
delete type.icon;
type.iconUrl = iconUrl;
const source = path.join(dir, icon);
const destination = path.join(GENERATED_STATIC_DIR, iconUrl);
return mkdir(path.dirname(destination), { recursive: true }).then(async () =>
copyFile(source, destination),
);
}),
);
await Promise.all(iconPromises);
// Nodes and credentials that have been loaded immediately