Added getList endpoint
This commit is contained in:
parent
807c06504f
commit
9f74fdeae5
35
handlers/getlist.py
Normal file
35
handlers/getlist.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
from objects import glob
|
||||||
|
|
||||||
|
allowed_args = ["file_hash", "file_version", "timestamp"]
|
||||||
|
|
||||||
|
def handle(request):
|
||||||
|
if len([x for x in request.args if x in allowed_args]) == 0:
|
||||||
|
return {
|
||||||
|
"error": "Missing valid args",
|
||||||
|
"allowed": allowed_args
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in range(len(allowed_args)): # Gets the first valid argument and sets it as the method handler
|
||||||
|
method = request.args.get(allowed_args[i])
|
||||||
|
method_name = allowed_args[i]
|
||||||
|
if method is not None:
|
||||||
|
break
|
||||||
|
|
||||||
|
output = {
|
||||||
|
"method": method_name,
|
||||||
|
"response": callback(method_name, request.args.get(method_name))
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
|
||||||
|
def callback(method, data):
|
||||||
|
cur = glob.sql.cursor()
|
||||||
|
|
||||||
|
cur.execute("SELECT {} FROM updates WHERE filename = 'osu!.exe' ORDER BY file_version".format(
|
||||||
|
method
|
||||||
|
))
|
||||||
|
|
||||||
|
data = []
|
||||||
|
for row in cur.fetchall():
|
||||||
|
data.append(row[method])
|
||||||
|
|
||||||
|
return data
|
7
web.py
7
web.py
|
@ -2,7 +2,7 @@ import json
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
import MySQLdb.cursors
|
import MySQLdb.cursors
|
||||||
from flask import Flask, make_response, request, render_template, jsonify
|
from flask import Flask, make_response, request, render_template, jsonify
|
||||||
from handlers import getupdate, getfile
|
from handlers import getupdate, getfile, getlist
|
||||||
from objects import glob
|
from objects import glob
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
@ -36,5 +36,10 @@ def api_file():
|
||||||
data = getfile.handle(request)
|
data = getfile.handle(request)
|
||||||
return jsonify(data)
|
return jsonify(data)
|
||||||
|
|
||||||
|
@app.route("/api/getList", methods=["GET", "POST"])
|
||||||
|
def api_list():
|
||||||
|
data = getlist.handle(request)
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(**config["web"])
|
app.run(**config["web"])
|
Loading…
Reference in New Issue
Block a user