feat: filter sidebar, ingest progress, starred photos
- Left filter sidebar: All Photos / Favorites / Date by Year / Tags / Collections with counts, See more/less toggles, and blue active-row highlight - SSE ingest badge in header: pulsing dot + filename + indexed count during scan; auto-refreshes the library when a scan finishes - Starred/Favorites: starred column on photos, star button in lightbox toolbar, Favorites row in sidebar, ?starred=1 filter on /api/photos - GET /api/library/stats endpoint (totals, years, tags, collections) - GET /api/ingest/stream SSE endpoint (polls ingest_status table every 1.5s) - Worker writes ingest_status (active, current file, scanned count) to SQLite Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
4df32f9f32
commit
f0e237ab2b
10 files changed
+541
-127
No files matched your search
+15
-6
@@ -13,22 +13,31 @@ const db = openDb(DB_PATH);
|
||||
console.log(`[worker] watching ${path.resolve(PHOTO_DIR)}`);
|
||||
console.log(`[worker] db at ${path.resolve(DB_PATH)} (${db.count()} photos indexed)`);
|
||||
|
||||
// Serial queue: chokidar fires many 'add' events at once on startup;
|
||||
// process them one at a time to keep memory and I/O pressure low.
|
||||
const queue = [];
|
||||
let busy = false;
|
||||
let busy = false;
|
||||
let scanned = 0;
|
||||
let errors = 0;
|
||||
|
||||
async function drain() {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
|
||||
db.setIngestStatus({ active: true, scanned, errors });
|
||||
|
||||
while (queue.length > 0) {
|
||||
const fp = queue.shift();
|
||||
try {
|
||||
await ingestFile(fp, db, POSTER_DIR);
|
||||
scanned++;
|
||||
db.setIngestStatus({ active: true, current: path.basename(fp), scanned, errors });
|
||||
} catch (err) {
|
||||
errors++;
|
||||
console.error(`[worker] ${path.basename(fp)}: ${err.message}`);
|
||||
db.setIngestStatus({ active: true, current: path.basename(fp), scanned, errors });
|
||||
}
|
||||
}
|
||||
|
||||
db.setIngestStatus({ active: false, current: null, scanned, errors });
|
||||
busy = false;
|
||||
}
|
||||
|
||||
@@ -36,7 +45,7 @@ const watcher = chokidar.watch(PHOTO_DIR, {
|
||||
persistent: true,
|
||||
ignoreInitial: false,
|
||||
awaitWriteFinish: { stabilityThreshold: 2000, pollInterval: 100 },
|
||||
ignored: /(^|[/\\])\../, // skip dotfiles
|
||||
ignored: /(^|[/\\])\../,
|
||||
});
|
||||
|
||||
watcher.on('add', (fp) => {
|
||||
@@ -46,8 +55,7 @@ watcher.on('add', (fp) => {
|
||||
});
|
||||
|
||||
watcher.on('unlink', (fp) => {
|
||||
const resolved = path.resolve(fp);
|
||||
db.removePhoto(resolved);
|
||||
db.removePhoto(path.resolve(fp));
|
||||
console.log(`[worker] removed ${path.basename(fp)}`);
|
||||
});
|
||||
|
||||
@@ -55,6 +63,7 @@ watcher.on('error', (err) => console.error('[worker] watcher error:', err));
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\n[worker] shutting down');
|
||||
db.setIngestStatus({ active: false, current: null, scanned, errors });
|
||||
watcher.close();
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in new issue
Block a user