feat: Add image deletion functionality before a specific date and update gallery UI
Some checks failed
Deploy to BeePC / deploy (push) Has been cancelled
Some checks failed
Deploy to BeePC / deploy (push) Has been cancelled
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user