Fix adoption report photos and section order
This commit is contained in:
+34
-2
@@ -1387,6 +1387,37 @@ const deleteBirdPhotoObjectIfNeeded = async (objectKey: string | null) => {
|
||||
}
|
||||
};
|
||||
|
||||
const loadBirdReportPhotoBuffer = async (bird: BirdRow) => {
|
||||
if (!bird.photo_object_key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const s3Config = getS3ImageStorageConfig();
|
||||
|
||||
if (!s3Config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const signedUrl = getSignedS3ObjectUrl({
|
||||
config: s3Config,
|
||||
objectKey: bird.photo_object_key,
|
||||
expiresInSeconds: 5 * 60,
|
||||
});
|
||||
const imageResponse = await fetch(signedUrl);
|
||||
|
||||
if (!imageResponse.ok) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const contentType = imageResponse.headers.get('content-type') || bird.photo_content_type || '';
|
||||
|
||||
if (!/^image\/(?:png|jpe?g)$/i.test(contentType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Buffer.from(await imageResponse.arrayBuffer());
|
||||
};
|
||||
|
||||
const getDefaultBirdPhotoAttachment = () => {
|
||||
const defaultPhotoPath = path.join(process.cwd(), 'assets', 'yoda-default.png');
|
||||
|
||||
@@ -3568,10 +3599,11 @@ app.post(
|
||||
throw new Error('Unable to create bird transfer code.');
|
||||
}
|
||||
|
||||
const [weights, vetVisits, notes] = await Promise.all([
|
||||
const [weights, vetVisits, notes, birdPhotoBuffer] = await Promise.all([
|
||||
listWeightsForBird(sourceBird.id, req.auth!.workspace.id, adoptionReportWeightHistoryDays),
|
||||
listVetVisitsForBird(sourceBird.id, req.auth!.workspace.id),
|
||||
listFlockNotes(req.auth!.workspace.id),
|
||||
loadBirdReportPhotoBuffer(sourceBird),
|
||||
]);
|
||||
const birdNotes = notes.filter((note) => note.bird_id === sourceBird.id);
|
||||
const pdf = await renderAdoptionReportPdf({
|
||||
@@ -3579,8 +3611,8 @@ app.post(
|
||||
weights,
|
||||
vetVisits,
|
||||
notes: birdNotes,
|
||||
workspace: req.auth!.workspace,
|
||||
transferCode: transferCode.code,
|
||||
birdPhotoBuffer,
|
||||
printFriendly: req.query.printFriendly === 'true',
|
||||
assets: {
|
||||
logoPath: path.join(process.cwd(), 'assets', 'flockpal-logo.png'),
|
||||
|
||||
Reference in New Issue
Block a user