@@ -24,9 +23,9 @@
{% else %}
diff --git a/BDSM/toot.py b/BDSM/toot.py
index c0efba5..bcc8e06 100644
--- a/BDSM/toot.py
+++ b/BDSM/toot.py
@@ -3,7 +3,7 @@
from mastodon import Mastodon
from tenacity import *
from BDSM import db
-from BDSM.models import Other, Toot, Tag, Media, Emoji, Poll
+from BDSM.models import Other, Toot, Tag, Media, Emoji, Poll, Settings
import sys
import dateutil.parser
@@ -40,8 +40,9 @@ def app_login(url):
return mastodon, user
def get_context(url, toot_id):
- mastodon, user = app_login(url)
- acct = mastodon.me().acct
+ mastodon, _ = app_login(url)
+ settings = Settings.query.first()
+ acct = settings.account
context = mastodon.status_context(toot_id)
statuses = []
statuses= context['ancestors'] + context['descendants']
diff --git a/BDSM/views.py b/BDSM/views.py
index d0a9570..7969828 100644
--- a/BDSM/views.py
+++ b/BDSM/views.py
@@ -7,7 +7,7 @@ from flask import render_template, request, url_for, redirect, flash, abort
from flask_sqlalchemy import Pagination
from BDSM import app, db
from BDSM.models import Media, Poll, Settings, Toot, Emoji, Other
-from BDSM.toot import app_register, archive_toot, get_context
+from BDSM.toot import app_login, app_register, archive_toot, get_context
from mastodon import Mastodon
from types import SimpleNamespace
from datetime import timezone
@@ -32,6 +32,21 @@ def index():
return render_template('view.html', toots=toots, pagination=toots_, path=path)
+@app.route('/favourited', methods=['GET', 'POST'])
+def favourited():
+ settings = Settings.query.first()
+ if settings == None:
+ return redirect(url_for('settings'))
+ else:
+ page = request.args.get('page', 1, type=int)
+ toots_ = Toot.query.order_by(Toot.created_at.desc()).paginate(page=page, per_page=50)
+ toots = process_toot(toots_)
+ path=SimpleNamespace()
+ path.path = "favourited"
+ path.args = {}
+
+ return render_template('view.html', toots=toots, pagination=toots_, path=path)
+
@app.route('/search', methods=['GET', 'POST'])
def search():
if request.method == 'POST':
@@ -106,20 +121,19 @@ def grab(toot_id):
@app.route('/settings', methods=['GET', 'POST'])
def settings():
if request.method == 'POST':
- account = request.form['account']
+ domain = request.form['domain']
timezone = request.form['timezone']
- if not account or len(account) > 30:
+ if not domain or len(domain) > 50:
flash('无效输入')
return redirect(url_for('settings'))
settings = Settings.query.first()
if settings == None:
- settings = Settings(account=account, timezone=timezone)
+ settings = Settings(domain=domain, timezone=timezone)
db.session.add(settings)
else:
- settings.account = account
settings.timezone = timezone
db.session.commit()
@@ -137,11 +151,10 @@ def settings():
def register():
settings = Settings.query.first()
if settings == None:
- flash('请先输入用户名!')
+ flash('请先输入站点地址!')
return redirect(url_for('settings'))
else:
- account = settings.account[1:]
- username, domain = account.split("@")
+ domain = settings.domain
url = "https://" + domain
if request.method == 'POST':
@@ -149,6 +162,11 @@ def register():
mastodon = Mastodon(client_id='pyBDSM_clientcred.secret', api_base_url=url)
mastodon.log_in(code=token, to_file='user.secret', scopes=['read'])
+ mastodon, _ = app_login(url)
+ account = mastodon.me().acct
+ settings.account = account
+ db.session.commit()
+
if os.path.isfile('user.secret'):
flash('应用已授权!')
return redirect(url_for('settings'))
@@ -168,8 +186,7 @@ def archive():
settings = Settings.query.first()
if request.method == 'POST':
archive_match = request.form.getlist("archive_match")
- account = settings.account[1:]
- username, domain = account.split("@")
+ domain = settings.domain
url = "https://" + domain
archive_toot(url, archive_match)