openscad-remote/openscad_remote.py
2021-08-18 08:11:52 +01:00

42 lines
715 B
Python

from flask import (
Flask,
request,
jsonify,
send_file
)
import os
from uuid import uuid4
import subprocess
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
@app.route("/upload", methods=['POST'])
def upload_file():
f = request.files['file']
uuid = uuid4()
filepath = os.path.join("/data/upload", f"{uuid}.scad")
f.save(filepath)
return jsonify({
"id": uuid
})
@app.route("/generate/<id>")
def generate(id):
subprocess.run([
"openscad",
"-o", f"/data/build/{id}.stl",
f"/data/upload/{id}.scad"
])
return send_file(f"/data/build/{id}.stl")
if __name__ == "__main__":
app.run()