2019-03-11 13:25:39 +01:00
|
|
|
import traceback
|
|
|
|
import json
|
|
|
|
|
|
|
|
import tornado.gen
|
|
|
|
import tornado.web
|
|
|
|
|
2019-03-11 14:41:55 +01:00
|
|
|
from helpers import validatorHelper
|
2019-03-11 13:25:39 +01:00
|
|
|
from web import asyncTornado
|
|
|
|
from constants import argumentTypes
|
|
|
|
|
|
|
|
from objects import glob
|
|
|
|
|
2019-03-11 14:41:55 +01:00
|
|
|
class handler(asyncTornado.asyncRequestHandler):
|
|
|
|
ARGS = {
|
|
|
|
("file_hash", "file_version", "timestamp"): argumentTypes.one_required
|
|
|
|
}
|
2019-03-11 13:25:39 +01:00
|
|
|
|
2019-03-11 14:41:55 +01:00
|
|
|
ARGS_VALIDATION = {
|
|
|
|
validatorHelper.HEX: ["file_hash"],
|
|
|
|
validatorHelper.INT: ["file_version", "timestamp"]
|
|
|
|
}
|
|
|
|
|
|
|
|
SQL_STRUCT = {
|
|
|
|
"main": "SELECT %s FROM updates WHERE filename = 'osu!.exe' ORDER BY file_version"
|
|
|
|
}
|
2019-03-11 13:25:39 +01:00
|
|
|
|
|
|
|
@tornado.web.asynchronous
|
|
|
|
@tornado.gen.engine
|
|
|
|
def asyncGet(self):
|
|
|
|
status_code = 400
|
|
|
|
data = {}
|
|
|
|
try:
|
2019-03-11 14:41:55 +01:00
|
|
|
args_filter = asyncTornado.check_arguments(self)
|
2019-03-11 13:25:39 +01:00
|
|
|
if not args_filter:
|
|
|
|
raise Exception("Missing required arguments")
|
|
|
|
|
|
|
|
conn = glob.new_sql()
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
2019-03-11 14:41:55 +01:00
|
|
|
cur.execute(self.SQL_STRUCT["main"] % ",".join(args_filter))
|
2019-03-11 13:25:39 +01:00
|
|
|
data = cur.fetchall()
|
|
|
|
|
|
|
|
cur.close()
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
status_code = 200
|
|
|
|
except Exception as e:
|
|
|
|
status_code = 400
|
|
|
|
data["status"] = status_code
|
|
|
|
data["message"] = str(e)
|
|
|
|
print("Err: %s" % e)
|
|
|
|
traceback.print_exc()
|
|
|
|
finally:
|
|
|
|
self.write( json.dumps(data) )
|
|
|
|
self.set_header("Content-Type", "application/json")
|
|
|
|
self.set_status(status_code)
|