Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/stdin expected output from url #306

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'open-uri'

class SubmissionsController < ApplicationController
before_action :authorize_request, only: [:index, :destroy]
before_action :check_maintenance, only: [:create, :destroy]
Expand Down Expand Up @@ -181,12 +183,29 @@ def submission_params(params)
)

submission_params[:additional_files] = Base64Service.decode(submission_params[:additional_files])

incoming_stdin = params[:stdin]
if @base64_encoded
incoming_stdin = Base64Service.decode(params[:stdin])
end
if Config::FILE_BASE_URL
if incoming_stdin and incoming_stdin.start_with?(Config::FILE_BASE_URL)
incoming_stdin = open(incoming_stdin).read
end
end
incoming_expected_output = params[:expected_output]
if @base64_encoded
incoming_expected_output = Base64Service.decode(params[:expected_output])
end
if Config::FILE_BASE_URL
if incoming_expected_output and incoming_expected_output.start_with?(Config::FILE_BASE_URL)
incoming_expected_output = open(incoming_expected_output).read
end
end
if @base64_encoded
submission_params[:source_code] = Base64Service.decode(submission_params[:source_code])
submission_params[:stdin] = Base64Service.decode(submission_params[:stdin])
submission_params[:expected_output] = Base64Service.decode(submission_params[:expected_output])
end
submission_params[:stdin] = incoming_stdin
submission_params[:expected_output] = incoming_expected_output

submission_params
end
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module Config
USE_DOCS_AS_HOMEPAGE = ENV["USE_DOCS_AS_HOMEPAGE"] == "true"
ALLOW_ENABLE_NETWORK = ENV["ALLOW_ENABLE_NETWORK"] != "false"
ENABLE_NETWORK = ENV["ENABLE_NETWORK"] == "true"
FILE_BASE_URL = ENV["FILE_BASE_URL"].presence

def self.config_info
@@default_confg ||= {
Expand Down Expand Up @@ -82,7 +83,8 @@ def self.config_info
"submission_cache_duration": SUBMISSION_CACHE_DURATION,
"use_docs_as_homepage": USE_DOCS_AS_HOMEPAGE,
"allow_enable_network": ALLOW_ENABLE_NETWORK,
"enable_network": ENABLE_NETWORK
"enable_network": ENABLE_NETWORK,
"file_base_url": FILE_BASE_URL
}
end
end
9 changes: 8 additions & 1 deletion judge0.conf
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ SUBMISSION_CACHE_DURATION=
# If true the documentation page will be used as a homepage, otherwise, the
# homepage will be empty. You can always access the documentation page via /docs.
# Default: false
USE_DOCS_AS_HOMEPAGE=
USE_DOCS_AS_HOMEPAGE=true


################################################################################
Expand Down Expand Up @@ -356,3 +356,10 @@ RAILS_SERVER_PROCESSES=
# Secret key base for production, if not set it will be randomly generated
# Default: randomly generated
SECRET_KEY_BASE=

################################################################################
# STDIN EXPECTED_OUTPUR Url Configuration
################################################################################
# Specify Rails environment: production or development
# Default: empty
FILE_BASE_URL=https://d3dyfaf3iutrxo.cloudfront.net/