1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 08:38:59 +00:00

moved bot and help pages into their own dirs

This commit is contained in:
Lynne Megido 2019-09-18 21:02:23 +10:00
parent d9447fcec7
commit 5dfb8766d6
8 changed files with 20 additions and 20 deletions

View file

@ -145,7 +145,7 @@ def bot_edit(id):
if request.method == "GET": if request.method == "GET":
dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor) dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
dc.execute("SELECT * FROM bots WHERE handle = %s", (id,)) dc.execute("SELECT * FROM bots WHERE handle = %s", (id,))
return render_template("bot_edit.html", bot = dc.fetchone(), error = session.pop('error', None), success = session.pop('success', None)) return render_template("bot/edit.html", bot = dc.fetchone(), error = session.pop('error', None), success = session.pop('success', None))
else: else:
# update stored settings # update stored settings
replies_enabled = 'replies' in request.form replies_enabled = 'replies' in request.form
@ -202,7 +202,7 @@ def bot_delete(id):
if bot_check(id): if bot_check(id):
if request.method == 'GET': if request.method == 'GET':
instance = id.split("@")[2] instance = id.split("@")[2]
return render_template("bot_delete.html", instance = instance) return render_template("bot/delete.html", instance = instance)
else: else:
# delete bot by deleting its credentials # delete bot by deleting its credentials
# FK constraint will delete bot # FK constraint will delete bot
@ -255,7 +255,7 @@ def bot_accounts(id):
c.close() c.close()
return render_template("bot_accounts.html", users = users, post_count = post_count) return render_template("bot/accounts.html", users = users, post_count = post_count)
@app.route("/bot/accounts/add", methods = ['GET', 'POST']) @app.route("/bot/accounts/add", methods = ['GET', 'POST'])
def bot_accounts_add(): def bot_accounts_add():
@ -263,14 +263,14 @@ def bot_accounts_add():
if session['step'] == 1: if session['step'] == 1:
if request.form['account'] == session['bot']: if request.form['account'] == session['bot']:
error = "Bots cannot learn from themselves." error = "Bots cannot learn from themselves."
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
# look up user # look up user
handle_list = request.form['account'].split('@') handle_list = request.form['account'].split('@')
if len(handle_list) != 3: if len(handle_list) != 3:
# not formatted correctly # not formatted correctly
error = "Incorrectly formatted handle." error = "Incorrectly formatted handle."
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
username = handle_list[1] username = handle_list[1]
instance = handle_list[2] instance = handle_list[2]
@ -280,23 +280,23 @@ def bot_accounts_add():
r = requests.get("https://{}/api/v1/instance".format(instance), timeout=10) r = requests.get("https://{}/api/v1/instance".format(instance), timeout=10)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
error = "Couldn't connect to {}.".format(instance) error = "Couldn't connect to {}.".format(instance)
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
except: except:
error = "An unknown error occurred." error = "An unknown error occurred."
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
if r.status_code == 200: if r.status_code == 200:
j = r.json() j = r.json()
if 'contact_account' in j and 'is_pro' in j['contact_account']: if 'contact_account' in j and 'is_pro' in j['contact_account']:
# gab instance # gab instance
error = "Gab instances are not supported." error = "Gab instances are not supported."
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
# 1. download host-meta to find webfinger URL # 1. download host-meta to find webfinger URL
r = requests.get("https://{}/.well-known/host-meta".format(instance), timeout=10) r = requests.get("https://{}/.well-known/host-meta".format(instance), timeout=10)
if r.status_code != 200: if r.status_code != 200:
error = "Couldn't get host-meta." error = "Couldn't get host-meta."
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
# 2. use webfinger to find user's info page # 2. use webfinger to find user's info page
#TODO: use more reliable method #TODO: use more reliable method
@ -305,14 +305,14 @@ def bot_accounts_add():
uri = uri.format(uri = "{}@{}".format(username, instance)) uri = uri.format(uri = "{}@{}".format(username, instance))
except: except:
error = "Couldn't find WebFinger URL." error = "Couldn't find WebFinger URL."
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
r = requests.get(uri, headers={"Accept": "application/json"}, timeout=10) r = requests.get(uri, headers={"Accept": "application/json"}, timeout=10)
try: try:
j = r.json() j = r.json()
except: except:
error = "Invalid WebFinger response." error = "Invalid WebFinger response."
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
found = False found = False
for link in j['links']: for link in j['links']:
@ -323,7 +323,7 @@ def bot_accounts_add():
break break
if not found: if not found:
error = "Couldn't find a valid ActivityPub outbox URL." error = "Couldn't find a valid ActivityPub outbox URL."
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
# 3. format as outbox URL and check to make sure it works # 3. format as outbox URL and check to make sure it works
outbox = "{}/outbox?page=true".format(uri) outbox = "{}/outbox?page=true".format(uri)
@ -338,12 +338,12 @@ def bot_accounts_add():
return redirect("/bot/accounts/{}".format(session['bot']), 303) return redirect("/bot/accounts/{}".format(session['bot']), 303)
else: else:
error = "Couldn't access ActivityPub outbox. {} may require authenticated fetches, which FediBooks doesn't support yet.".format(instance) error = "Couldn't access ActivityPub outbox. {} may require authenticated fetches, which FediBooks doesn't support yet.".format(instance)
return render_template("bot_accounts_add.html", error = error) return render_template("bot/accounts_add.html", error = error)
else: else:
# new account add request # new account add request
session['step'] = 1 session['step'] = 1
return render_template("bot_accounts_add.html", error = session.pop('error', None)) return render_template("bot/accounts_add.html", error = session.pop('error', None))
@app.route("/bot/accounts/toggle/<id>") @app.route("/bot/accounts/toggle/<id>")
def bot_accounts_toggle(id): def bot_accounts_toggle(id):
@ -357,7 +357,7 @@ def bot_accounts_toggle(id):
def bot_accounts_delete(id): def bot_accounts_delete(id):
if request.method == 'GET': if request.method == 'GET':
instance = id.split("@")[2] instance = id.split("@")[2]
return render_template("bot_accounts_delete.html", user = id, instance = instance) return render_template("bot/accounts_delete.html", user = id, instance = instance)
else: else:
#NOTE: when user credential support is added, we'll need to delete the creds too #NOTE: when user credential support is added, we'll need to delete the creds too
c = mysql.connection.cursor() c = mysql.connection.cursor()
@ -384,10 +384,10 @@ def bot_create():
r = requests.get("https://{}/api/v1/instance".format(session['instance']), timeout=10) r = requests.get("https://{}/api/v1/instance".format(session['instance']), timeout=10)
except requests.ConnectionError: except requests.ConnectionError:
session['error'] = "Couldn't connect to https://{}.".format(session['instance']) session['error'] = "Couldn't connect to https://{}.".format(session['instance'])
return render_template("bot_create.html", error = session.pop('error', None)) return render_template("bot/create.html", error = session.pop('error', None))
except: except:
session['error'] = "An unknown error occurred while trying to load https://{}".format(session['instance']) session['error'] = "An unknown error occurred while trying to load https://{}".format(session['instance'])
return render_template("bot_create.html", error = session.pop('error', None)) return render_template("bot/create.html", error = session.pop('error', None))
if r.status_code == 200: if r.status_code == 200:
j = r.json() j = r.json()
@ -468,7 +468,7 @@ def bot_create():
# authentication error occurred # authentication error occurred
error = "Authentication failed." error = "Authentication failed."
session['step'] = 3 session['step'] = 3
return render_template("bot_create.html", error = error) return render_template("bot/create.html", error = error)
# authentication success!! # authentication success!!
c = mysql.connection.cursor() c = mysql.connection.cursor()
@ -498,7 +498,7 @@ def bot_create():
session['step'] = 1 session['step'] = 1
return render_template("bot_create.html", error = session.pop('error', None)) return render_template("bot/create.html", error = session.pop('error', None))
@app.route("/bot/create/back") @app.route("/bot/create/back")
def bot_create_back(): def bot_create_back():
@ -618,7 +618,7 @@ def report_bug():
@app.route("/help/settings") @app.route("/help/settings")
def help_settings(): def help_settings():
return render_template("help_settings.html") return render_template("help/settings.html")
@app.route("/img/bot_generic.png") @app.route("/img/bot_generic.png")
def img_bot_generic(): def img_bot_generic():