flaskr.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """
  2. Website for Craftbroec RR stuff
  3. """
  4. import os
  5. import hashlib
  6. import hmac
  7. import subprocess
  8. from flask import jsonify, abort, request, send_from_directory
  9. from app import app
  10. from app.util import job
  11. @app.route('/')
  12. def index():
  13. """Show index page"""
  14. return send_from_directory('static', 'index.html')
  15. @app.route("/tutorial/<document>.pdf")
  16. def tutorial_document(document):
  17. """Display tutorial document"""
  18. return send_from_directory('static', 'tutorial/%s.pdf' % document)
  19. @app.route("/tutorial/<image>.png")
  20. def tutorial_image(image):
  21. """Display tutorial image"""
  22. return send_from_directory('static', 'tutorial/%s.png' % image)
  23. @app.route("/tutorial/<image>")
  24. def tutorial_image_page(image):
  25. """Display tutorial image"""
  26. return send_from_directory('static', 'tutorial/%s_afbeelding.html' % image)
  27. @app.route('/typeset', methods=['GET', 'POST'])
  28. def typeset():
  29. """Add job to schedeuler"""
  30. job.typeset_add()
  31. return jsonify(True)
  32. @app.route('/deploy', methods=['POST'])
  33. def deploy():
  34. """Run deploy script"""
  35. secret = os.environ["WEBHOOK_KEY"].encode('utf-8')
  36. digest = hmac.new(secret, request.data, hashlib.sha256).hexdigest()
  37. signature = request.headers['X-Gogs-Signature']
  38. if len(signature) < 2 or not hmac.compare_digest(signature, digest):
  39. abort(400, 'Invalid signature')
  40. job.upgrade_add()
  41. return jsonify(True)
  42. @app.errorhandler(404)
  43. def page_not_found(e):
  44. """Return 404 page"""
  45. return send_from_directory('static', '404.html'), 404