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']) @app.route("/create", methods=['GET','POST'])
def create(): def create():
if request.method == "GET": 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": elif request.method == "POST":
newTorrent = createNewTorrent(request) newTorrent = createNewTorrent(request)
if len(newTorrent.errors) == 0: if len(newTorrent.errors) == 0:
message = _("Successfully created torrent <a href=\"/search?h={}\">{}</a>").format(newTorrent.fileid, newTorrent.fileid[:-20]) 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: 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>") @app.route("/download/<filename>")

View file

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

View file

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

View file

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