Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 26x 26x 25x 1x 24x 24x 2x 4x 5x 4x 19x 19x 21x 21x 21x 1x | // Cover Image Denormalization Helpers
// Recalculates and updates the denormalized coverImage column on the projects table.
// Called after mutations that could change the cover image (photo/media add/delete/reorder).
import type { Dal } from "../dal";
import { resolveProjectCover } from "../services/cover-cascade";
/**
* Recalculate the cover image path for a project.
*
* Room-based projects delegate to resolveProjectCover() which implements
* the full cascade: defaultRoom cover → defaultRoom first → any room cover → any room first.
* Legacy projects use resolveLegacyCover().
*/
export async function recalculateCoverImage(
projectId: string,
dal: Dal,
_services?: unknown,
): Promise<string | null> {
try {
const project = await dal.projects.findById(projectId);
if (!project) {
return null;
}
const rooms = await dal.rooms.findByProjectId(projectId);
if (rooms.length === 0) {
return null;
}
const roomsWithMedia = await Promise.all(
rooms.map(async (room) => ({
...room,
media: await dal.media.findByRoomId(room.id),
})),
);
return resolveProjectCover(roomsWithMedia, project.defaultRoomId);
} catch (err) {
console.error(
"Failed to recalculate cover image for project:",
projectId,
err,
);
return null;
}
}
/**
* Recalculate and persist the cover image for a project.
*
* Calls recalculateCoverImage and then updates the project's coverImage column.
* Designed to be called via c.executionCtx.waitUntil() for non-blocking execution.
*/
export async function updateProjectCoverImage(
projectId: string,
dal: Dal,
_services?: unknown,
): Promise<void> {
try {
const coverImage = await recalculateCoverImage(projectId, dal);
await dal.projects.update(projectId, { coverImage });
} catch (err) {
// Log but don't throw - cover image updates should not break mutations
console.error("Failed to update cover image for project:", projectId, err);
}
}
|