2020-04-25 12:28:57 +08:00
|
|
|
import CustomConfig
|
2022-08-05 14:49:53 +08:00
|
|
|
import Database
|
2020-04-25 12:28:57 +08:00
|
|
|
|
2020-04-09 11:21:52 +08:00
|
|
|
from flask import Flask
|
|
|
|
from flask import g
|
|
|
|
from flask import render_template
|
|
|
|
from flask import url_for
|
|
|
|
from flask import request
|
2020-04-13 15:36:37 +08:00
|
|
|
from flask import abort
|
2020-04-18 12:49:48 +08:00
|
|
|
from flask import redirect
|
2020-04-09 11:21:52 +08:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2020-04-18 12:49:48 +08:00
|
|
|
# =============================================database
|
2020-04-09 11:21:52 +08:00
|
|
|
def get_db():
|
|
|
|
db = getattr(g, '_database', None)
|
|
|
|
if db is None:
|
2022-08-05 14:49:53 +08:00
|
|
|
db = g._database = Database.CreateDatabase()
|
2020-04-09 11:21:52 +08:00
|
|
|
return db
|
|
|
|
|
|
|
|
@app.teardown_appcontext
|
|
|
|
def close_connection(exception):
|
|
|
|
db = getattr(g, '_database', None)
|
|
|
|
if db is not None:
|
2022-08-05 14:49:53 +08:00
|
|
|
Database.CloseDatabase(db)
|
2020-04-12 16:02:20 +08:00
|
|
|
|
2020-04-18 12:49:48 +08:00
|
|
|
# =============================================route
|
2020-08-11 13:08:20 +08:00
|
|
|
|
|
|
|
# =========== default
|
|
|
|
|
2020-04-09 11:21:52 +08:00
|
|
|
@app.route('/', methods=['GET'])
|
2022-08-05 14:49:53 +08:00
|
|
|
def handle_nospec():
|
|
|
|
return redirect(url_for('handle_index'))
|
2020-04-18 12:49:48 +08:00
|
|
|
|
2022-08-05 14:49:53 +08:00
|
|
|
# =========== basic pages
|
|
|
|
|
|
|
|
@app.route('/index', methods=['GET'])
|
|
|
|
def handle_index():
|
|
|
|
return app.send_static_file("html/index.html")
|
|
|
|
|
|
|
|
@app.route('/script', methods=['GET'])
|
|
|
|
def handle_script():
|
|
|
|
return redirect(url_for('handle_index'))
|
|
|
|
|
|
|
|
@app.route('/array', methods=['GET'])
|
|
|
|
def handle_array():
|
|
|
|
return redirect(url_for('handle_index'))
|
|
|
|
|
|
|
|
@app.route('/environment', methods=['GET'])
|
|
|
|
def handle_environment():
|
|
|
|
return redirect(url_for('handle_index'))
|
2020-08-11 13:08:20 +08:00
|
|
|
|
2020-04-18 12:49:48 +08:00
|
|
|
@app.route('/help', methods=['GET'])
|
2022-08-05 14:49:53 +08:00
|
|
|
def handle_help():
|
|
|
|
return app.send_static_file("html/help.html")
|
2020-04-18 12:49:48 +08:00
|
|
|
|
2020-08-11 13:08:20 +08:00
|
|
|
@app.route('/about', methods=['GET'])
|
2022-08-05 14:49:53 +08:00
|
|
|
def handle_about():
|
|
|
|
return app.send_static_file("html/about.html")
|
2020-08-11 13:08:20 +08:00
|
|
|
|
2022-08-05 14:49:53 +08:00
|
|
|
# =========== viewer
|
|
|
|
# script and array should have at least 2 items splitted by slash(/)
|
|
|
|
# the first one is document id and the second one is the real CK_ID of viewing object.
|
|
|
|
# however, environment do not have this, environment only allow one item, the id of environment.
|
|
|
|
|
|
|
|
@app.route('/script/<path:script_path>', methods=['GET'])
|
|
|
|
def handle_script_viewer(script_path):
|
|
|
|
# check invalid url
|
|
|
|
if len(script_path.split('/')) < 2:
|
|
|
|
return redirect(url_for('handle_index'))
|
|
|
|
return app.send_static_file("html/viewer_script.html")
|
|
|
|
|
|
|
|
@app.route('/array/<path:array_path>', methods=['GET'])
|
|
|
|
def handle_array_viewer(array_path):
|
|
|
|
# check invalid url
|
|
|
|
if len(script_path.split('/')) < 2:
|
|
|
|
return redirect(url_for('handle_index'))
|
|
|
|
return app.send_static_file("html/viewer_array.html")
|
|
|
|
|
|
|
|
@app.route('/environment/<path:environment_path>', methods=['GET'])
|
|
|
|
def handle_environment_viewer(environment_path):
|
|
|
|
# check invalid url
|
|
|
|
if len(script_path.split('/')) > 1:
|
|
|
|
return redirect(url_for('handle_index'))
|
|
|
|
return app.send_static_file("html/viewer_environment.html")
|
2020-04-09 11:21:52 +08:00
|
|
|
|
2020-08-11 13:08:20 +08:00
|
|
|
# =========== viewer
|
|
|
|
|
2022-08-05 14:49:53 +08:00
|
|
|
@app.route('/api/index/getList', methods=['POST'])
|
|
|
|
def handle_api_index_getList(scriptPath):
|
|
|
|
return {
|
|
|
|
"document": [],
|
|
|
|
"script": [],
|
|
|
|
"array": [],
|
|
|
|
"environment": []
|
|
|
|
}
|
2020-04-13 12:35:41 +08:00
|
|
|
|
2022-08-05 14:49:53 +08:00
|
|
|
# =========== startup
|
2020-04-09 11:21:52 +08:00
|
|
|
def run():
|
|
|
|
app.run()
|
2020-08-11 13:08:20 +08:00
|
|
|
|