diff --git a/feedi/routes.py b/feedi/routes.py index bbd9c83..b5637d4 100644 --- a/feedi/routes.py +++ b/feedi/routes.py @@ -125,8 +125,8 @@ def autocomplete(): # we can reasonably assume this is a url options += [ - ('Add to feed', flask.url_for('entry_add', url=term), 'fas fa-download'), - ('View in reader', flask.url_for('entry_add', url=term, redirect=1), 'fas fa-book-reader'), + ('Add to feed', flask.url_for('entry_add', url=term), 'fas fa-download', 'POST'), + ('View in reader', flask.url_for('entry_add', url=term, redirect=1), 'fas fa-book-reader', 'POST'), ('Send to backlog', flask.url_for('entry_backlog_url', url=term), 'fas fa-archive', 'POST'), ('Discover feed', flask.url_for('feed_add', url=term), 'fas fa-rss'), ] @@ -485,8 +485,7 @@ def feed_sync(feed_name): return response -# this should be a .post but that complicates utilization from hyperscipt -@app.get("/entries/") +@app.post("/entries/") @login_required def entry_add(): """ @@ -495,16 +494,20 @@ def entry_add(): """ # TODO sanitize? url = flask.request.args['url'] + redirect = flask.request.args.get('redirect') try: entry = models.Entry.from_url(current_user.id, url) except Exception: - return redirect_response(url) + if redirect: + return redirect_response(url) + else: + return 'failed to parse entry', 500 db.session.add(entry) db.session.commit() - if flask.request.args.get('redirect'): + if redirect: return redirect_response(flask.url_for('entry_view', id=entry.id)) else: return '', 204 diff --git a/tests/test_routes.py b/tests/test_routes.py index 370a943..e52fff2 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -277,7 +277,7 @@ def test_add_external_entry(client): mock_request(content_url, body=body) # add a standalone entry for that url, check that browser redirects to view content - response = client.get( + response = client.post( '/entries/', query_string={'url': content_url, 'redirect': 1}, follow_redirects=True) assert response.status_code == 200 assert 'reclaiming-the-web' in response.text @@ -285,7 +285,7 @@ def test_add_external_entry(client): # add same url again, verify that redirected entry url is the same as before previous_entry_url = response.request.path - response = client.get( + response = client.post( '/entries/', query_string={'url': content_url, 'redirect': 1}, follow_redirects=True) assert response.status_code == 200 assert response.request.path == previous_entry_url