From b550da579665808ca284142b7c5f99836eaa7bb4 Mon Sep 17 00:00:00 2001 From: zema1 Date: Fri, 1 Dec 2017 21:53:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BD=BF=E7=94=A8Nginx=20X-A?= =?UTF-8?q?ccel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/nginx/common.conf | 7 ++++++- judge/languages.py | 36 ++++++++++++++++++++++++------------ problem/views/admin.py | 10 ++++++++-- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/deploy/nginx/common.conf b/deploy/nginx/common.conf index ecfd2513..8d26d084 100644 --- a/deploy/nginx/common.conf +++ b/deploy/nginx/common.conf @@ -9,6 +9,11 @@ location /api { client_max_body_size 200M; } +location /data/ { + internal; + alias /data/; # note that trailing slash +} + location /admin { root /app/dist/admin; try_files $uri $uri/ /index.html =404; @@ -17,4 +22,4 @@ location /admin { location / { root /app/dist; try_files $uri $uri/ /index.html =404; -} \ No newline at end of file +} diff --git a/judge/languages.py b/judge/languages.py index a1d67485..45eee2b9 100644 --- a/judge/languages.py +++ b/judge/languages.py @@ -95,12 +95,14 @@ _cpp_lang_spj_config = { } _java_lang_config = { - "template": """/*--PREPEND START--*/ -/*--PREPEND END--*/ -/*--TEMPLATE BEGIN--*/ -/*--TEMPLATE END--*/ -/*--APPEND START--*/ -/*--APPEND END--*/""", + "template": """//PREPEND BEGIN +//PREPEND END + +//TEMPLATE BEGIN +//TEMPLATE END + +//APPEND BEGIN +//APPEND END""", "compile": { "src_name": "Main.java", "exe_name": "Main", @@ -119,12 +121,14 @@ _java_lang_config = { _py2_lang_config = { - "template": """/*--PREPEND START--*/ -/*--PREPEND END--*/ -/*--TEMPLATE BEGIN--*/ -/*--TEMPLATE END--*/ -/*--APPEND START--*/ -/*--APPEND END--*/""", + "template": """//PREPEND BEGIN +//PREPEND END + +//TEMPLATE BEGIN +//TEMPLATE END + +//APPEND BEGIN +//APPEND END""", "compile": { "src_name": "solution.py", "exe_name": "solution.pyc", @@ -139,6 +143,14 @@ _py2_lang_config = { } } _py3_lang_config = { + "template": """//PREPEND BEGIN +//PREPEND END + +//TEMPLATE BEGIN +//TEMPLATE END + +//APPEND BEGIN +//APPEND END""", "compile": { "src_name": "solution.py", "exe_name": "__pycache__/solution.cpython-35.pyc", diff --git a/problem/views/admin.py b/problem/views/admin.py index 3116fe27..0e5045d7 100644 --- a/problem/views/admin.py +++ b/problem/views/admin.py @@ -6,7 +6,7 @@ import zipfile from wsgiref.util import FileWrapper from django.conf import settings -from django.http import StreamingHttpResponse +from django.http import StreamingHttpResponse, HttpResponse from account.decorators import problem_permission_required from judge.dispatcher import SPJCompiler @@ -67,8 +67,14 @@ class TestCaseAPI(CSRFExemptAPIView): with zipfile.ZipFile(file_name, "w") as file: for test_case in name_list: file.write(f"{test_case_dir}/{test_case}", test_case) - response = StreamingHttpResponse(FileWrapper(open(file_name, "rb")), content_type="application/zip") + if os.environ.get("OJ_ENV") == "production": + response = HttpResponse() + response["X-Accel-Redirect"] = file_name + else: + response = StreamingHttpResponse(FileWrapper(open(file_name, "rb")), content_type="application/octet-stream") + response["Content-Disposition"] = f"attachment; filename=problem_{problem.id}_test_cases.zip" + response["Content-Length"] = os.path.getsize(file_name) return response @problem_permission_required