module ApplicationHelper
def flash_tag
return '' if flash.blank?
html = ''
flash.each do |name, msg|
if msg.is_a?(String)
html << "
"
html << ""
html << "#{msg}"
html << '
'
end
end
raw html
end
def aws_s3_json(directory)
aws_s3_hash = {
bucket: ENV['AWS_S3_BUCKET'],
region: ENV['AWS_S3_REGION'],
key_start: "#{ENV['AWS_S3_KEY_START']}#{directory}",
acl: ENV['AWS_S3_ACL'],
access_id: ENV['AWS_S3_ACCESS_ID'],
signature: aws_s3_signature(directory),
policy: aws_s3_policy(directory),
}
@aws_s3_json = aws_s3_hash.to_json
end
def froala_key
ENV['FROALA_KEY'];
end
private
def aws_s3_signature(directory)
Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest.new('sha1'),
ENV['AWS_S3_SECRET_KEY'], aws_s3_policy(directory)
)
).gsub("\n", '')
end
def aws_s3_policy(directory)
Base64.encode64(aws_s3_policy_data(directory).to_json).gsub("\n", '')
end
def aws_s3_policy_data(directory)
{
expiration: 10.hours.from_now.utc.iso8601,
conditions: [
['starts-with', '$key', "#{ENV['AWS_S3_KEY_START']}#{directory}"],
%w(starts-with $x-requested-with xhr),
['content-length-range', 0, 20.megabytes],
['starts-with', '$content-type', ''],
{bucket: ENV['AWS_S3_BUCKET']},
{acl: ENV['AWS_S3_ACL']},
{success_action_status: '201'}
]
}
end
end