Skip to content

[IMP] preview of images#832

Merged
emjay0921 merged 2 commits into
17.0from
dms-fixes
Sep 12, 2025
Merged

[IMP] preview of images#832
emjay0921 merged 2 commits into
17.0from
dms-fixes

Conversation

@emjay0921
Copy link
Copy Markdown
Contributor

Why is this change needed?

Fix the problem on previewing images

How was the change implemented?

Modified the JS: preview_binary_field.esm.js

New unit tests

None

Unit tests executed by the author

None

How to test manually

  • Install or Upgrade spp_dms
  • Open or Create a DMS File with Image as content
  • Click the eye icon to preview

Related links

Copy link
Copy Markdown
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.

Summary of Changes

Hello @emjay0921, 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 pull request addresses an issue with image preview functionality within the system. The changes ensure that images are correctly displayed when the preview action is triggered, improving the user experience for viewing image content.

Highlights

  • Image Preview Logic Refactor: The logic for previewing images has been updated to directly construct an image URL using the /web/image endpoint and pass a fileModel object to the file viewer, rather than relying on the Attachment store.
  • New Import: The url utility from @web/core/utils/urls has been imported to facilitate the construction of dynamic image URLs.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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.

Copy link
Copy Markdown
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 aims to fix image previews. The change modifies the JavaScript logic to use Odoo's /web/image URL for displaying images, which is a good approach. However, my review identifies two main issues with the implementation. First, there's a performance issue where file content is fetched twice for images, once unnecessarily. Second, the code incorrectly assumes any non-PDF file is an image, which could break previews for other file types. I've provided detailed comments with suggestions to address these high severity issues.

Comment on lines +43 to +56
const imageUrl = url("/web/image", {
model: resModel,
id: resId,
filename: record.name || "",
name: record.name || "",
mimetype: record.mimetype,
model_name: resModel,
url: fileUrl,
field: "content",
});
const fileModel = {
isImage: true,
isViewable: true,
displayName: record.name,
defaultSource: imageUrl,
downloadUrl: imageUrl,
};

this.fileViewer.open(attachment);
this.fileViewer.open(fileModel);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

While this change correctly uses the /web/image URL for previews, it introduces a performance issue.

The orm.read on line 23 fetches the entire file content, which can be large. This content is then not used within this else block for image previews, as the image is fetched again via the imageUrl. This results in fetching the file content twice.

Additionally, the blob creation logic on lines 30-38 is executed for all file types, but the resulting fileUrl is only used for PDFs. For images, this is unnecessary work.

To improve performance, consider refactoring to:

  • Only fetch file content when it's needed (i.e., for PDFs). For images, you can rely on the /web/image route. You could read the size field to check for file existence without fetching the content.
  • Move the blob creation logic (lines 30-38) inside the if block for PDFs.

Comment on lines +43 to +56
const imageUrl = url("/web/image", {
model: resModel,
id: resId,
filename: record.name || "",
name: record.name || "",
mimetype: record.mimetype,
model_name: resModel,
url: fileUrl,
field: "content",
});
const fileModel = {
isImage: true,
isViewable: true,
displayName: record.name,
defaultSource: imageUrl,
downloadUrl: imageUrl,
};

this.fileViewer.open(attachment);
this.fileViewer.open(fileModel);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

This logic assumes that any file that is not a PDF is an image by hardcoding isImage: true. This could lead to incorrect behavior or errors when trying to preview other viewable file types, such as videos or text files, that are not PDFs.

It would be more robust to check the file's mimetype to determine if it's an image before setting isImage: true.

For example:

const isImage = record.mimetype?.startsWith("image/");
if (isImage) {
    // current logic for images
} else {
    // handle other file types, or at least don't assume they are images.
    // The previous implementation might give a hint on how to handle them,
    // possibly by creating a blob URL and opening it with fileViewer for generic files.
}

A complete implementation would require handling other file types, but at a minimum, you should avoid incorrectly classifying all non-PDFs as images.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.14%. Comparing base (3ab7cfe) to head (5f8733e).

Additional details and impacted files
@@            Coverage Diff             @@
##             17.0     #832      +/-   ##
==========================================
+ Coverage   76.13%   76.14%   +0.01%     
==========================================
  Files         766      766              
  Lines       20306    20306              
  Branches     2504     2504              
==========================================
+ Hits        15460    15463       +3     
+ Misses       4302     4300       -2     
+ Partials      544      543       -1     

☔ View full report in Codecov by Sentry.
📢 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.

@emjay0921 emjay0921 removed the request for review from reichie020212 September 3, 2025 05:32
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Sep 3, 2025

@emjay0921 emjay0921 merged commit c582798 into 17.0 Sep 12, 2025
10 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant