mirror of
https://github.com/redmine/redmine.git
synced 2026-04-02 02:31:17 +02:00
Make Microsoft Office / LibreOffice preview limits configurable (#8959).
git-svn-id: https://svn.redmine.org/redmine/trunk@24522 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -239,9 +239,28 @@ default:
|
||||
|
||||
# Preview for Office documents (Microsoft Office / LibreOffice)
|
||||
#
|
||||
# Redmine uses Pandoc to convert supported Microsoft Office and LibreOffice
|
||||
# attachments to Markdown for preview. The settings below named
|
||||
# `markdownized_preview_*` control that Markdown-based preview generation.
|
||||
#
|
||||
# Absolute path (e.g. /usr/local/bin/pandoc) to the Pandoc command
|
||||
# used to convert supported attachments to Markdown for preview.
|
||||
#pandoc_command:
|
||||
#
|
||||
# Timeout when generating Markdown previews using the Pandoc command.
|
||||
# Timeout is set in seconds.
|
||||
# Default: 10
|
||||
#markdownized_preview_generation_timeout: 10
|
||||
#
|
||||
# Maximum source file size in bytes for Markdown preview generation.
|
||||
# Files larger than this limit are skipped.
|
||||
# Default: 10485760 (10 megabytes)
|
||||
#markdownized_preview_max_source_size: 10485760
|
||||
#
|
||||
# Maximum output size in bytes saved after Markdown conversion.
|
||||
# Larger output is truncated to this limit.
|
||||
# Default: 102400 (100 kilobytes)
|
||||
#markdownized_preview_max_output_size: 102400
|
||||
|
||||
# specific configuration options for production environment
|
||||
# that overrides the default ones
|
||||
|
||||
@@ -27,7 +27,10 @@ module Redmine
|
||||
'email_delivery' => nil,
|
||||
'max_concurrent_ajax_uploads' => 2,
|
||||
'common_mark_enable_hardbreaks' => true,
|
||||
'thumbnails_generation_timeout' => 10
|
||||
'thumbnails_generation_timeout' => 10,
|
||||
'markdownized_preview_generation_timeout' => 10,
|
||||
'markdownized_preview_max_source_size' => 10.megabytes,
|
||||
'markdownized_preview_max_output_size' => 100.kilobytes
|
||||
}
|
||||
|
||||
@config = nil
|
||||
|
||||
@@ -27,8 +27,9 @@ module Redmine
|
||||
extend Redmine::Utils::Shell
|
||||
|
||||
COMMAND = (Redmine::Configuration['pandoc_command'] || 'pandoc').freeze
|
||||
MAX_SOURCE_SIZE = 20.megabytes
|
||||
MAX_PREVIEW_SIZE = 512.kilobytes
|
||||
PREVIEW_GENERATION_TIMEOUT = Redmine::Configuration['markdownized_preview_generation_timeout'].to_i
|
||||
MAX_SOURCE_SIZE = Redmine::Configuration['markdownized_preview_max_source_size'].to_i
|
||||
MAX_OUTPUT_SIZE = Redmine::Configuration['markdownized_preview_max_output_size'].to_i
|
||||
|
||||
def self.supports?(filename)
|
||||
markdownizable_extensions.include?(File.extname(filename.to_s).downcase)
|
||||
@@ -50,7 +51,7 @@ module Redmine
|
||||
output = Tempfile.new('markdownized-preview')
|
||||
|
||||
begin
|
||||
Timeout.timeout(Redmine::Configuration['thumbnails_generation_timeout'].to_i) do
|
||||
Timeout.timeout(PREVIEW_GENERATION_TIMEOUT) do
|
||||
pid = Process.spawn(*args, out: output.path)
|
||||
_, status = Process.wait2(pid)
|
||||
unless status.success?
|
||||
@@ -72,8 +73,8 @@ module Redmine
|
||||
output.close
|
||||
end
|
||||
|
||||
preview = File.binread(output.path, MAX_PREVIEW_SIZE + 1) || +""
|
||||
File.binwrite(target, preview.byteslice(0, MAX_PREVIEW_SIZE))
|
||||
preview = File.binread(output.path, MAX_OUTPUT_SIZE + 1) || +""
|
||||
File.binwrite(target, preview.byteslice(0, MAX_OUTPUT_SIZE))
|
||||
target
|
||||
ensure
|
||||
output&.unlink
|
||||
|
||||
Reference in New Issue
Block a user