Spaces:
Runtime error
Runtime error
File size: 2,872 Bytes
66ca64a 5e7bebe 66ca64a |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
import os
from flask import *
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from routes import *
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
limiter = Limiter(app, default_limits=["5/minute"], key_func=get_remote_address, storage_uri="memory://",)
#limiter
@limiter.request_filter
def ip_whitelist():
try:
if request.method == 'POST': signature = request.form['signature']
else: signature = request.args['signature']
return helpers.checkSignature(signature)
except: return False
#error pages
@app.errorhandler(429)
def ratelimit_handler(e): return render_template('ratelimit.html')
@app.errorhandler(403)
def forbidden_handler(e): return render_template('forbidden.html')
@app.errorhandler(404)
def ratelimit_handler(e): return render_template('notfound.html')
# site routes
@app.route('/')
@limiter.exempt
def index(): return render_template('index.html')
#empty routes
@app.route('/yt/api/v1', methods=['GET', 'POST'])
@app.route('/recognize/api/v1', methods=['GET', 'POST'])
@app.route('/osu/api/v1', methods=['GET', 'POST'])
def emptyPath(): return {}
@app.route('/yt/api/v1/<path:path>', methods=['GET', 'POST'])
@app.route('/recognize/api/v1/<path:path>', methods=['GET', 'POST'])
@app.route('/osu/api/v1/<path:path>', methods=['GET', 'POST'])
def emptyApiWA(path): return {"status": "error", "error_code": 100, "error_details": "No method like that found"}
#for dns-query
@app.route('/dns-query', methods=['GET', 'POST'])
@limiter.exempt
def rerouteto(): return make_response("Wrong port! Use 334 port for dns-query.", 400)
#icon
@app.route('/favicon.ico')
@limiter.exempt
def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')
###############
#RECOGNIZE API
@app.route('/recognize/api/v1/voice', methods=['GET', 'POST'])
def recognizeVoice(): return witaiApi.recognizeVoice(request)
###############
#YT SOUND API
@app.route('/yt/api/v1/search', methods=['GET', 'POST'])
def search(): return ytApi.search(request)
@app.route('/yt/api/v1/get-full', methods=['GET', 'POST'])
def getFull(): return ytApi.getFull(request)
@app.route('/yt/api/v1/get-preview', methods=['GET', 'POST'])
def getPreview(): return ytApi.getPreview(request)
###############
#OSU API
@app.route('/osu/api/v1/find-song', methods=['GET', 'POST'])
def findSong(): return osuApi.findSong(request)
@app.route('/osu/api/v1/get-beatmap', methods=['GET', 'POST'])
def getBeatmap(): return osuApi.getBeatmap(request)
@app.route('/osu/api/v1/get-preview', methods=['GET', 'POST'])
def getBMPreview(): return osuApi.getPreview(request)
@app.route('/osu/api/v1/get-full', methods=['GET', 'POST'])
def getBMFull(): return osuApi.getFull(request)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860, debug=True)
|