Merge pull request #271 from rachmadaniHaryono/feature/server
Feature/server
This commit is contained in:
commit
33fe72da3c
@ -1,34 +0,0 @@
|
|||||||
#### Install server
|
|
||||||
|
|
||||||
You need to have some packages before you install `bukuserver` on your server. So be sure to have `python3`, `python3-pip` , `python3-dev`, `libffi-dev` packages from your distribution.
|
|
||||||
|
|
||||||
##### Installing PIP, virtualenv and dependencies
|
|
||||||
|
|
||||||
```
|
|
||||||
$ python3 -m pip install --user --upgrade pip
|
|
||||||
$ python3 -m pip install --user virtualenv
|
|
||||||
$ python3 -m virtualenv env
|
|
||||||
$ source env/bin/activate
|
|
||||||
$ git clone https://github.com/jarun/Buku
|
|
||||||
$ cd Buku
|
|
||||||
$ pip3 install .[server]
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Installing buku and bukuserver from PIP
|
|
||||||
|
|
||||||
```
|
|
||||||
$ pip3 install buku[server]
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Webserver options
|
|
||||||
|
|
||||||
To run the server on host 127.0.0.1, port 5001, run following command:
|
|
||||||
|
|
||||||
$ bukuserver run --host 127.0.0.1 --port 5001
|
|
||||||
Visit `127.0.0.1:5001` in your browser to access your bookmarks.
|
|
||||||
|
|
||||||
See more option on `bukuserver run --help` and `bukuserver --help`
|
|
||||||
|
|
||||||
#### CAUTION
|
|
||||||
|
|
||||||
This snapshot of web APIs is indicative. The program APIs are bound to change and if you need these, you may have to adapt the APIs to the current signature/return type etc. We are NOT actively updating these whenever an API changes in the main program.
|
|
83
bukuserver/README.rst
Normal file
83
bukuserver/README.rst
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
Bukuserver
|
||||||
|
==========
|
||||||
|
|
||||||
|
Install server
|
||||||
|
--------------
|
||||||
|
|
||||||
|
You need to have some packages before you install `bukuserver` on your server.
|
||||||
|
So be sure to have `python3`, `python3-pip` , `python3-dev`, `libffi-dev` packages from your distribution.
|
||||||
|
|
||||||
|
Installing PIP, virtualenv and dependencies
|
||||||
|
-------------------------------------------
|
||||||
|
|
||||||
|
.. code:: shell
|
||||||
|
|
||||||
|
$ python3 -m pip install --user --upgrade pip
|
||||||
|
$ python3 -m pip install --user virtualenv
|
||||||
|
$ python3 -m virtualenv env
|
||||||
|
$ source env/bin/activate
|
||||||
|
$ git clone https://github.com/jarun/Buku
|
||||||
|
$ cd Buku
|
||||||
|
$ pip3 install .[server]
|
||||||
|
|
||||||
|
Installing buku and bukuserver from PIP
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
.. code:: shell
|
||||||
|
|
||||||
|
$ pip3 install buku[server]
|
||||||
|
|
||||||
|
Webserver options
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
To run the server on host 127.0.0.1, port 5001, run following command:
|
||||||
|
|
||||||
|
.. code:: shell
|
||||||
|
|
||||||
|
$ bukuserver run --host 127.0.0.1 --port 5001
|
||||||
|
|
||||||
|
Visit `127.0.0.1:5001` in your browser to access your bookmarks.
|
||||||
|
|
||||||
|
See more option on `bukuserver run --help` and `bukuserver --help`
|
||||||
|
|
||||||
|
Webserver Env config
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
Following are available os env config available for bukuserver.
|
||||||
|
|
||||||
|
+-----------------------+------------------------------------+
|
||||||
|
| Name (without prefix) | Value and description |
|
||||||
|
+-----------------------+------------------------------------+
|
||||||
|
| PER_PAGE | v: [:code:`10`]/(positive integer) |
|
||||||
|
| | |
|
||||||
|
| | Bookmark entry per page. |
|
||||||
|
+-----------------------+------------------------------------+
|
||||||
|
| SECRET_KEY | v: [(os.urandom(24))]/(string) |
|
||||||
|
| | |
|
||||||
|
| | Server secret key. |
|
||||||
|
+-----------------------+------------------------------------+
|
||||||
|
| URL_RENDER_MODE | v: [:code:`full`]/:code:`netloc` |
|
||||||
|
| | |
|
||||||
|
| | Url render mode. |
|
||||||
|
+-----------------------+------------------------------------+
|
||||||
|
|
||||||
|
Note: If any invalid input given, default value will be used
|
||||||
|
|
||||||
|
Note: to use it add `BUKUSERVER_` as prefix.
|
||||||
|
|
||||||
|
ie to set bukuserver to show 100 item per page run the following command
|
||||||
|
|
||||||
|
.. code::
|
||||||
|
|
||||||
|
$ # on linux
|
||||||
|
$ export BUKUSERVER_PER_PAGE=100
|
||||||
|
$ # on windows
|
||||||
|
$ SET BUKUSERVER_PER_PAGE=100
|
||||||
|
|
||||||
|
CAUTION
|
||||||
|
-------
|
||||||
|
|
||||||
|
This snapshot of web APIs is indicative.
|
||||||
|
The program APIs are bound to change and if you need these,
|
||||||
|
you may have to adapt the APIs to the current signature/return type etc.
|
||||||
|
We are NOT actively updating these whenever an API changes in the main program.
|
@ -33,6 +33,7 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
DEFAULT_PER_PAGE = 10
|
DEFAULT_PER_PAGE = 10
|
||||||
|
DEFAULT_URL_RENDER_MODE = 'full'
|
||||||
STATISTIC_DATA = None
|
STATISTIC_DATA = None
|
||||||
|
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ def bookmarks():
|
|||||||
default=int(
|
default=int(
|
||||||
current_app.config.get('BUKUSERVER_PER_PAGE', DEFAULT_PER_PAGE))
|
current_app.config.get('BUKUSERVER_PER_PAGE', DEFAULT_PER_PAGE))
|
||||||
)
|
)
|
||||||
|
url_render_mode = current_app.config['BUKUSERVER_URL_RENDER_MODE']
|
||||||
create_bookmarks_form = forms.CreateBookmarksForm()
|
create_bookmarks_form = forms.CreateBookmarksForm()
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
all_bookmarks = bukudb.get_rec_all()
|
all_bookmarks = bukudb.get_rec_all()
|
||||||
@ -131,6 +133,7 @@ def bookmarks():
|
|||||||
pagination=pagination,
|
pagination=pagination,
|
||||||
search_bookmarks_form=forms.SearchBookmarksForm(),
|
search_bookmarks_form=forms.SearchBookmarksForm(),
|
||||||
create_bookmarks_form=create_bookmarks_form,
|
create_bookmarks_form=create_bookmarks_form,
|
||||||
|
url_render_mode=url_render_mode,
|
||||||
)
|
)
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
url_data = create_bookmarks_form.url.data
|
url_data = create_bookmarks_form.url.data
|
||||||
@ -518,9 +521,14 @@ def view_statistic():
|
|||||||
def create_app(config_filename=None):
|
def create_app(config_filename=None):
|
||||||
"""create app."""
|
"""create app."""
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['BUKUSERVER_PER_PAGE'] = os.getenv(
|
per_page = int(os.getenv('BUKUSERVER_PER_PAGE', DEFAULT_PER_PAGE))
|
||||||
'BUKUSERVER_PER_PAGE', DEFAULT_PER_PAGE)
|
per_page = per_page if per_page > 0 else DEFAULT_PER_PAGE
|
||||||
app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SERVER_SECRET_KEY') or os.urandom(24)
|
app.config['BUKUSERVER_PER_PAGE'] = per_page
|
||||||
|
url_render_mode = os.getenv('BUKUSERVER_URL_RENDER_MODE', DEFAULT_URL_RENDER_MODE)
|
||||||
|
if url_render_mode not in ('full', 'netloc'):
|
||||||
|
url_render_mode = DEFAULT_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)
|
||||||
bukudb = BukuDb()
|
bukudb = BukuDb()
|
||||||
app.app_context().push()
|
app.app_context().push()
|
||||||
setattr(flask.g, 'bukudb', bukudb)
|
setattr(flask.g, 'bukudb', bukudb)
|
||||||
@ -530,6 +538,8 @@ def create_app(config_filename=None):
|
|||||||
"""Shell context definition."""
|
"""Shell context definition."""
|
||||||
return {'app': app, 'bukudb': bukudb}
|
return {'app': app, 'bukudb': bukudb}
|
||||||
|
|
||||||
|
app.jinja_env.filters['netloc'] = lambda x: urlparse(x).netloc # pylint: disable=no-member
|
||||||
|
|
||||||
Bootstrap(app)
|
Bootstrap(app)
|
||||||
# routing
|
# routing
|
||||||
app.add_url_rule('/api/tags', 'get_tags', get_tags, methods=['GET'])
|
app.add_url_rule('/api/tags', 'get_tags', get_tags, methods=['GET'])
|
||||||
|
@ -60,12 +60,18 @@
|
|||||||
{% for item in bookmarks %}
|
{% for item in bookmarks %}
|
||||||
<tr> <td style="overflow-wrap: break-word;">
|
<tr> <td style="overflow-wrap: break-word;">
|
||||||
<h3>
|
<h3>
|
||||||
|
{% if item.url|netloc %}
|
||||||
|
<img src='http://www.google.com/s2/favicons?domain={{item.url|netloc}}'/>
|
||||||
|
{% endif %}
|
||||||
<a href="{{item.url}}">{{item.title}}</a>
|
<a href="{{item.url}}">{{item.title}}</a>
|
||||||
<a href="{{url_for('bookmark_api-html', id=item.id)}}">
|
<a href="{{url_for('bookmark_api-html', id=item.id)}}">
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||||
</a>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
{% if url_render_mode == 'netloc' %} ({{item.url|netloc}}) {% endif %}
|
||||||
|
{% if not url_render_mode or url_render_mode == 'full' %}
|
||||||
<p><a href="{{item.url}}">{{item.url}}</a></p>
|
<p><a href="{{item.url}}">{{item.url}}</a></p>
|
||||||
|
{% endif %}
|
||||||
<p>{{item.description}}</p>
|
<p>{{item.description}}</p>
|
||||||
<p>
|
<p>
|
||||||
{% for tag in item.tags %}
|
{% for tag in item.tags %}
|
||||||
|
Loading…
Reference in New Issue
Block a user