From 9ec244d9f363e5f15086ecdf6d1a12bbcdca51c6 Mon Sep 17 00:00:00 2001 From: sqozz Date: Sun, 15 Feb 2015 04:51:27 +0100 Subject: [PATCH] Files are now stored as a hash from a uuid to preserve uniqueness Server prints out the submitted data --- indexer.py | 30 ++++++++++++++++++++++-------- static/css/create.css | 16 ++++++++++++++++ static/js/create.js | 2 ++ templates/create.html | 20 +++++++++++++------- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/indexer.py b/indexer.py index 2d5ff5e..6930ba7 100644 --- a/indexer.py +++ b/indexer.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 #/* vim:set ts=2 set noexpandtab */ -import json +import json, uuid, hashlib from flask import Flask, render_template, url_for, request from werkzeug import secure_filename app = Flask(__name__) @@ -20,13 +20,11 @@ def create(): if request.method == "GET": return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=None) elif request.method == "POST": - uploadfile = request.files["torrentFile"] - filename = secure_filename(uploadfile.filename) - # TODO: Create unique filename so that existing files doesn't get overwritten - uploadfile.save("torrentFiles/" + filename) - # TODO: Process inputdate from the form and save it to the (until now) non-existing DB - print(request.form["name"]) - return "\o/" + errors = createNewTorrent(request) + if errors == None: + return "It's allright" + else: + return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=errors) @app.route("/search", methods=['GET']) def search(): @@ -51,6 +49,22 @@ def getLocalString(language, descriptor): else: return descriptor +def createNewTorrent(reuqest): + uploadfile = request.files["torrentFile"] + filename = secure_filename(uploadfile.filename) + + h = hashlib.sha256() + h.update((str(uuid.uuid4()) + filename).encode()) + safeFilename = h.hexdigest() + uploadfile.save("torrentFiles/" + safeFilename) + print("=== CREATE NEW TORRENT FILE ===") + print( "Name: " + request.form["name"] ) + print( "Torrent file: " + safeFilename ) + print( "Category: " + request.form["category"] ) + print( "Subcategory: " + request.form["subcategory"] ) + print( "Description: " + request.form["description"] ) + # TODO: Process inputdate from the form and save it to the (until now) non-existing DB + return ["Error1", "Error2"] if __name__ == "__main__": init() diff --git a/static/css/create.css b/static/css/create.css index f369a76..a468834 100644 --- a/static/css/create.css +++ b/static/css/create.css @@ -1,3 +1,19 @@ +.category-column { + padding-right: 5px; +} + +.subcategory-column { + padding-left: 5px; +} + +.row.row-container { + margin-bottom: 0px; +} + +.button-container { + padding-right: 20px; + padding-left: 20px; +} /* Links */ a, diff --git a/static/js/create.js b/static/js/create.js index e899972..1ab1679 100644 --- a/static/js/create.js +++ b/static/js/create.js @@ -92,6 +92,8 @@ function setButtonToFilename(event) { // Sets the text of a given dropdown-button to a given value function setDropdownButtonText(text, dropdownButton) { var dropdownTextSpan = dropdownButton.getElementsByClassName("text")[0] + dropdownHiddenValue = dropdownButton.getElementsByTagName("input")[0] + dropdownHiddenValue.setAttribute("value", getDescriptorByLocalString("english", text)) dropdownTextSpan.innerHTML = text } diff --git a/templates/create.html b/templates/create.html index 22d29af..0859cfc 100644 --- a/templates/create.html +++ b/templates/create.html @@ -9,12 +9,14 @@ vim: ts=2 noexpandtab

{{ getLocalString(language, "create_new_torrent") }}

- + {% endfor %} + {% endif %}
@@ -30,12 +32,13 @@ vim: ts=2 noexpandtab {{ getLocalString(language, "category") }}
-
-
+
+
-
+
- +
+ +
{% endblock content%}