16 lines
562 B
JavaScript
16 lines
562 B
JavaScript
export function addFileWithDedup(state, fileNode) {
|
|
const accept = (node) => {
|
|
if (node.kind === 'file') {
|
|
const key = `${node.path}\u0000${node.file.size}`;
|
|
if (state.fileKeys.has(key)) return null;
|
|
state.fileKeys.add(key);
|
|
return node;
|
|
}
|
|
node.children = node.children.map(accept).filter(Boolean);
|
|
return node.children.length ? node : null;
|
|
};
|
|
const accepted = accept(fileNode);
|
|
if (!accepted || (accepted.kind !== 'file' && !accepted.children.length)) return false;
|
|
state.nodes.push(accepted);
|
|
return true;
|
|
} |