def new_message():
"""
Post a new message.
This endpoint is requires a valid user token.
"""
msg = Message(user_id=g.jwt_claims['user_id'])
msg.from_dict(request.get_json(), partial_update=False)
msg.html = '...'
db.session.add(msg)
db.session.commit()
r = jsonify(msg.to_dict())
r.status_code = 201
r.headers['Location'] = url_for('get_message', id=msg.id)
# render the markdown and expand the links in a background task
if app.config['TESTING']:
# for unit tests, render synchronously
render_message(msg.id)
else:
# asynchronous rendering
render_thread = threading.Thread(target=render_message,
args=(msg.id,))
render_thread.start()
return r
评论列表
文章目录