mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 23:05:10 +01:00
Search API endpoint
This commit is contained in:
24
digimarks.py
24
digimarks.py
@@ -482,6 +482,14 @@ def make_external(url):
|
|||||||
return urljoin(request.url_root, url)
|
return urljoin(request.url_root, url)
|
||||||
|
|
||||||
|
|
||||||
|
def _find_bookmarks(userkey, filter_text):
|
||||||
|
return Bookmark.select().where(
|
||||||
|
Bookmark.userkey == userkey,
|
||||||
|
(Bookmark.title.contains(filter_text) | Bookmark.url.contains(filter_text) | Bookmark.note.contains(filter_text)),
|
||||||
|
Bookmark.status == Bookmark.VISIBLE
|
||||||
|
).order_by(Bookmark.created_date.desc())
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
theme = themes[DEFAULT_THEME]
|
theme = themes[DEFAULT_THEME]
|
||||||
@@ -524,11 +532,7 @@ def get_bookmarks(userkey, filtermethod=None, sortmethod=None):
|
|||||||
filter_note = True
|
filter_note = True
|
||||||
|
|
||||||
if filter_text:
|
if filter_text:
|
||||||
bookmarks = Bookmark.select().where(
|
bookmarks = _find_bookmarks(userkey, filter_text)
|
||||||
Bookmark.userkey == userkey,
|
|
||||||
(Bookmark.title.contains(filter_text) | Bookmark.url.contains(filter_text) | Bookmark.note.contains(filter_text)),
|
|
||||||
Bookmark.status == Bookmark.VISIBLE
|
|
||||||
).order_by(Bookmark.created_date.desc())
|
|
||||||
elif filter_starred:
|
elif filter_starred:
|
||||||
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey,
|
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey,
|
||||||
Bookmark.starred).order_by(Bookmark.created_date.desc())
|
Bookmark.starred).order_by(Bookmark.created_date.desc())
|
||||||
@@ -595,6 +599,16 @@ def bookmark_json(userkey, urlhash):
|
|||||||
return jsonify(bookmark.to_dict())
|
return jsonify(bookmark.to_dict())
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/v1/<userkey>/search/<filter_text>')
|
||||||
|
def search_bookmark_titles_json(userkey, filter_text):
|
||||||
|
""" Serialise bookmark to json """
|
||||||
|
bookmarks = _find_bookmarks(userkey, filter_text)
|
||||||
|
result = []
|
||||||
|
for bookmark in bookmarks:
|
||||||
|
result.append(bookmark.to_dict())
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<userkey>/<urlhash>')
|
@app.route('/<userkey>/<urlhash>')
|
||||||
@app.route('/<userkey>/<urlhash>/edit')
|
@app.route('/<userkey>/<urlhash>/edit')
|
||||||
def editbookmark(userkey, urlhash):
|
def editbookmark(userkey, urlhash):
|
||||||
|
|||||||
Reference in New Issue
Block a user