Add tracker validation for uploaded torrent

This commit is contained in:
sqozz 2018-04-02 13:34:51 +02:00
parent 439e284135
commit 11522b79f0
4 changed files with 20 additions and 4 deletions

View file

@ -117,14 +117,14 @@ def categorys():
@app.route("/create", methods=['GET','POST'])
def create():
if request.method == "GET":
return render_template("create.html", categories=categories.categories, errors=None)
return render_template("create.html", categories=categories.categories, errors=None, tracker=settings["valid_tracker"])
elif request.method == "POST":
newTorrent = createNewTorrent(request)
if len(newTorrent.errors) == 0:
message = _("Successfully created torrent <a href=\"/search?h={}\">{}</a>").format(newTorrent.fileid, newTorrent.fileid[:-20])
return render_template("create.html", categories=categories.categories, messages=[message])
return render_template("create.html", categories=categories.categories, messages=[message], tracker=settings["valid_tracker"])
else:
return render_template("create.html", categories=categories.categories, errors=newTorrent.errors)
return render_template("create.html", categories=categories.categories, errors=newTorrent.errors, tracker=settings["valid_tracker"])
@app.route("/download/<filename>")

View file

@ -98,6 +98,14 @@ body {
content: "*:";
}
.has-error {
color: #a94442;
}
.has-success {
color: #3c763d;
}
.detectedFiles {
max-height: 300px;
overflow: auto;

View file

@ -126,7 +126,6 @@ function getOrCreate(root, foldername, displayname, type) {
content.hidden = true
element.appendChild(content)
}
foobar = root
root = root.querySelector(".content")
root.appendChild(element)
return element
@ -210,12 +209,20 @@ function validateForm() {
subcategory = document.querySelector("#subcategory")
torrentname = document.querySelector(".torrent-form .name input")
description = document.querySelector(".torrent-form .description textarea")
tracker = document.querySelector(".trackerGroup .detectedTracker").parentElement
file_label = document.querySelector(".torrent-form .file")
category_label = document.querySelector(".torrent-form .category")
name_label = document.querySelector(".torrent-form .name")
description_label = document.querySelector(".torrent-form .description")
if(validtracker.indexOf(torrentObject.announce) < 0) {
valid = false
setError(tracker)
} else {
setSuccess(tracker)
}
if(file.value.length <= 0) {
valid = false
setError(file_label)

View file

@ -7,6 +7,7 @@ vim: ts=2 noexpandtab
{% block content %}
<link href="{{ url_for("static", filename="css/create.css") }}" rel="stylesheet">
<script src="{{ url_for("static", filename="js/create.js") }}"></script>
<script>var validtracker = "{{ ",".join(tracker) }}".split(",")</script>
<div>
<h2 class="headline">{{ _("Create new torrent") }}</h2>
{% if errors %}