-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
45 lines (35 loc) · 915 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
require_relative "lib/version"
require_relative "lib/image_resize_service"
require "sinatra"
require "newrelic_rpm"
require "debug" if Sinatra::Base.development?
get "/" do
status 200
body "Image Resizer service is running"
end
get "/version" do
VERSION
end
post "/image" do
image_file = params[:image_file]&.[](:tempfile)
halt 400, "no image file was provided" unless image_file.is_a?(Tempfile)
options = { width:, height: }.compact
resized_image = ImageResizeService.call(image_file, **options)
status 200
body resized_image
end
error MiniMagick::Error do
NewRelic::Agent.notice_error(env["sinatra.error"])
env["sinatra.error"].message
end
def width
value = params[:width]&.to_i
halt 400, "invalid width" if value && value <= 0
value
end
def height
value = params[:height]&.to_i
halt 400, "invalid height" if value && value <= 0
value
end