Feature #8959 » preview-limits-configurable.patch
| config/configuration.yml.example | ||
|---|---|---|
|
# 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
|
||
| lib/redmine/configuration.rb | ||
|---|---|---|
|
'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
|
||
| lib/redmine/markdownizer.rb | ||
|---|---|---|
|
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)
|
||
| ... | ... | |
|
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?
|
||
| ... | ... | |
|
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
|
||