From 6ea9abab81203d4e47927b6e7197b8953c9b8a51 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Sun, 23 Nov 2025 09:23:37 +0100 Subject: [PATCH] feat: Filter category tree based on `ROOT_CATEGORY_ID` for display while keeping the full tree for image sync, and summarize image deletion logs. --- .env.example | 2 +- category-syncer.js | 10 ++++++---- picture-syncer.js | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 6b9d15c..27de352 100644 --- a/.env.example +++ b/.env.example @@ -4,7 +4,7 @@ DB_PASSWORD= DB_DATABASE=eazybusiness REDIS_PREFIX=shop_api_ CACHE_LOCATION=./cache -ROOT_CATEGORY_ID=209 +ROOT_CATEGORY_ID=0 JTL_SHOP_ID=0 JTL_SPRACHE_ID=1 JTL_PLATTFORM_ID=1 \ No newline at end of file diff --git a/category-syncer.js b/category-syncer.js index 79892a3..8bb7e8f 100644 --- a/category-syncer.js +++ b/category-syncer.js @@ -97,9 +97,11 @@ class CategorySyncer extends EventEmitter { const articleCounts = articleCountsResult.recordset; const images = imagesResult.recordset; - let tree = this._buildTree(categories, names, articleCounts, images); + // Build tree with ROOT_CATEGORY_ID filter (if set) + // This gives us the subtree we're interested in + let tree = this._buildTree(categories, names, articleCounts, images, true); - // Keep unpruned tree for image sync + // Keep unpruned tree for image sync (same subtree, but not pruned) const unprunedTree = tree; // Ensure directory exists @@ -137,7 +139,7 @@ class CategorySyncer extends EventEmitter { } } - _buildTree(categories, names, articleCounts, images) { + _buildTree(categories, names, articleCounts, images, applyRootFilter = true) { // Create a map for quick lookup of names const nameMap = new Map(); names.forEach(n => nameMap.set(n.kKategorie, n.cName)); @@ -186,7 +188,7 @@ class CategorySyncer extends EventEmitter { const rootId = process.env.ROOT_CATEGORY_ID ? parseInt(process.env.ROOT_CATEGORY_ID) : null; let resultNodes = rootNodes; - if (rootId) { + if (rootId && applyRootFilter) { const specificRoot = categoryMap.get(rootId); // Return the children of the specified root, not the root itself resultNodes = specificRoot ? specificRoot.children : []; diff --git a/picture-syncer.js b/picture-syncer.js index 34ec162..1b75110 100644 --- a/picture-syncer.js +++ b/picture-syncer.js @@ -38,7 +38,9 @@ class PictureSyncer { for (const id of toDelete) { const filePath = path.join(groupDir, `${id}.jpg`); await fs.unlink(filePath); - console.log(`🗑️ Deleted obsolete image: ${filePath}`); + } + if (toDelete.length > 0) { + console.log(`🗑️ Deleted ${toDelete.length} obsolete images.`); } // 2. Download missing images