Skip to content

Fix broken preview images for extension-less external files - #1520

Merged
jbtronics merged 2 commits into
Part-DB:masterfrom
killecaptron:fix-attachment-picture-detection
Sep 6, 2026
Merged

Fix broken preview images for extension-less external files#1520
jbtronics merged 2 commits into
Part-DB:masterfrom
killecaptron:fix-attachment-picture-detection

Conversation

@killecaptron

Copy link
Copy Markdown
Contributor

If no file extension can be extracted from the URL of an external attachment, Part-DB assumed that it is a picture. That is a sensible guess for image URLs, but it also applies to URLs which redirect to the actual file, like the datasheet links of the TrustedParts provider (https://www.trustedparts.com/productredirect?id=...).

Such datasheets were rendered as an in the attachment lists (showing a broken image) and the first one was automatically used as the preview picture of the part by the AttachmentSubmitHandler, so the part page showed a broken main image too.

The attachment type already knows which filetypes it may contain (the "Datasheet" type created by the info provider system is restricted to application/pdf), so use that information for the guess. Attachments whose URL has a known picture extension are unaffected, as are attachment types without a filetype filter.

Existing parts heal themselves: the AttachmentSubmitHandler already removes a master picture attachment which is not a picture anymore, as soon as the part is saved the next time.

If no file extension can be extracted from the URL of an external
attachment, Part-DB assumed that it is a picture. That is a sensible
guess for image URLs, but it also applies to URLs which redirect to the
actual file, like the datasheet links of the TrustedParts provider
(https://www.trustedparts.com/productredirect?id=...).

Such datasheets were rendered as an <img> in the attachment lists
(showing a broken image) and the first one was automatically used as the
preview picture of the part by the AttachmentSubmitHandler, so the part
page showed a broken main image too.

The attachment type already knows which filetypes it may contain (the
"Datasheet" type created by the info provider system is restricted to
application/pdf), so use that information for the guess. Attachments
whose URL has a known picture extension are unaffected, as are
attachment types without a filetype filter.

Existing parts heal themselves: the AttachmentSubmitHandler already
removes a master picture attachment which is not a picture anymore, as
soon as the part is saved the next time.
@jbtronics

Copy link
Copy Markdown
Member

Thanks for the PR. Seems like a useful change.

I moved the "allowsPicture" logic to the AttachmentType class, as its more a property of them and the logic might be reusable in other places.

@jbtronics
jbtronics merged commit 58b4321 into Part-DB:master Sep 6, 2026
14 checks passed
@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.39%. Comparing base (0e1a932) to head (c08fa33).
⚠️ Report is 28 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1520      +/-   ##
============================================
+ Coverage     61.82%   62.39%   +0.57%     
- Complexity     9728     9871     +143     
============================================
  Files           724      735      +11     
  Lines         31302    31745     +443     
============================================
+ Hits          19353    19808     +455     
+ Misses        11949    11937      -12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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