Skip to content

Conversation

@julien-nc
Copy link
Member

PreviewManager::getPreview can fail because it does not use the forced mimetype when checking if the preview is available.
This happens, for example, when $file->getMimeType() returns application/octet-stream because the file name has no extension.

This broke pretty recently, I saw it because the assistant is requesting previews for files which names have no extensions but we know their mimetype. It used to work fine by forcing the mimetype when calling PreviewManager::getPreview, now we get a NotFoundException because isAvailable returns false because it uses the mimetype from $file->getMimeType().

I didn't see any other way than to add an optional param to IPreview::isAvailable. It does not break anything as it's a new optional param. Is that ok? I'm fine with implementing another approach.

This can be backported to stable31 and stable30.
stable29 and older are not affected IMO.

@julien-nc julien-nc added this to the Nextcloud 32 milestone May 30, 2025
@julien-nc julien-nc requested a review from kyteinsky May 30, 2025 11:34
@julien-nc julien-nc requested a review from a team as a code owner May 30, 2025 11:34
@julien-nc julien-nc added the bug label May 30, 2025
@julien-nc julien-nc removed the request for review from a team May 30, 2025 11:34
@julien-nc julien-nc added the 3. to review Waiting for reviews label May 30, 2025
@julien-nc julien-nc requested review from Altahrim, come-nc and nfebe May 30, 2025 11:34
Copy link
Contributor

@kyteinsky kyteinsky left a comment

Choose a reason for hiding this comment

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

🚀

* Check if a preview can be generated for a file
*
* @param \OCP\Files\FileInfo $file
* @param string|null $mimeType To force a given mimetype for the file
Copy link
Contributor

Choose a reason for hiding this comment

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

we might need a @since for this even when it is optional

Copy link
Member Author

Choose a reason for hiding this comment

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

@susnux Hey, what would you recommend in terms of annotation for the addition of an optional param?

Copy link
Contributor

Choose a reason for hiding this comment

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

The since for 32 looks ok :)

@julien-nc julien-nc force-pushed the fix/noid/get-preview-force-mimetype branch 2 times, most recently from 28a6f94 to dd887f1 Compare June 2, 2025 10:21
@julien-nc
Copy link
Member Author

/backport to stable31

@julien-nc
Copy link
Member Author

/backport to stable30

@julien-nc julien-nc force-pushed the fix/noid/get-preview-force-mimetype branch from dd887f1 to 43d695c Compare June 2, 2025 10:29
Comment on lines 98 to 99
* @since 30.0.12 - isAvailable($mimeType) added the $mimeType argument to the signature
* @since 31.0.6 - isAvailable($mimeType) added the $mimeType argument to the signature
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not backport features normally to patch releases, so in other cases we only added it to the public interface for the current version (32) and only backported the private implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, so just to make sure we're on the same page: in this branch we add @since 32.0.0 - isAvailable($mimeType) added blabla in the public interface
and in the backports, we don't even add the new param in the interface but we backport the change in lib/private/PreviewManager.php. Right?

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
@julien-nc julien-nc force-pushed the fix/noid/get-preview-force-mimetype branch from 43d695c to c7e9f2c Compare June 2, 2025 13:51
@julien-nc julien-nc enabled auto-merge June 2, 2025 13:55
@julien-nc
Copy link
Member Author

@AndyScherzinger @come-nc Cypress failures should not be related.

@julien-nc julien-nc merged commit c4e936c into master Jun 2, 2025
233 of 248 checks passed
@julien-nc julien-nc deleted the fix/noid/get-preview-force-mimetype branch June 2, 2025 18:27
@backportbot
Copy link

backportbot bot commented Jun 2, 2025

The backport to stable30 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable30
git pull origin stable30

# Create the new backport branch
git checkout -b backport/53205/stable30

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts, resolve them
git cherry-pick c7e9f2c0

# Push the cherry pick commit to the remote repository and open a pull request
git push origin backport/53205/stable30

Error: Failed to push branch backport/53205/stable30: remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/nextcloud/server.git/'


Learn more about backports at https://docs.nextcloud.com/server/stable/go.php?to=developer-backports.

@AndyScherzinger
Copy link
Member

@julien-nc restarted it, turned green 👍
Backport to 30 failed though

@AndyScherzinger
Copy link
Member

/backport to stable30

@AndyScherzinger
Copy link
Member

Backport worked for me 😂

@skjnldsv skjnldsv mentioned this pull request Aug 19, 2025
@skjnldsv skjnldsv modified the milestones: Nextcloud 32, Nextcloud 33 Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants