-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
executable file
·45 lines (37 loc) · 1.21 KB
/
app.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
import coffeescript, flask, werkzeug, os, json
from fbx_to_json import fbx_to_json
app = flask.Flask(__name__)
# Index page
@app.route("/")
def index():
return flask.render_template('index.html')
# Compile FBX to JSON
@app.route("/fbx/<file>")
def fbx(file):
return json.dumps(fbx_to_json('fbx/' + file))
# Compile coffeescript to javascript
@app.route('/coffee/<file>')
def coffee(file):
return coffeescript.compile_file('coffee/' + file)
# Upload handler
@app.route('/upload_fbx', methods = ['GET', 'POST'])
def upload_fbx():
if flask.request.method == 'POST':
print(flask.request.files)
file = flask.request.files.get('files[]')
print(file)
if file:
print(file.filename)
if file.filename.endswith('.fbx'):
filename = werkzeug.secure_filename(file.filename)
print(filename)
file.save(os.path.join('./fbx', filename))
return json.dumps({
'name' : file.filename,
'size' : 0,
'url' : '/fbx/' + filename,
})
# Return empty json on error
return json.dumps({})
if __name__ == "__main__":
app.run(debug = True)