MkForms App¶
- Author:
This Program create an interactive book online from pictures as pages source,
is structured with a client-server
squema, the backend is constructed as a Web Service with python and mysql.
In the Frontend the build is made with Vanilla Javascript and the connection motor is supported by fetch
What we need :
Web Server Apache, nginx, lighttpd,…
Database Server Mysql, Mariadb, PosgreSQL, mssql
python3.7+
Webserver with autoindex route to store and publish the images pages of books
SSL key and Certificates files
db management tool such as mssql-cli, mycli , dbext-vim, dbeaver
Install The Api Web Service¶
The Installation of the Web Service is very straight forward only we need to accomplish a few step in command line
Steps:
Build the skelton app
Connect to the db
Publish the Web Service
Install the database squeme¶
Need to download and install in mysql server
Download from https¶
mysql --user=user --password=pass database < db/bms.sql
Install the Api¶
Need to Download the source code of the api from
Download from https¶
Download the Api with git¶
git clone -b release https://github.com/ambagasdowa/bms_connector.git
Install the dependencies¶
python3 -m pip install uvicorn fastapi sqlalchemy pandas pymysql jinja2 python-multipart
Config setup¶
In the root directory of the api we need to create a file of configuration called config.py or rename to config_template.py with contents as follow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Hint
The above configuration creates:
Connection string for mysql link:
database: db_name,
user: db_user,
password: ‘db_pass’,
proc_exec: The procedure to execute
Routes to :
upload path : /var/www/images/public_html/assets/Panamericano/files/source/
fetch path : https://server/assets/Panamericano/files/source
tmp proccessing path : /tmp/book/
Tip
How the pathname is build ? for example if upload the file
custom_file_name.zip
Then the upload and fetch path are determinated by […]/source/[custom/file/name]/pages
The config.py
sections are db_connection and refers
to parameters for the database connection
Database Parameters¶
user
database
password
The section download_config
refer to parameters for storing the book-pages in jpg format
Book Parameters¶
Store Procedures¶
The SP must execute for earch new upload Book or a new linked user creation. The api already run the sp bms_proc_build_cache_inp_usr
when a new book is created
Server¶
To start the Api server run the next command :
uvicorn --reload --host [host.ipv4] bms_connector.main:app --ssl-keyfile=privkey.pem --ssl-certfile=fullchain.pem --ssl-keyfile-password=[password|None]
Letsencrypt :
/etc/letsencrypt/live/baizabal.xyz/
1 2 3 4 5 6 |
|
Note
The defautl port of uvicorn is 8000
Note
The method /books
replaces the deprecated method /items
Api use examples¶
Upload¶
/upload
Upload a book packet as a zip file
/upload Method for upload a new book[s]
book_name
: Name[s] of the book[s] , separate by commasmultipart
: upload zip file as multipart objecttoken
: Token authentication
1 2 3 4 5 6 7 |
|
Srcpositions¶
/srcpositions
Create forms in page
/srcpositions Method for create a new positions of a form [input,checkbox,…]
bms_books_id
: Id of bookbms_bookspage_id
: Id of pageinputType
: The type of the form [text,radio,checkbox]x1
: Position from left of Window Inner to left corner of form rectangley1
: Position from top of Window Inner top to top-left corner of form rectanglex2
: Position from left of Window Inner to right corner of form rectangley2
: Position from top of Window Inner top to bottom-left corner of form rectangle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Querys¶
For run this example you will need to install httpie and jq packages
sudo apt install httpie jq
https --verify=no baizabal.xyz:8000/books | jq | cat -l json
https --verify=no baizabal.xyz:8000/srcpos/4/6 | jq | cat -l json
other
https --verify=no baizabal.xyz:8000/items/4/1702 | jq | cat -l json
test
https --verify=no baizabal.xyz:8000/srcpositions/1 | jq | cat -l json