From: W. Trevor King Date: Sat, 20 Sep 2014 20:17:50 +0000 (-0700) Subject: nmhive.py: Add GET/POST /mid/ X-Git-Tag: v0.1.0~32 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=aa5e782a237da554e74ae0a15b713837d7112a27;p=nmhive.git nmhive.py: Add GET/POST /mid/ So the bookmarklet can get and set tags on a given message. This currently just uses an in-memory store, but eventually we'll drop notmuch in on the backend. --- diff --git a/nmhive.py b/nmhive.py index 6f12084..08c61fc 100755 --- a/nmhive.py +++ b/nmhive.py @@ -13,6 +13,38 @@ app = flask.Flask(__name__) flask_cors.CORS(app) +_TAGS = {} + + +@app.route('/mid/', methods=['GET', 'POST']) +def message_id_tags(message_id): + if flask.request.method == 'POST': + tags = _TAGS.get(message_id, set()) + new_tags = tags.copy() + for change in flask.request.get_json(): + if change.startswith('+'): + new_tags.add(change[1:]) + elif change.startswith('-'): + try: + new_tags.remove(change[1:]) + except KeyError: + return flask.Response(status=400) + else: + return flask.Response(status=400) + _TAGS[message_id] = new_tags + return flask.Response( + response=json.dumps(sorted(new_tags)), + mimetype='application/json') + elif flask.request.method == 'GET': + try: + tags = _TAGS[message_id] + except KeyError: + return flask.Response(status=404) + return flask.Response( + response=json.dumps(sorted(tags)), + mimetype='application/json') + + @app.route('/gmane//', methods=['GET']) def gmane_message_id(group, article): url = 'http://download.gmane.org/{}/{}/{}'.format(