-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.py
63 lines (50 loc) · 1.56 KB
/
serve.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# serve.py
from flask import Flask
from flask import render_template
import zk
import json
from flask import request
# creates a Flask application, named app
app = Flask(__name__)
# a route where we will display a welcome message via an HTML template
@app.route("/")
def home():
message = "ZK UI"
return render_template('index.html', message=message)
@app.route("/<title>")
def note(title):
message = "ZK UI"
return render_template('index.html', message=message)
@app.route("/api/notes", methods=['GET'])
def list_notes():
search = request.args.get('search')
if search is not None:
return json.dumps(zk.search(search))
return json.dumps(zk.list())
@app.route("/api/notes/<title>", methods=['GET'])
def cat_note(title):
result = zk.cat(title)
return result
@app.route("/api/notes/<title>/open-browser", methods=['GET'])
def open_browser(title):
result = zk.open_browser(title)
return result
@app.route("/api/notes/<title>/open-code", methods=['GET'])
def open_code(title):
result = zk.open_code(title)
return result
@app.route("/api/notes/<title>/new-code", methods=['GET'])
def new_code(title):
result = zk.new_code(title)
return result
@app.route("/api/notes/<title>/remove", methods=['GET'])
def remove(title):
result = zk.remove(title)
return result
@app.route("/api/notes/<title>/link/<link_title>", methods=['GET'])
def link(title, link_title):
result = zk.link(title, link_title)
return result
# run the application
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0")