-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
35 lines (28 loc) · 897 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
# Add `lib' directory to the load path.
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'sinatra/base'
require 'tempfile'
require 'json'
require 'code_runner'
class CodeRunnerApp < Sinatra::Base
@@runner = CodeRunner.new
post '/' do
content_type :json
if (params['code'].nil? || params['code'][:filename].nil?) &&
(params['zip_file'].nil? || params['zip_file'][:filename].nil?)
status 400
body ({success: false, error: "Missing `code' or `zip_file' parameter. "}).to_json
return
end
begin
result = @@runner.run((params['code'] || params['zip_file'])[:tempfile].path)
status 200
body result.merge({success: true}).to_json
return
rescue CodeRunner::NoCompatibleRunner => e
status 400
body ({success: false, error: "File type not supported yet. "}).to_json
return
end
end
end