feat: Add image deletion functionality before a specific date and update gallery UI
Some checks failed
Deploy to BeePC / deploy (push) Has been cancelled

This commit is contained in:
2026-02-12 16:14:06 -05:00
parent 9c72b00b1b
commit 854fd199bf
4 changed files with 653 additions and 343 deletions

View File

@@ -293,6 +293,38 @@ function cleanupOldImages(daysOld = 30) {
}); });
} }
/**
* Get images before a specific date (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS)
*/
function getImagesBeforeDate(beforeDate) {
return new Promise((resolve, reject) => {
db.all(
'SELECT id, file_path FROM images WHERE fetched_at < ? ORDER BY fetched_at ASC',
[beforeDate],
(err, rows) => {
if (err) reject(err);
else resolve(rows || []);
}
);
});
}
/**
* Delete images before a specific date (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS)
*/
function deleteImagesBeforeDate(beforeDate) {
return new Promise((resolve, reject) => {
db.run(
'DELETE FROM images WHERE fetched_at < ?',
[beforeDate],
function(err) {
if (err) reject(err);
else resolve(this.changes);
}
);
});
}
/** /**
* Get images by hash (detect duplicates) * Get images by hash (detect duplicates)
*/ */
@@ -337,6 +369,8 @@ module.exports = {
getImageCount, getImageCount,
deleteImage, deleteImage,
cleanupOldImages, cleanupOldImages,
getImagesBeforeDate,
deleteImagesBeforeDate,
getImagesByHash, getImagesByHash,
closeDatabase closeDatabase
}; };

View File

@@ -29,6 +29,3 @@ async function loadStatus() {
// Load status on page load // Load status on page load
document.addEventListener('DOMContentLoaded', loadStatus); document.addEventListener('DOMContentLoaded', loadStatus);
// Refresh status every 30 seconds
setInterval(loadStatus, 30000);

File diff suppressed because it is too large Load Diff

View File

@@ -224,6 +224,45 @@ router.post('/cleanup', async (req, res) => {
} }
}); });
/**
* POST /api/cleanup/before - Delete images before a specific date
*/
router.post('/cleanup/before', async (req, res) => {
try {
const { beforeDate } = req.body;
if (!beforeDate || typeof beforeDate !== 'string') {
return res.status(400).json({ success: false, error: 'beforeDate is required (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS)' });
}
const normalizedInput = beforeDate.replace('T', ' ');
const normalized = normalizedInput.length <= 10
? `${normalizedInput} 00:00:00`
: (normalizedInput.length === 16 ? `${normalizedInput}:00` : normalizedInput);
const imagesToDelete = await database.getImagesBeforeDate(normalized);
let filesDeleted = 0;
for (const image of imagesToDelete) {
const deletedFile = await storage.deleteImageFile(image.file_path);
if (deletedFile) filesDeleted++;
}
const deletedFromDb = await database.deleteImagesBeforeDate(normalized);
res.json({
success: true,
cleanup: {
deletedFromDb,
filesDeleted,
beforeDate: normalized
}
});
} catch (err) {
res.status(500).json({ success: false, error: err.message });
}
});
/** /**
* GET /api/fetcher/status - Get fetcher status * GET /api/fetcher/status - Get fetcher status
*/ */