lib/kanoko/application/convert.rb in kanoko-0.3.0 vs lib/kanoko/application/convert.rb in kanoko-0.3.1
- old
+ new
@@ -43,27 +43,32 @@
EXT_MAP = IMAGE_TYPES.each_with_object({}) do |i, h|
i.extensions.each do |ext|
h[ext] = i.to_s
end
end
+ QUERY_REGEXP = /\?.*/
# /123abc456def=/resize/200x200/crop/100x100/path/to/src
get '/:hash/*' do
# REQUEST_URI dependent on unicorn.
# request.path should be use only testing
- raw_request_uri = env["REQUEST_URI"] || request.path
+ raw_request_uri = if env["REQUEST_URI"]
+ env["REQUEST_URI"]
+ else
+ "#{request.path}#{request.params.empty? ? "" : "?#{request.query_string}"}"
+ end
request_params = raw_request_uri.split('/').tap(&:shift)
hash = request_params.shift
unless 0 < request_params.length
logger.error "invalid url #{request_uri}"
return 400
end
list = Kanoko::Application::Convert::Function.list
convert_options = []
arguments = []
- to_ext = File.extname(request_params.last)[1..-1]
+ to_ext = File.extname(request_params.last).sub(QUERY_REGEXP, '')[1..-1]
while id = request_params.shift.to_sym
if id == :to
to_ext = request_params.shift
arguments << id << to_ext
elsif list.include?(id)
@@ -99,16 +104,17 @@
t = TYPE_MAP[res.content_type]
src_type = if t
"#{t}:"
else
""
- end
+ end
dst_name = if to_ext.nil?
"dst"
else
["dst", ".#{to_ext}"]
- end
+ end
+
Tempfile.create(dst_name) do |dst_file|
system_command = [
{ "OMP_NUM_THREADS" => "1" },
'convert',
'-depth', '8',