mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
fix(storage): stop deleting covers, place images and journey photos another row may still show
Replacing a trip or list cover, changing or deleting a place or saved-place image and deleting a journey photo removed the bytes at once, without asking whether a trip copy, a journey, a saved place or another photo row still named them (#2924). Those paths now leave the object in place and the reclaim job removes it once no row names it. A journey photo the user deletes takes its local photo row with it when nothing else links it, so its bytes become reclaimable instead of being kept by a row nobody sees. A place image copied from a trip file is still dropped at once when the update that would name it fails: that copy was never anyone else's. Size and warning baselines follow the shrunk files.
This commit is contained in:
@@ -200,15 +200,8 @@ export class TripsController {
|
||||
throw new HttpException({ error: 'Could not save the selected cover image' }, 502);
|
||||
}
|
||||
}
|
||||
const oldCover =
|
||||
body.cover_image !== undefined
|
||||
? ((await this.trips.getRaw(id)) as { cover_image: string | null } | undefined)?.cover_image
|
||||
: undefined;
|
||||
try {
|
||||
const result = await this.trips.update(id, user.id, body, user.role);
|
||||
if (body.cover_image !== undefined && body.cover_image !== oldCover) {
|
||||
await this.trips.deleteOldCover(oldCover);
|
||||
}
|
||||
if (Object.keys(result.changes).length > 0) {
|
||||
await this.audit.writeAudit({
|
||||
userId: user.id,
|
||||
@@ -264,8 +257,9 @@ export class TripsController {
|
||||
}
|
||||
// Commit the spooled upload to its final storage location (atomic
|
||||
// same-volume rename) before anything references the final path.
|
||||
// The replaced cover stays: a trip copy or a journey may show the same
|
||||
// object, and the storage reclaim job removes it once nothing names it.
|
||||
await this.storage.put('covers', file.filename, { tmpPath: file.path });
|
||||
await this.trips.deleteOldCover(trip.cover_image);
|
||||
const coverUrl = `/uploads/covers/${file.filename}`;
|
||||
await this.trips.updateCoverImage(id, coverUrl);
|
||||
return { cover_image: coverUrl };
|
||||
|
||||
Reference in New Issue
Block a user