Skip to content

Conversation

@jaskfla
Copy link
Contributor

@jaskfla jaskfla commented Oct 8, 2025

RN-1715

  • Converts all uploaded raster images to WebP (SVGs uploaded as-is)
  • Downscales it to a maximum of 3000 px along any one dimension
  • Strips location, EXIF, XMP metadata (preserves colour profile)

Todo

  • Allow lossless PNGs if small?

🥞 Stack

This is PR 1 of 2 in a stack:

  1. fix(datatrak): RN-1715: enforce allowlist of supported file types for Photo questions #6502
  2. This PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jaskfla, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This PR introduces image processing capabilities to the server-utils package using the sharp library. It ensures that all uploaded photos are stripped of location data, resized to a maximum dimension of 3000x3000 pixels, and converted to the WebP format for efficiency and standardization. This is the second PR in a two-part stack addressing issue RN-1715.

Highlights

  • Intent: This pull request, part of a two-PR stack (PR 2 of 2), aims to enhance photo upload functionality by stripping location data (EXIF metadata) from images and enforcing a maximum size for uploaded photos. It also standardizes image uploads to the WebP format.
  • Key Changes: - Dependency Update: Added the sharp image processing library (~0.34.4) to packages/server-utils/package.json.
  • Image Processing Logic: In packages/server-utils/src/s3/S3Client.ts, the uploadImage method was modified to:
    • Define MAX_IMAGE_SIZE as 3000 pixels.
    • Utilize sharp to process uploaded image buffers:
      • Preserve ICC color profiles (.keepIccProfile()).
      • Automatically correct image orientation based on EXIF data (.autoOrient()).
      • Resize images to fit within MAX_IMAGE_SIZE (3000x3000 pixels) without enlarging smaller images (.resize()).
      • Convert all uploaded images to the WebP format (.webp()), which implicitly strips most metadata, including location data.
    • Update the file naming and content type to reflect the new WebP format for all processed images.
  • Reviewer Activity: No specific reviewer activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces image processing capabilities to strip metadata and resize images before uploading to S3, which is a great improvement for security and performance. The implementation using sharp is solid for standard raster images. However, I've identified a couple of significant side effects for specific image types that should be addressed.

cursor[bot]

This comment was marked as outdated.

@jaskfla jaskfla force-pushed the rn-1715-strip-meta branch from 7ab44e4 to 34bcefb Compare October 8, 2025 23:13
cursor[bot]

This comment was marked as outdated.

# Conflicts:
#	packages/server-utils/package.json
#	yarn.lock
@jaskfla jaskfla force-pushed the rn-1715-strip-meta branch from 34bcefb to 524b7fa Compare October 8, 2025 23:24
@jaskfla jaskfla force-pushed the rn-1715-strip-meta branch from 524b7fa to 0827586 Compare October 8, 2025 23:32
Copy link
Collaborator

@rohan-bes rohan-bes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice stuff! Couple of tiny nitpicks but approving 👍

Comment on lines 180 to 183
const destinationContentType = shouldConvert ? 'image/webp' : sourceContentType;

if (shouldConvert) {
buffer = await sharp(buffer)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const destinationContentType = shouldConvert ? 'image/webp' : sourceContentType;
if (shouldConvert) {
buffer = await sharp(buffer)
let destinationContentType = sourceContentType;
if (shouldConvert) {
destinationContentType = 'image/webp';
buffer = await sharp(buffer)

Extremely minor but I think this reads a bit nicer to me.

Copy link
Contributor Author

@jaskfla jaskfla Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would typically agree with you here, but ephemerally setting it to sourceContentType means that destinationContentType’s TS type has to be quite wide: "image/avif" | "image/gif" | "image/jpeg" | "image/png" | "image/svg+xml" | "image/tiff" | "image/webp"

Whereas immediately setting it to one or the other lets the LSP infer destinationContentType: 'image/webp' | 'image/svg+xml'


if (shouldConvert) {
buffer = await sharp(buffer)
.autoOrient()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might just wanna do a little bit of testing on this, if I recall we've had issues in the past of incorrectly oriented Facility photos. Possibly this will resolve that issue :)

jaskfla and others added 2 commits October 13, 2025 16:26
Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com>
@jaskfla jaskfla force-pushed the rn-1715-strip-meta branch from 56b7cdd to 30c3615 Compare October 13, 2025 03:39
Base automatically changed from rn-1715-img-upload to dev December 1, 2025 23:38
# Conflicts:
#	packages/server-utils/src/s3/S3Client.ts
#	yarn.lock
@jaskfla jaskfla force-pushed the rn-1715-strip-meta branch 2 times, most recently from 5d5b1f1 to d15ec8c Compare December 11, 2025 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants