Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat., Imaginary: disable document processing by default #46447

Closed
wants to merge 2 commits into from

Conversation

ernolf
Copy link
Contributor

@ernolf ernolf commented Jul 11, 2024

Summary

Document previews often appear as minimal, almost blank "miniatures" that can inadvertently reveal content, which may not always be desired.
Many users prefer having document icons instead of these previews.
The classic preview provider settings have considered this preference.
This feature reintroduces this choice for Imaginary.
Given that it is easier to generate previews than to remove existing ones, the default value is set to 'false'.

ernolf

TODO

  • ...

Checklist

Signed-off-by: ernolf <raphael.gradenwitz@googlemail.com>
Signed-off-by: ernolf <raphael.gradenwitz@googlemail.com>
Copy link
Contributor

@szaimen szaimen left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @ernolf!

I'd personally vote for enabling it by default and allowing to disable it

Comment on lines +1317 to +1319
* Defaults to ``false``
*/
'imaginary_process_documents' => false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Defaults to ``false``
*/
'imaginary_process_documents' => false,
* Defaults to ``true``
*/
'imaginary_process_documents' => true,

return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp)|application\/(pdf|illustrator))/';
$config = \OC::$server->getConfig();
// Check if processing of documents is enabled
$processDocuments = $config->getSystemValueBool('imaginary_process_documents', false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$processDocuments = $config->getSystemValueBool('imaginary_process_documents', false);
$processDocuments = $config->getSystemValueBool('imaginary_process_documents', true);

case 'application/pdf':
case 'application/illustrator':
// Check if processing of documents is enabled
if (!$this->config->getSystemValueBool('imaginary_process_documents', false)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!$this->config->getSystemValueBool('imaginary_process_documents', false)) {
if (!$this->config->getSystemValueBool('imaginary_process_documents', true)) {

@szaimen szaimen requested a review from st3iny July 11, 2024 18:51
@szaimen szaimen added this to the Nextcloud 30 milestone Jul 11, 2024
@@ -1307,6 +1307,17 @@
*/
'preview_imaginary_key' => 'secret',

/**
* Imaginary can, but does not, process PDF and Illustrator files by default.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Imaginary can, but does not, process PDF and Illustrator files by default.
* Imaginary processes PDF and Illustrator files by default.

@kesselb
Copy link
Contributor

kesselb commented Jul 11, 2024

Thanks for your pull request 👍

Cleaner, then a new configuration option, would be to use subclassing and reuse the existing preview provider configuration.

  • Change Imaginary.supportedMimeTypes and remove the application mime type
  • Create a new class ImaginaryDocuments extending Imaginary and overwrite supportedMimeTypes to return only the document mime types.
  • To enable/disable the provider, add Imaginary or ImaginaryDocuments to the preview provider list.
Index: lib/private/PreviewManager.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php
--- a/lib/private/PreviewManager.php	(revision e6502b1399ae57a1ab3e9097ab5337e51216adb2)
+++ b/lib/private/PreviewManager.php	(date 1720727804062)
@@ -346,6 +346,7 @@
 		$this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/');
 		$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
 		$this->registerCoreProvider(Preview\Imaginary::class, Preview\Imaginary::supportedMimeTypes());
+		$this->registerCoreProvider(Preview\ImaginaryDocuments::class, Preview\ImaginaryDocuments::supportedMimeTypes());
 
 		// SVG and Bitmap require imagick
 		if ($this->imagickSupport->hasExtension()) {
Index: lib/private/Preview/Imaginary.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/private/Preview/Imaginary.php b/lib/private/Preview/Imaginary.php
--- a/lib/private/Preview/Imaginary.php	(revision e6502b1399ae57a1ab3e9097ab5337e51216adb2)
+++ b/lib/private/Preview/Imaginary.php	(date 1720727664657)
@@ -40,7 +40,7 @@
 	}
 
 	public static function supportedMimeTypes(): string {
-		return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp)|application\/(pdf|illustrator))/';
+		return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp))/';
 	}
 
 	public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop): ?IImage {
Index: lib/private/Preview/ImaginaryDocuments.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/private/Preview/ImaginaryDocuments.php b/lib/private/Preview/ImaginaryDocuments.php
new file mode 100644
--- /dev/null	(date 1720728758772)
+++ b/lib/private/Preview/ImaginaryDocuments.php	(date 1720728758772)
@@ -0,0 +1,15 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OC\Preview;
+
+class ImaginaryDocuments extends Imaginary {
+	public static function supportedMimeTypes(): string {
+		return '/application\/(pdf|illustrator)/';
+	}
+}

Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

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

Conceptually, this seems like a good idea.

However, I prefer kesselb's approach for its simplicity as this is mostly about changing supported mime types.

@ernolf
Copy link
Contributor Author

ernolf commented Jul 13, 2024

I prefer kesselb's approach for its simplicity as this is mostly about changing supported mime types.

I also believe @kesselb's suggestion is beneficial as it moves us towards standardizing preview handling.

Some thoughts:
When categorizing MIME types, we can group them as follows:

  • Images (Lossy): jpeg, gif, webp
  • Raw Images (Lossless): bmp, x-bitmap, png, heic, heif, tiff
  • Vector-based Images: svg+xml, application/illustrator (I have now categorized Illustrator among images, where it rightly belongs.)
  • PDF/Documents: application/pdf

Maintaining one provider per MIME type (as with legacy providers) or further dividing images into lossy, lossless, and vector-based categories might confuse existing Imaginary users. Therefore, I propose simplifying this into two categories: images processed by "Imaginary" and PDF document previews processed by "ImaginaryPDF". Since only PDF documents can be handled and Illustrator actually belongs among the images, introducing a provider called "ImaginaryDocuments" would also be rather confusing.

I've submitted a new pull request #46508 (this time as a member) that expands on kesselb's approach and this thoughts.

So, I kindly request your support there and would like to close this pull request if that would be OK for you.

Copy link
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@ernolf
Copy link
Contributor Author

ernolf commented Jul 26, 2024

Since #46508 is merged, this can be closed

@ernolf ernolf closed this Jul 26, 2024
@skjnldsv skjnldsv removed this from the Nextcloud 30 milestone Aug 14, 2024
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.

6 participants