feat: Add web server and UI for category tree display, and update picture syncer to use AVIF format.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import sharp from 'sharp';
|
||||
import { createConnection } from './database.js';
|
||||
|
||||
class PictureSyncer {
|
||||
@@ -25,18 +26,17 @@ class PictureSyncer {
|
||||
// Directory might be empty or new
|
||||
}
|
||||
|
||||
// Filter for image files (assuming we save as {id}.jpg or similar, but let's check just by ID prefix)
|
||||
// Actually, let's assume we save as `${id}.jpg`
|
||||
// Filter for image files (assuming we save as {id}.avif)
|
||||
const existingIds = existingFiles
|
||||
.filter(f => f.endsWith('.jpg'))
|
||||
.map(f => parseInt(f.replace('.jpg', '')));
|
||||
.filter(f => f.endsWith('.avif'))
|
||||
.map(f => parseInt(f.replace('.avif', '')));
|
||||
|
||||
const validIds = new Set(imageIds.filter(id => id !== null && id !== undefined));
|
||||
|
||||
// 1. Delete obsolete images
|
||||
const toDelete = existingIds.filter(id => !validIds.has(id));
|
||||
for (const id of toDelete) {
|
||||
const filePath = path.join(groupDir, `${id}.jpg`);
|
||||
const filePath = path.join(groupDir, `${id}.avif`);
|
||||
await fs.unlink(filePath);
|
||||
}
|
||||
if (toDelete.length > 0) {
|
||||
@@ -73,9 +73,11 @@ class PictureSyncer {
|
||||
|
||||
for (const record of result.recordset) {
|
||||
if (record.bBild) {
|
||||
const filePath = path.join(dir, `${record.kBild}.jpg`);
|
||||
await fs.writeFile(filePath, record.bBild);
|
||||
// console.log(`💾 Saved image: ${filePath}`);
|
||||
const filePath = path.join(dir, `${record.kBild}.avif`);
|
||||
// Convert to AVIF using sharp
|
||||
await sharp(record.bBild)
|
||||
.avif({ quality: 80 })
|
||||
.toFile(filePath);
|
||||
}
|
||||
}
|
||||
const processed = Math.min(i + chunkSize, ids.length);
|
||||
|
||||
Reference in New Issue
Block a user