Skip to content

Convert Telegram HEIC uploads to JPEG before storage#405

Merged
techeng322 merged 1 commit into
mainfrom
techengme/telegram-convert-heic-to-jpeg-before-upload
Jul 11, 2026
Merged

Convert Telegram HEIC uploads to JPEG before storage#405
techeng322 merged 1 commit into
mainfrom
techengme/telegram-convert-heic-to-jpeg-before-upload

Conversation

@techeng322

@techeng322 techeng322 commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Detect HEIC/HEIF buffers in uploadPhotoAttachment and decode to JPEG via the shared prepareImageBufferForSharp helper before Supabase upload.
  • Stored metadata and content mime become image/jpeg for new Telegram moments.
  • EXIF saleStart extraction in createMomentsFromGroup is unchanged — it still runs on the original HEIC buffer before upload.

Test plan

  • pnpm test:run src/lib/telegram/chat/__tests__/uploadPhotoAttachment.test.ts
  • pnpm test:run src/lib/telegram/chat/__tests__/uploadPhotoAttachment.heic.test.ts
  • Upload a HEIC via Telegram bot and confirm Supabase/Arweave asset is JPEG and blur URLs work without HEIC proxy decoding

Made with Cursor

Summary by CodeRabbit

  • New Features

    • HEIC photo attachments are now automatically converted to JPEG format before upload.
    • Converted images retain the expected metadata and remain available through the uploaded photo URL.
  • Bug Fixes

    • Improved compatibility for HEIC images, ensuring they are uploaded as broadly supported JPEG files.
  • Tests

    • Added coverage verifying HEIC conversion, JPEG output, metadata, and upload behavior.

EXIF saleStart is still read from the original buffer in createMomentsFromGroup;
only the stored asset is normalized to image/jpeg so downstream consumers avoid
HEIC decoding.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Jul 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
in-process-api Ready Ready Preview Jul 11, 2026 5:59pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a0ac3755-4773-4fef-9295-7ac1de6f8bf9

📥 Commits

Reviewing files that changed from the base of the PR and between b5acd4f and 1a388a2.

📒 Files selected for processing (2)
  • src/lib/telegram/chat/__tests__/uploadPhotoAttachment.heic.test.ts
  • src/lib/telegram/chat/uploadPhotoAttachment.ts

📝 Walkthrough

Walkthrough

uploadPhotoAttachment now detects HEIC buffers, converts them to JPEG before upload, updates the MIME type, and adds integration coverage for the converted bytes and metadata.

Changes

HEIC photo upload handling

Layer / File(s) Summary
HEIC detection and JPEG upload preparation
src/lib/telegram/chat/uploadPhotoAttachment.ts
Adds HEIC detection and image conversion before constructing the Supabase upload payload, setting converted uploads to image/jpeg.
HEIC upload integration validation
src/lib/telegram/chat/__tests__/uploadPhotoAttachment.heic.test.ts
Adds mocked integration coverage for JPEG MIME output, JPEG signature bytes, file upload arguments, and JSON metadata.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch techengme/telegram-convert-heic-to-jpeg-before-upload

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/lib/telegram/chat/__tests__/uploadPhotoAttachment.heic.test.ts

Oops! Something went wrong! :(

ESLint: 9.39.4

TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'configs' -> object with constructor 'Object'
| property 'flat' -> object with constructor 'Object'
| ...
| property 'plugins' -> object with constructor 'Object'
--- property 'react' closes the circle
Referenced from: /.eslintrc.json
at JSON.stringify ()
at /node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2255:45
at Array.map ()
at ConfigValidator.formatErrors (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2246:23)
at ConfigValidator.validateConfigSchema (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2277:84)
at ConfigArrayFactory._normalizeConfigData (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/

... [truncated 446 characters] ...

c/dist/eslintrc.cjs:3261:25)
at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3199:25)
(node:2) ESLintRCWarning: You are using an eslintrc configuration file, which is deprecated and support will be removed in v10.0.0. Please migrate to an eslint.config.js file. See https://eslint.org/docs/latest/use/configure/migration-guide for details. An eslintrc configuration file is used because you have the ESLINT_USE_FLAT_CONFIG environment variable set to false. If you want to use an eslint.config.js file, remove the environment variable. If you want to find the location of the eslintrc configuration file, use the --debug flag.
(Use node --trace-warnings ... to show where the warning was created)

src/lib/telegram/chat/uploadPhotoAttachment.ts

Oops! Something went wrong! :(

ESLint: 9.39.4

TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'configs' -> object with constructor 'Object'
| property 'flat' -> object with constructor 'Object'
| ...
| property 'plugins' -> object with constructor 'Object'
--- property 'react' closes the circle
Referenced from: /.eslintrc.json
at JSON.stringify ()
at /node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2255:45
at Array.map ()
at ConfigValidator.formatErrors (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2246:23)
at ConfigValidator.validateConfigSchema (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2277:84)
at ConfigArrayFactory._normalizeConfigData (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/

... [truncated 446 characters] ...

c/dist/eslintrc.cjs:3261:25)
at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3199:25)
(node:2) ESLintRCWarning: You are using an eslintrc configuration file, which is deprecated and support will be removed in v10.0.0. Please migrate to an eslint.config.js file. See https://eslint.org/docs/latest/use/configure/migration-guide for details. An eslintrc configuration file is used because you have the ESLINT_USE_FLAT_CONFIG environment variable set to false. If you want to use an eslint.config.js file, remove the environment variable. If you want to find the location of the eslintrc configuration file, use the --debug flag.
(Use node --trace-warnings ... to show where the warning was created)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@techeng322 techeng322 merged commit e375204 into main Jul 11, 2026
2 of 3 checks passed
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.

1 participant