Skip to content

feat: make preview conversion timeout and max file size configurable#5408

Open
juliusknorr wants to merge 1 commit intomainfrom
feat/configurable-preview-timeout-and-max-filesize
Open

feat: make preview conversion timeout and max file size configurable#5408
juliusknorr wants to merge 1 commit intomainfrom
feat/configurable-preview-timeout-and-max-filesize

Conversation

@juliusknorr
Copy link
Member

@juliusknorr juliusknorr commented Feb 19, 2026

Attempt to implement with Claude Sonnet 4.6 and a custom agent definition, therefore collecting my personal feedback on that a bit here:

  • Prompt was rather simple with more context in the github issue: Create a branch, Implement the feature described in https://github.com/nextcloud/richdocuments/issues/5404 and open a pull request for it
  • Did one manual fixup 1f269e6 but otherwise this is good 👍
  • Not a fan of the changes summary in the pr message, could be improved in prompting
  • It needed some guidance to run phpunit tests with the xml configuration file
  • Asked to cover this with phpunit tests 2a2ed3e

Summary

Fixes #5404

Adds two new configurable options for preview conversion:

  • Timeout: The timeout (in seconds) for preview conversion requests to Collabora. Defaults to 5 seconds.
  • Max file size: Files larger than this limit are skipped and no preview is generated. Defaults to 100 MB.

Both options can be set via occ config:app:set:

occ config:app:set richdocuments preview_conversion_timeout --type integer --value 10
occ config:app:set richdocuments preview_conversion_max_filesize --type integer --value 52428800

Changes

  • Added PREVIEW_CONVERSION_TIMEOUT and PREVIEW_CONVERSION_MAX_FILESIZE constants + getter methods to AppConfig
  • Office::getThumbnail now skips conversion when file size exceeds the configured limit
  • RemoteService::convertFileTo passes the configured timeout to the HTTP client
  • RemoteService::convertTo accepts a $timeout parameter (defaults to REMOTE_TIMEOUT_DEFAULT for non-preview callers)
  • Documentation updated in docs/app_settings.md

@juliusknorr juliusknorr requested a review from elzody as a code owner February 19, 2026 14:07
@juliusknorr juliusknorr force-pushed the feat/configurable-preview-timeout-and-max-filesize branch from 2a2ed3e to 063a515 Compare February 19, 2026 15:13
@juliusknorr juliusknorr added the enhancement New feature or request label Feb 19, 2026
@juliusknorr juliusknorr requested a review from Copilot February 19, 2026 15:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements configurable timeout and maximum file size settings for preview conversion operations in the Nextcloud Richdocuments app. The changes address issue #5404 by allowing administrators to customize preview conversion behavior via OCC commands.

Changes:

  • Added two new configuration options: preview_conversion_timeout (default: 5 seconds) and preview_conversion_max_filesize (default: 100 MB)
  • Modified the preview generation logic to skip files exceeding the configured size limit
  • Updated the conversion service to use the configured timeout for preview requests while maintaining backward compatibility for other conversion operations

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/AppConfig.php Adds constants and getter methods for the two new configuration options with appropriate defaults
lib/Service/RemoteService.php Adds timeout parameter to convertTo() method and passes configured timeout from convertFileTo()
lib/Preview/Office.php Implements file size check before attempting preview conversion with debug logging
docs/app_settings.md Documents the new configuration options with usage examples
tests/lib/AppConfigTest.php Adds unit tests for the new AppConfig getter methods
tests/lib/Preview/OfficeTest.php Adds unit tests for the new file size checking behavior in preview generation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Julius Knorr <jus@bitgrid.net>
@juliusknorr juliusknorr force-pushed the feat/configurable-preview-timeout-and-max-filesize branch from 063a515 to fc9d7c9 Compare February 19, 2026 19:00
@juliusknorr juliusknorr requested a review from Copilot February 19, 2026 20:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +69 to 72
$timeout = $this->appConfig->getPreviewConversionTimeout();
return $this->convertTo($file->getName(), $stream, $format, [], $timeout);
}

Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

convertFileTo() now unconditionally uses getPreviewConversionTimeout(). This method is also used outside the preview code path (e.g. via ConversionProvider::convertFile()), so changing it makes the preview timeout setting affect non-preview conversions as well, which is inconsistent with the config name/docs and can change behavior unexpectedly.

Consider keeping convertFileTo() on the default timeout and instead passing the preview timeout from Office::getThumbnail() (e.g. by adding an optional timeout parameter to convertFileTo() or introducing a dedicated preview-only method).

Suggested change
$timeout = $this->appConfig->getPreviewConversionTimeout();
return $this->convertTo($file->getName(), $stream, $format, [], $timeout);
}
return $this->convertTo($file->getName(), $stream, $format);
}

Copilot uses AI. Check for mistakes.
}
return $this->convertTo($file->getName(), $stream, $format);
$timeout = $this->appConfig->getPreviewConversionTimeout();
return $this->convertTo($file->getName(), $stream, $format, [], $timeout);
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

convertFileTo() opens a local file stream but never closes it. In exception cases (and potentially in long-running PHP processes), this can leak file descriptors.

Wrap the convertTo() call in a try/finally and fclose($stream) in the finally block.

Suggested change
return $this->convertTo($file->getName(), $stream, $format, [], $timeout);
try {
return $this->convertTo($file->getName(), $stream, $format, [], $timeout);
} finally {
fclose($stream);
}

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +42
'preview_conversion_timeout' => 5,
'preview_conversion_max_filesize' => 104857600, // 100 MB
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The new default entries use string literals ('preview_conversion_timeout', 'preview_conversion_max_filesize') even though constants for these keys were introduced just above. Using the constants here would reduce the chance of typos/mismatches if the key names ever change.

Suggested change
'preview_conversion_timeout' => 5,
'preview_conversion_max_filesize' => 104857600, // 100 MB
self::PREVIEW_CONVERSION_TIMEOUT => 5,
self::PREVIEW_CONVERSION_MAX_FILESIZE => 104857600, // 100 MB

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make timeout and maximum file size for preview conversion of the convert-to endpoint configurable

2 participants