123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- """
- Website for Craftbroec RR stuff
- """
- import os
- import hashlib
- import hmac
- import subprocess
- from flask import jsonify, abort, request, send_from_directory
- from app import app
- from app.util import job
- @app.route('/')
- def index():
- """Show index page"""
- return send_from_directory('static', 'index.html')
- @app.route("/tutorial/<document>.pdf")
- def tutorial_document(document):
- """Display tutorial document"""
- return send_from_directory('static', 'tutorial/%s.pdf' % document)
- @app.route("/tutorial/<image>.png")
- def tutorial_image(image):
- """Display tutorial image"""
- return send_from_directory('static', 'tutorial/%s.png' % image)
- @app.route("/tutorial/<image>")
- def tutorial_image_page(image):
- """Display tutorial image"""
- return send_from_directory('static', 'tutorial/%s_afbeelding.html' % image)
- @app.route('/typeset', methods=['GET', 'POST'])
- def typeset():
- """Add job to schedeuler"""
- job.typeset_add()
- return jsonify(True)
- @app.route('/deploy', methods=['POST'])
- def deploy():
- """Run deploy script"""
- secret = os.environ["WEBHOOK_KEY"].encode('utf-8')
- digest = hmac.new(secret, request.data, hashlib.sha256).hexdigest()
- signature = request.headers['X-Gogs-Signature']
- if len(signature) < 2 or not hmac.compare_digest(signature, digest):
- abort(400, 'Invalid signature')
- job.upgrade_add()
- return jsonify(True)
- @app.errorhandler(404)
- def page_not_found(e):
- """Return 404 page"""
- return send_from_directory('static', '404.html'), 404
|