Tweak the UI (make it use the new user API) and bugfixes
This commit is contained in:
parent
ef5b32a33c
commit
7db48800a2
5 changed files with 20 additions and 42 deletions
|
@ -182,7 +182,7 @@ class BaseActivity(object):
|
|||
valid_kwargs = {}
|
||||
for k, v in kwargs.items():
|
||||
if v is None:
|
||||
break
|
||||
continue
|
||||
valid_kwargs[k] = v
|
||||
self._data.update(**valid_kwargs)
|
||||
|
||||
|
|
51
app.py
51
app.py
|
@ -75,13 +75,15 @@ app.config.update(
|
|||
)
|
||||
csrf = CSRFProtect(app)
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Hook up Flask logging with gunicorn
|
||||
gunicorn_logger = logging.getLogger('gunicorn.error')
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.handlers = gunicorn_logger.handlers
|
||||
root_logger.setLevel(gunicorn_logger.level)
|
||||
# gunicorn_logger = logging.getLogger('gunicorn.error')
|
||||
# root_logger = logging.getLogger()
|
||||
# root_logger.handlers = gunicorn_logger.handlers
|
||||
# root_logger.setLevel(gunicorn_logger.level)
|
||||
|
||||
SIG_AUTH = HTTPSigAuth(ID+'#main-key', KEY.privkey)
|
||||
|
||||
|
@ -460,6 +462,7 @@ def nodeinfo():
|
|||
'usage': {'users': {'total': 1}, 'localPosts': DB.outbox.count()},
|
||||
'metadata': {
|
||||
'sourceCode': 'https://github.com/tsileo/microblog.pub',
|
||||
'nodeName': f'@{USERNAME}@{DOMAIN}',
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
@ -482,16 +485,16 @@ def wellknown_nodeinfo():
|
|||
def wellknown_webfinger():
|
||||
"""Enable WebFinger support, required for Mastodon interopability."""
|
||||
resource = request.args.get('resource')
|
||||
if resource not in ["acct:"+USERNAME+"@"+DOMAIN, ID]:
|
||||
if resource not in [f'acct:{USERNAME}@{DOMAIN}', ID]:
|
||||
abort(404)
|
||||
|
||||
out = {
|
||||
"subject": "acct:"+USERNAME+"@"+DOMAIN,
|
||||
"subject": f'acct:{USERNAME}@{DOMAIN}',
|
||||
"aliases": [ID],
|
||||
"links": [
|
||||
{"rel": "http://webfinger.net/rel/profile-page", "type": "text/html", "href": BASE_URL},
|
||||
{"rel": "self", "type": "application/activity+json", "href": ID},
|
||||
{"rel":"http://ostatus.org/schema/1.0/subscribe","template": BASE_URL+"/authorize_follow?profile={uri}"},
|
||||
{"rel":"http://ostatus.org/schema/1.0/subscribe", "template": BASE_URL+"/authorize_follow?profile={uri}"},
|
||||
],
|
||||
}
|
||||
|
||||
|
@ -690,36 +693,9 @@ def admin():
|
|||
)
|
||||
|
||||
|
||||
@app.route('/new', methods=['GET', 'POST'])
|
||||
@app.route('/new', methods=['GET'])
|
||||
@login_required
|
||||
def new():
|
||||
if request.method == 'POST':
|
||||
reply = None
|
||||
if request.form.get('reply'):
|
||||
reply = activitypub.parse_activity(OBJECT_SERVICE.get(request.form.get('reply')))
|
||||
source = request.form.get('content')
|
||||
content, tags = parse_markdown(source)
|
||||
to = request.form.get('to')
|
||||
cc = [ID+'/followers']
|
||||
if reply:
|
||||
cc.append(reply.attributedTo)
|
||||
for tag in tags:
|
||||
if tag['type'] == 'Mention':
|
||||
cc.append(tag['href'])
|
||||
|
||||
note = activitypub.Note(
|
||||
cc=cc,
|
||||
to=[to if to else config.AS_PUBLIC],
|
||||
content=content, # TODO(tsileo): handle markdown
|
||||
tag=tags,
|
||||
source={'mediaType': 'text/markdown', 'content': source},
|
||||
inReplyTo=reply.id if reply else None
|
||||
)
|
||||
|
||||
create = note.build_create()
|
||||
print(create.to_dict())
|
||||
create.post_to_outbox()
|
||||
|
||||
reply_id = None
|
||||
content = ''
|
||||
if request.args.get('reply'):
|
||||
|
@ -804,8 +780,9 @@ def _user_api_get_note(from_outbox: bool = False):
|
|||
|
||||
|
||||
def _user_api_response(**kwargs):
|
||||
if request.args.get('redirect'):
|
||||
return redirect(request.args.get('redirect'))
|
||||
_redirect = _user_api_arg('redirect')
|
||||
if _redirect:
|
||||
return redirect(_redirect)
|
||||
|
||||
resp = flask_jsonify(**kwargs)
|
||||
resp.status_code = 201
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
version: '2'
|
||||
version: '3'
|
||||
services:
|
||||
celery:
|
||||
image: microblogpub:latest
|
||||
|
@ -7,7 +7,7 @@ services:
|
|||
- rabbitmq
|
||||
command: 'celery worker -l info -A tasks'
|
||||
environment:
|
||||
- MICROBLOGPUB_AMQP_BORKER=pyamqp://guest@rabbitmq//
|
||||
- MICROBLOGPUB_AMQP_BROKER=pyamqp://guest@rabbitmq//
|
||||
- MICROBLOGPUB_MONGODB_HOST=mongo:27017
|
||||
mongo:
|
||||
image: "mongo:latest"
|
||||
|
|
1
tasks.py
1
tasks.py
|
@ -19,7 +19,6 @@ from utils.linked_data_sig import generate_signature
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
app = Celery('tasks', broker=os.getenv('MICROBLOGPUB_AMQP_BROKER', 'pyamqp://guest@localhost//'))
|
||||
# app = Celery('tasks', broker='pyamqp://guest@rabbitmq//')
|
||||
SigAuth = HTTPSigAuth(ID+'#main-key', KEY.privkey)
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
<div id="container">
|
||||
{% include "header.html" %}
|
||||
<div id="new">
|
||||
<form action="" method="POST">
|
||||
<form action="/api/new_note" method="POST">
|
||||
<input type="hidden" name="redirect" value="/">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{% if reply %}<input type="hidden" name="reply" value="{{reply}}">{% endif %}
|
||||
<textarea name="content" rows="10" cols="50" autofocus="autofocus">{{ content }}</textarea>
|
||||
<div style="margin-top:20px;">
|
||||
|
|
Loading…
Reference in a new issue