From 3dc40ea3dc9e84575c1927867e98693810e9561f Mon Sep 17 00:00:00 2001 From: James Wang Date: Sun, 3 Jan 2016 19:02:58 +0000 Subject: [PATCH] Fix file upload --- .gitignore | 2 +- server/api/problem.py | 9 ++------- server/config.py | 2 +- web/files/Binary.txt | 1 - web/files/Binary2.txt | 1 - web/files/example.txt | 1 - web/files/example2.txt | 1 - 7 files changed, 4 insertions(+), 13 deletions(-) delete mode 100644 web/files/Binary.txt delete mode 100644 web/files/Binary2.txt delete mode 100644 web/files/example.txt delete mode 100644 web/files/example2.txt diff --git a/.gitignore b/.gitignore index bb191d4..60a090c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ .secret_key .bundle/config logs/ -uploads/ +files/ # Object files *.o diff --git a/server/api/problem.py b/server/api/problem.py index d10a515..a790cad 100644 --- a/server/api/problem.py +++ b/server/api/problem.py @@ -37,14 +37,9 @@ def problem_add(): if len(filename) == 0: continue - folder = problem.name.replace(" ", "-") - folder_path = os.path.join(os.path.normpath(app.config["UPLOAD_FOLDER"]), folder) - if not os.path.exists(folder_path): - os.makedirs(folder_path) - - file_path = os.path.join(folder_path, filename) + file_path = os.path.join(app.config["UPLOAD_FOLDER"], filename) _file.save(file_path) - db_file = Files(problem.pid, file_path) + db_file = Files(problem.pid, "/".join(file_path.split("/")[2:])) db.session.add(db_file) db.session.commit() diff --git a/server/config.py b/server/config.py index a28a51f..eb5039e 100644 --- a/server/config.py +++ b/server/config.py @@ -15,7 +15,7 @@ SECRET_KEY = key SQLALCHEMY_DATABASE_URI = "mysql://root:i_hate_passwords@localhost/easyctf" SQLALCHEMY_TRACK_MODIFICATIONS = False -UPLOAD_FOLDER = os.path.normpath("files") +UPLOAD_FOLDER = os.path.normpath("../web/files") CTF_BEGIN = 0 # To be used later CTF_END = 0 # To be used later diff --git a/web/files/Binary.txt b/web/files/Binary.txt deleted file mode 100644 index 70cd0b9..0000000 --- a/web/files/Binary.txt +++ /dev/null @@ -1 +0,0 @@ -This is hard! I'm telling you! diff --git a/web/files/Binary2.txt b/web/files/Binary2.txt deleted file mode 100644 index d9ec9ae..0000000 --- a/web/files/Binary2.txt +++ /dev/null @@ -1 +0,0 @@ -Binary is not fun at all! diff --git a/web/files/example.txt b/web/files/example.txt deleted file mode 100644 index a061bc9..0000000 --- a/web/files/example.txt +++ /dev/null @@ -1 +0,0 @@ -This is an example file, and should be removed before the tournament starts. diff --git a/web/files/example2.txt b/web/files/example2.txt deleted file mode 100644 index 847fdf0..0000000 --- a/web/files/example2.txt +++ /dev/null @@ -1 +0,0 @@ -Hello World! How art thou?