Skip to content

Preserve PNG uploads as PNG and make image storage format-aware - #20

Open
langningchen with Copilot wants to merge 2 commits into
mainfrom
copilot/store-png-files
Open

Preserve PNG uploads as PNG and make image storage format-aware#20
langningchen with Copilot wants to merge 2 commits into
mainfrom
copilot/store-png-files

Conversation

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

PNG uploads were being converted to JPEG, which removes alpha transparency. This change keeps PNG assets as .png while preserving compatibility with existing .jpeg images across read and cleanup paths.

  • Upload format preservation

    • Frontend image recompression now keeps PNG input as image/png (instead of forcing image/jpeg).
    • Backend upload parsing now derives storage extension from the incoming data URL and writes ${imageId}.png for PNG, ${imageId}.jpeg otherwise.
  • Format-aware image serving

    • Image fetch path now resolves files by trying supported extensions (.png, .jpeg) for a given imageId.
    • Response Content-Type now reflects the resolved file type (image/png or image/jpeg).
  • Retention and deletion compatibility

    • Repository tree scan now recognizes both .png and .jpeg image objects.
    • Cleanup/deletion logic now deletes whichever supported extension exists for the target imageId.
const imageExtension: ImageExtension =
  imageMatch[1].toLowerCase() === 'png' ? 'png' : 'jpeg';

await fetch(githubApiUrl(env, `/contents/${imageId}.${imageExtension}`), {
  method: 'PUT',
  // ...
});

Co-authored-by: langningchen <81672884+langningchen@users.noreply.github.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 22, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
image 8f5dbca Commit Preview URL

Branch Preview URL
Aug 22 2026, 12:23 PM

Copilot AI changed the title [WIP] Store .png files instead of converting to .jpeg Preserve PNG uploads as PNG and make image storage format-aware Aug 22, 2026
Copilot AI requested a review from langningchen August 22, 2026 12:25
@langningchen
langningchen marked this pull request as ready for review August 22, 2026 12:25
Copilot AI lite review requested due to automatic review settings August 22, 2026 12:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f5dbca6a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/index.ts
headers: corsHeaders,
});
}
const imageExtension: ImageExtension = imageMatch[1].toLowerCase() === 'png' ? 'png' : 'jpeg';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update purge workflow for PNG image histories

When this line starts storing PNG uploads as ${imageId}.png, the second cleanup stage stops covering those files: target-repository/scripts/purge-deleted-image-history.sh:26 and :30 still only select deleted *.jpeg paths. The Worker can delete stale PNGs from HEAD, but the documented history-purge workflow will never select their deleted paths, so PNG uploads continue consuming repository history indefinitely; please extend that script to include .png alongside .jpeg.

Useful? React with 👍 / 👎.

Comment on lines +64 to +65
const mimeType = /^data:image\/png;/i.test(dataUrl) ? 'image/png' : 'image/jpeg';
resolve(canvas.toDataURL(mimeType, quality));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Commit the rebuilt browser bundle

This source change does not reach clients that use the checked-in Worker assets: wrangler.toml serves ./public, public/index.html loads /main.js, and the current public/main.js still calls toDataURL("image/jpeg", z). In deployments or reviews that serve the committed public directory without regenerating it, PNG uploads larger than 1 MiB are still converted to JPEG before /upload; please rebuild and commit public/main.js or remove the stale checked-in bundle from the served path.

Useful? React with 👍 / 👎.

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.

Store .png in .png files instead of converting them to .jpeg files

3 participants