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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

* The following MIME types are always processed:
* bmp, x-bitmap, png, jpeg, gif, heic, heif, svg+xml, tiff and webp
*
* Set to ``true`` to enable processing of documents of type pdf and illustrator.
*
* Defaults to ``false``
*/
'imaginary_process_documents' => false,
Comment on lines +1317 to +1319
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,


/**
* Only register providers that have been explicitly enabled
*
Expand Down
19 changes: 18 additions & 1 deletion lib/private/Preview/Imaginary.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ public function getMimeType(): string {
}

public static function supportedMimeTypes(): string {
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);


if ($processDocuments) {
return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp)|application\/(pdf|illustrator))/';
} else {
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 {
Expand Down Expand Up @@ -81,8 +89,17 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop
$mimeType = 'png';
break;
case 'image/svg+xml':
$convert = true;
// Converted files do not need to be autorotated
$autorotate = false;
$mimeType = 'png';
break;
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)) {

return null;
}
$convert = true;
// Converted files do not need to be autorotated
$autorotate = false;
Expand Down
Loading