2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module SnippetsActions
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def raw
|
|
|
|
disposition = params[:inline] == 'false' ? 'attachment' : 'inline'
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
workhorse_set_content_type!
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
send_data(
|
2020-04-08 14:13:33 +05:30
|
|
|
convert_line_endings(blob.data),
|
2017-08-17 22:00:37 +05:30
|
|
|
type: 'text/plain; charset=utf-8',
|
|
|
|
disposition: disposition,
|
2020-04-08 14:13:33 +05:30
|
|
|
filename: Snippet.sanitized_file_name(blob.name)
|
2017-08-17 22:00:37 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def js_request?
|
|
|
|
request.format.js?
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def convert_line_endings(content)
|
|
|
|
params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n")
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
def check_repository_error
|
|
|
|
repository_errors = Array(snippet.errors.delete(:repository))
|
|
|
|
|
|
|
|
flash.now[:alert] = repository_errors.first if repository_errors.present?
|
|
|
|
recaptcha_check_with_fallback(repository_errors.empty?) { render :edit }
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|