feat: Filter category tree based on ROOT_CATEGORY_ID for display while keeping the full tree for image sync, and summarize image deletion logs.
This commit is contained in:
@@ -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
|
||||
@@ -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 : [];
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user