Commit 261ca22e by John Doe

resize thumbnail pngs to save space

parent 529e3b06
......@@ -38,6 +38,7 @@ gem 'devise_token_auth'
gem 'devise_invitable'
gem 'omniauth'
gem 'oj' # fast json
gem 'mini_magick'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
......
......@@ -168,6 +168,7 @@ GEM
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_magick (4.7.2)
mini_portile2 (2.1.0)
minitest (5.10.2)
multi_json (1.12.1)
......@@ -354,6 +355,7 @@ DEPENDENCIES
httparty
jbuilder (~> 2.0)
jquery-rails
mini_magick
oj
omniauth
rack-cors
......
......@@ -7,9 +7,23 @@ class CreateDataView
def run(data_view_params, stream_ids, user, home_view=false)
# normal data view
@data_view = DataView.new(data_view_params.merge({owner: user}))
#resize thumbnail because client can upload any dimension
if(!@data_view.image.empty?)
metadata = "data:image/png;base64,"
base64_string = @data_view.image[metadata.size..-1]
blob = Base64.decode64(base64_string)
image = MiniMagick::Image.read(blob)
image.resize('200x100!')
image.format 'png'
scaled_image_bytes = image.to_blob
@data_view.image = metadata+Base64.strict_encode64(scaled_image_bytes)
end
# build nilm associations for permissions
begin
#retrieve nilms for every stream in this view
......
......@@ -50,12 +50,17 @@ class UpdateStream
# create or update DbDecimations for the
# specified DbStream
def __build_decimations(stream:, entry_group:)
if !entry_group.empty?
Rails.logger.warn("deleting decimations for #{stream.path}")
stream.db_decimations.destroy_all #remove existing decimations
end
entry_group.each do |entry|
level = entry[:path].match(UpdateStream.decimation_tag)[1].to_i
decim = stream.db_decimations.find_by_level(level)
decim ||= DbDecimation.new(db_stream: stream, level: level)
decim.update_attributes(entry[:attributes])
decim.save!
#decim.save!
end
end
......@@ -71,11 +76,11 @@ class UpdateStream
# use the metadata if present
unless element.update_attributes(entry[0] || {})
element.use_default_attributes
element.save!
Rails.logger.warn(stream_data)
Rails.logger.warn("corrupt metadata: #{stream.path}:"\
"e#{element.column}")
end
element.save!
end
end
......
......@@ -2,3 +2,6 @@
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
Rails.application.config.filter_parameters << lambda do |key, value|
value.replace('[BASE64 STRING OMITTED]') if key == 'redux_json' || key == 'image'
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment