Merge pull request #503 from rachmadaniHaryono/feature/server-perf
server update
This commit is contained in:
commit
13db573995
@ -108,7 +108,7 @@ Following are available os env config available for bukuserver.
|
|||||||
| SECRET_KEY | server secret key | string [default: os.urandom(24)] |
|
| SECRET_KEY | server secret key | string [default: os.urandom(24)] |
|
||||||
| URL_RENDER_MODE | url render mode | `full` or `netloc` [default: `full`] |
|
| URL_RENDER_MODE | url render mode | `full` or `netloc` [default: `full`] |
|
||||||
| DB_FILE | full path to db file | path string [default: standard path for buku] |
|
| DB_FILE | full path to db file | path string [default: standard path for buku] |
|
||||||
| DISABLE_FAVICON | disable favicon | boolean [default: `false`] |
|
| DISABLE_FAVICON | disable favicon | boolean [default: `true`] |
|
||||||
| OPEN_IN_NEW_TAB | url link open in new tab | boolean [default: `false`] |
|
| OPEN_IN_NEW_TAB | url link open in new tab | boolean [default: `false`] |
|
||||||
| REVERSE_PROXY_PATH | reverse proxy path | string |
|
| REVERSE_PROXY_PATH | reverse proxy path | string |
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ def search_bookmarks():
|
|||||||
'id': bookmark[0],
|
'id': bookmark[0],
|
||||||
'url': bookmark[1],
|
'url': bookmark[1],
|
||||||
'title': bookmark[2],
|
'title': bookmark[2],
|
||||||
'tags': list([_f for _f in bookmark[3].split(',') if _f]),
|
'tags': list(filter(lambda x: x, bookmark[3].split(','))),
|
||||||
'description': bookmark[4]
|
'description': bookmark[4]
|
||||||
}
|
}
|
||||||
result['bookmarks'].append(result_bookmark)
|
result['bookmarks'].append(result_bookmark)
|
||||||
@ -214,6 +214,18 @@ def search_bookmarks():
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def get_bool_from_env_var(key: str, default_value: bool) -> bool:
|
||||||
|
"""Get bool value from env var."""
|
||||||
|
value = os.getenv(key)
|
||||||
|
if value is None:
|
||||||
|
return default_value
|
||||||
|
if value.lower() in ['true', '1']:
|
||||||
|
return True
|
||||||
|
if value.lower() in ['false', '0']:
|
||||||
|
return False
|
||||||
|
return default_value
|
||||||
|
|
||||||
|
|
||||||
def create_app(db_file=None):
|
def create_app(db_file=None):
|
||||||
"""create app."""
|
"""create app."""
|
||||||
app = FlaskAPI(__name__)
|
app = FlaskAPI(__name__)
|
||||||
@ -225,12 +237,10 @@ def create_app(db_file=None):
|
|||||||
url_render_mode = views.DEFAULT_URL_RENDER_MODE
|
url_render_mode = views.DEFAULT_URL_RENDER_MODE
|
||||||
app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode
|
app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode
|
||||||
app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24)
|
app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24)
|
||||||
disable_favicon = os.getenv('BUKUSERVER_DISABLE_FAVICON', 'false')
|
|
||||||
app.config['BUKUSERVER_DISABLE_FAVICON'] = \
|
app.config['BUKUSERVER_DISABLE_FAVICON'] = \
|
||||||
False if disable_favicon.lower() in ['false', '0'] else bool(disable_favicon)
|
get_bool_from_env_var('BUKUSERVER_DISABLE_FAVICON', True)
|
||||||
open_in_new_tab = os.getenv('BUKUSERVER_OPEN_IN_NEW_TAB', 'false')
|
|
||||||
app.config['BUKUSERVER_OPEN_IN_NEW_TAB'] = \
|
app.config['BUKUSERVER_OPEN_IN_NEW_TAB'] = \
|
||||||
False if open_in_new_tab.lower() in ['false', '0'] else bool(open_in_new_tab)
|
get_bool_from_env_var('BUKUSERVER_OPEN_IN_NEW_TAB', False)
|
||||||
app.config['BUKUSERVER_DB_FILE'] = os.getenv('BUKUSERVER_DB_FILE') or db_file
|
app.config['BUKUSERVER_DB_FILE'] = os.getenv('BUKUSERVER_DB_FILE') or db_file
|
||||||
reverse_proxy_path = os.getenv('BUKUSERVER_REVERSE_PROXY_PATH')
|
reverse_proxy_path = os.getenv('BUKUSERVER_REVERSE_PROXY_PATH')
|
||||||
if reverse_proxy_path:
|
if reverse_proxy_path:
|
||||||
@ -335,7 +345,7 @@ class ApiBookmarkView(MethodView):
|
|||||||
result_bookmark = {
|
result_bookmark = {
|
||||||
'url': bookmark[1],
|
'url': bookmark[1],
|
||||||
'title': bookmark[2],
|
'title': bookmark[2],
|
||||||
'tags': list([_f for _f in bookmark[3].split(',') if _f]),
|
'tags': list(filter(lambda x: x, bookmark[3].split(','))),
|
||||||
'description': bookmark[4]
|
'description': bookmark[4]
|
||||||
}
|
}
|
||||||
if not request.path.startswith('/api/'):
|
if not request.path.startswith('/api/'):
|
||||||
@ -349,7 +359,7 @@ class ApiBookmarkView(MethodView):
|
|||||||
result = {
|
result = {
|
||||||
'url': bookmark[1],
|
'url': bookmark[1],
|
||||||
'title': bookmark[2],
|
'title': bookmark[2],
|
||||||
'tags': list([_f for _f in bookmark[3].split(',') if _f]),
|
'tags': list(filter(lambda x: x, bookmark[3].split(','))),
|
||||||
'description': bookmark[4]
|
'description': bookmark[4]
|
||||||
}
|
}
|
||||||
res = jsonify(result)
|
res = jsonify(result)
|
||||||
@ -431,7 +441,7 @@ class ApiBookmarkRangeView(MethodView):
|
|||||||
result['bookmarks'][i] = {
|
result['bookmarks'][i] = {
|
||||||
'url': bookmark[1],
|
'url': bookmark[1],
|
||||||
'title': bookmark[2],
|
'title': bookmark[2],
|
||||||
'tags': list([_f for _f in bookmark[3].split(',') if _f]),
|
'tags': list(filter(lambda x: x, bookmark[3].split(','))),
|
||||||
'description': bookmark[4]
|
'description': bookmark[4]
|
||||||
}
|
}
|
||||||
res = jsonify(result)
|
res = jsonify(result)
|
||||||
@ -505,7 +515,7 @@ class ApiBookmarkSearchView(MethodView):
|
|||||||
'id': bookmark[0],
|
'id': bookmark[0],
|
||||||
'url': bookmark[1],
|
'url': bookmark[1],
|
||||||
'title': bookmark[2],
|
'title': bookmark[2],
|
||||||
'tags': list([_f for _f in bookmark[3].split(',') if _f]),
|
'tags': list(filter(lambda x: x, bookmark[3].split(','))),
|
||||||
'description': bookmark[4]
|
'description': bookmark[4]
|
||||||
}
|
}
|
||||||
result['bookmarks'].append(result_bookmark)
|
result['bookmarks'].append(result_bookmark)
|
||||||
|
@ -6,6 +6,8 @@ from click.testing import CliRunner
|
|||||||
|
|
||||||
from bukuserver import server
|
from bukuserver import server
|
||||||
from bukuserver.response import response_template
|
from bukuserver.response import response_template
|
||||||
|
from bukuserver.server import get_bool_from_env_var
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'args,word',
|
'args,word',
|
||||||
@ -234,3 +236,18 @@ def test_bookmark_search(client):
|
|||||||
assert rd.get_json() == response_template['success']
|
assert rd.get_json() == response_template['success']
|
||||||
rd = client.get('/api/bookmarks')
|
rd = client.get('/api/bookmarks')
|
||||||
assert rd.get_json() == {'bookmarks': []}
|
assert rd.get_json() == {'bookmarks': []}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('env_val, exp_val', [
|
||||||
|
['true', True],
|
||||||
|
['false', False],
|
||||||
|
['0', False],
|
||||||
|
['1', True],
|
||||||
|
[None, True],
|
||||||
|
['random', True]
|
||||||
|
])
|
||||||
|
def test_get_bool_from_env_var(monkeypatch, env_val, exp_val):
|
||||||
|
key = 'BUKUSERVER_TEST'
|
||||||
|
if env_val is not None:
|
||||||
|
monkeypatch.setenv(key, env_val)
|
||||||
|
assert get_bool_from_env_var(key, True) == exp_val
|
||||||
|
Loading…
x
Reference in New Issue
Block a user