-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainapp.py
43 lines (37 loc) · 1.17 KB
/
mainapp.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
from flask import Flask, request, jsonify, render_template, \
make_response
from paster import paste, get_content
import requests as req
app = Flask(__name__)
errors = {'405': 'Get method is not allowed !'}
@app.route('/api/documents')
def newdocument():
method = request.method
if method == 'POST':
content = request.form['content']
result = paste(content)
url = '127.0.0.1:5000/'+result
key = result
return jsonify({'ok': True, 'result': [{'key': key, 'url': url}]})
else:
return jsonify({'ok': False, 'result': [{'err_code': 405, 'error': errors['405']}]})
@app.route('/raw/<key>')
def viewraw(key):
if '.' in key:
ext = key.split('.')[1]
key = key.split('.')[0]
else:
ext = 'txt'
response = make_response(get_content(key), 200)
response.mimetype = "text/plain"
return response
@app.route('/<key>')
def view(key):
if '.' in key:
ext = key.split('.')[1]
key = key.split('.')[0]
else:
ext = 'txt'
return render_template('viewer.html', row=False, code=get_content(key), extension=ext)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)