Files are now stored as a hash from a uuid to preserve uniqueness
Server prints out the submitted data
This commit is contained in:
parent
4ba2e1168f
commit
9ec244d9f3
30
indexer.py
30
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()
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,14 @@ vim: ts=2 noexpandtab
|
||||
<script src="{{ url_for("static", filename="js/create.js") }}"></script>
|
||||
<div>
|
||||
<h2 class="headline">{{ getLocalString(language, "create_new_torrent") }}</h2>
|
||||
<!--
|
||||
{% if errors %}
|
||||
{% for error in errors %}
|
||||
<div class="alert alert-danger alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<strong>Warning!</strong> Better check yourself, you're not looking too good.
|
||||
<span class="message">{{ error }}</span>
|
||||
</div>
|
||||
-->
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<form action="/create" method="post" enctype="multipart/form-data">
|
||||
<div class="row">
|
||||
@ -30,12 +32,13 @@ vim: ts=2 noexpandtab
|
||||
<strong>{{ getLocalString(language, "category") }}</strong>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="row row-container">
|
||||
<div class="col-md-6 category-column">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
|
||||
<span class="text">{{ getLocalString(language, "category") }}</span>
|
||||
<span class="caret"></span>
|
||||
<input type="hidden" name="category">
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
|
||||
{% for category in sorted(categories.keys()) %}
|
||||
@ -44,11 +47,12 @@ vim: ts=2 noexpandtab
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-6 subcategory-column">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true" disabled>
|
||||
<span class="text">{{ getLocalString(language, "subcategory") }}</span>
|
||||
<span class="caret"></span>
|
||||
<input type="hidden" name="subcategory">
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
|
||||
</ul>
|
||||
@ -97,7 +101,9 @@ vim: ts=2 noexpandtab
|
||||
<textarea name="description" class="form-control" rows="10"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> {{ getLocalString(language, "create") }}!</button>
|
||||
<div class="button-container">
|
||||
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> {{ getLocalString(language, "create") }}!</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock content%}
|
||||
|
Loading…
Reference in New Issue
Block a user