genesis
This commit is contained in:
46
index.js
Normal file
46
index.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import categorySyncer from './category-syncer.js';
|
||||
import pictureSyncer from './picture-syncer.js';
|
||||
|
||||
categorySyncer.on('synced', async ({ tree, unprunedTree, changed }) => {
|
||||
if (changed) {
|
||||
console.log('🎉 Event received: Category tree updated! Root nodes:', tree.length);
|
||||
} else {
|
||||
console.log('🎉 Event received: Sync finished (no changes). Checking images...');
|
||||
}
|
||||
|
||||
// Extract all kBild IDs from unpruned tree (includes all categories)
|
||||
const imageIds = [];
|
||||
const traverse = (nodes) => {
|
||||
for (const node of nodes) {
|
||||
if (node.kBild) {
|
||||
imageIds.push(node.kBild);
|
||||
}
|
||||
if (node.children && node.children.length > 0) {
|
||||
traverse(node.children);
|
||||
}
|
||||
}
|
||||
};
|
||||
traverse(unprunedTree);
|
||||
|
||||
console.log(`🔍 Found ${imageIds.length} images in category tree.`);
|
||||
await pictureSyncer.syncImages(imageIds, 'categories');
|
||||
});
|
||||
|
||||
// Trigger immediate sync
|
||||
categorySyncer.triggerSync();
|
||||
|
||||
// Check if running interactively
|
||||
if (process.stdout.isTTY) {
|
||||
console.log('🤖 Interactive mode: Syncing every minute. Press Ctrl-C to exit.');
|
||||
|
||||
// Schedule periodic sync
|
||||
setInterval(() => {
|
||||
categorySyncer.triggerSync();
|
||||
}, 60000);
|
||||
|
||||
// Handle graceful shutdown
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\n👋 Bye!');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user