|
|
@@ -5,6 +5,7 @@ from hashlib import sha512 |
|
|
|
from os import getcwd |
|
|
|
from threading import get_ident |
|
|
|
from time import time |
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
database_path = 'rxsm-update.db' |
|
|
|
|
|
|
@@ -58,16 +59,26 @@ def download_database(): |
|
|
|
@app.route('/check-for-update', methods=['POST']) |
|
|
|
def check_for_update(): |
|
|
|
start = time() |
|
|
|
db_connection = get_or_create_connection() |
|
|
|
cursor = db_connection.cursor() |
|
|
|
collect_anonymous_stats = str(request.headers.get('DNT')).strip() != '1' |
|
|
|
# TODO: add hit counter |
|
|
|
# hit counter |
|
|
|
if collect_anonymous_stats: |
|
|
|
today = datetime.today().date().isoformat() |
|
|
|
cursor.execute('SELECT count FROM hits WHERE date=?', (today,)) |
|
|
|
result = cursor.fetchone() |
|
|
|
if result is not None: |
|
|
|
cursor.execute('UPDATE hits SET count=count+1 WHERE date=?', (today,)) |
|
|
|
else: |
|
|
|
cursor.execute('INSERT INTO hits (date, count) VALUES (?,?)', (today, 1)) |
|
|
|
db_connection.commit() |
|
|
|
# update lookup |
|
|
|
try: |
|
|
|
req_json = request.get_json(force=True) |
|
|
|
current_version = req_json['version'] |
|
|
|
platform = req_json['platform'] |
|
|
|
except: |
|
|
|
return jsonify({'status':400, 'reason':'Invalid request; missing parameter or invalid JSON'}), 400 |
|
|
|
db_connection = get_or_create_connection() |
|
|
|
cursor = db_connection.cursor() |
|
|
|
cursor.execute('SELECT version, url FROM releases WHERE platform=? ORDER BY created_date DESC', (platform,)) |
|
|
|
result = cursor.fetchone() |
|
|
|
if result is None: |
|
|
@@ -88,6 +99,11 @@ cursor.execute(\ |
|
|
|
platform TEXT NOT NULL, |
|
|
|
created_date INTEGER NOT NULL |
|
|
|
)''' ) |
|
|
|
cursor.execute(\ |
|
|
|
'''CREATE TABLE IF NOT EXISTS hits ( |
|
|
|
date TEXT UNIQUE NOT NULL, |
|
|
|
count INTEGER NOT NULL |
|
|
|
)''' ) |
|
|
|
conn.commit() |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|