Add success and duplicate message

This commit is contained in:
sqozz 2017-12-29 01:47:39 +01:00
parent 2256e6f2de
commit 09be31db82
2 changed files with 19 additions and 9 deletions

View File

@ -4,7 +4,7 @@ import json, uuid, hashlib, sqlite3, base64
from hashlib import sha1
import bencoder
import requests
from flask import Flask, render_template, url_for, request, send_file
from flask import Flask, render_template, url_for, request, send_file, redirect
from werkzeug import secure_filename
app = Flask(__name__)
strings = None
@ -24,11 +24,12 @@ def create():
if request.method == "GET":
return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=None)
elif request.method == "POST":
errors = createNewTorrent(request)
if errors == None:
return "It's allright"
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", language="english", categories=settings["categories"], strings=strings, messages=[message])
else:
return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=errors)
return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=newTorrent.errors)
@app.route("/download/<filename>")
def download(filename):
@ -144,13 +145,13 @@ def createNewTorrent(reuqest):
newTFile.metadata.writeToDb(connection.cursor())
connection.commit()
connection.close()
return ["Success"]
except sqlite3.IntegrityError as e:
print(e)
return ["Torrent <a href=\"/search?h={}\">{}</a> does already exist".format(info_hash, info_hash[:-20])]
newTFile.errors = ["Torrent <a href=\"/search?h={}\">{}</a> already exists".format(info_hash, info_hash[:-20])]
except Exception as e:
print(e)
return ["Unknown error in creation"]
newTFile.errors = ["Unknown error in creation"]
return newTFile
class Metadata():
def __init__(self, fileid):
@ -175,6 +176,7 @@ class Metadata():
c.execute("INSERT INTO metadata(fileid, created_by, creation_date, announce_url, source, torrentsize, name, private) VALUES(:fileid, :created_by, :creation_date, :announce_url, :source, :torrentsize, :name, :private)", { 'fileid' : self.fileid, 'created_by' : b64created_by, 'creation_date' : self.creation_date, 'announce_url' : b64announce_url, 'source' : b64source , 'torrentsize' : self.torrentsize, 'name' : b64name, 'private' : self.private})
class TorrentFile():
errors = []
fileid = None
name = None
category = None

View File

@ -17,6 +17,14 @@ vim: ts=2 noexpandtab
</div>
{% endfor %}
{% endif %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<span class="message">{{ message|safe }}</span>
</div>
{% endfor %}
{% endif %}
<form class="form-horizontal" action="/create" method="post" enctype="multipart/form-data" onsubmit="return validateForm()">
<div class="form-group">
<label for="inputTorrentFile" class="col-sm-3 control-label">{{ getLocalString(language, "torrent_file") }}</label>