From 11522b79f02d19cc4ec557c26b2532c912d90bbf Mon Sep 17 00:00:00 2001 From: sqozz Date: Mon, 2 Apr 2018 13:34:51 +0200 Subject: [PATCH] Add tracker validation for uploaded torrent --- indexer.py | 6 +++--- static/css/create.css | 8 ++++++++ static/js/create.js | 9 ++++++++- templates/create.html | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/indexer.py b/indexer.py index 083917e..df73d1f 100644 --- a/indexer.py +++ b/indexer.py @@ -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 {}").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/") diff --git a/static/css/create.css b/static/css/create.css index 10f088f..f3713f1 100644 --- a/static/css/create.css +++ b/static/css/create.css @@ -98,6 +98,14 @@ body { content: "*:"; } +.has-error { + color: #a94442; +} + +.has-success { + color: #3c763d; +} + .detectedFiles { max-height: 300px; overflow: auto; diff --git a/static/js/create.js b/static/js/create.js index 421cbd3..f005fa2 100644 --- a/static/js/create.js +++ b/static/js/create.js @@ -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) diff --git a/templates/create.html b/templates/create.html index c29f19a..8c7b7bb 100644 --- a/templates/create.html +++ b/templates/create.html @@ -7,6 +7,7 @@ vim: ts=2 noexpandtab {% block content %} +

{{ _("Create new torrent") }}

{% if errors %}