Add success and duplicate message
This commit is contained in:
parent
2256e6f2de
commit
09be31db82
20
indexer.py
20
indexer.py
|
@ -4,7 +4,7 @@ import json, uuid, hashlib, sqlite3, base64
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
import bencoder
|
import bencoder
|
||||||
import requests
|
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
|
from werkzeug import secure_filename
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
strings = None
|
strings = None
|
||||||
|
@ -24,11 +24,12 @@ def create():
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=None)
|
return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=None)
|
||||||
elif request.method == "POST":
|
elif request.method == "POST":
|
||||||
errors = createNewTorrent(request)
|
newTorrent = createNewTorrent(request)
|
||||||
if errors == None:
|
if len(newTorrent.errors) == 0:
|
||||||
return "It's allright"
|
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:
|
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>")
|
@app.route("/download/<filename>")
|
||||||
def download(filename):
|
def download(filename):
|
||||||
|
@ -144,13 +145,13 @@ def createNewTorrent(reuqest):
|
||||||
newTFile.metadata.writeToDb(connection.cursor())
|
newTFile.metadata.writeToDb(connection.cursor())
|
||||||
connection.commit()
|
connection.commit()
|
||||||
connection.close()
|
connection.close()
|
||||||
return ["Success"]
|
|
||||||
except sqlite3.IntegrityError as e:
|
except sqlite3.IntegrityError as e:
|
||||||
print(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:
|
except Exception as e:
|
||||||
print(e)
|
newTFile.errors = ["Unknown error in creation"]
|
||||||
return ["Unknown error in creation"]
|
|
||||||
|
return newTFile
|
||||||
|
|
||||||
class Metadata():
|
class Metadata():
|
||||||
def __init__(self, fileid):
|
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})
|
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():
|
class TorrentFile():
|
||||||
|
errors = []
|
||||||
fileid = None
|
fileid = None
|
||||||
name = None
|
name = None
|
||||||
category = None
|
category = None
|
||||||
|
|
|
@ -17,6 +17,14 @@ vim: ts=2 noexpandtab
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% 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">×</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()">
|
<form class="form-horizontal" action="/create" method="post" enctype="multipart/form-data" onsubmit="return validateForm()">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="inputTorrentFile" class="col-sm-3 control-label">{{ getLocalString(language, "torrent_file") }}</label>
|
<label for="inputTorrentFile" class="col-sm-3 control-label">{{ getLocalString(language, "torrent_file") }}</label>
|
||||||
|
|
Loading…
Reference in a new issue