diff --git a/velconnect/routes/api.py b/velconnect/routes/api.py index cf91253..a414abb 100644 --- a/velconnect/routes/api.py +++ b/velconnect/routes/api.py @@ -1,7 +1,8 @@ +from flask.helpers import send_from_directory from velconnect.auth import require_api_key from velconnect.db import connectToDB from velconnect.logger import logger -from flask import Blueprint, request, jsonify +from flask import Blueprint, request, jsonify, render_template, url_for import time import simplejson as json from random import random @@ -9,6 +10,20 @@ from random import random bp = Blueprint('api', __name__) + +@bp.route('/', methods=['GET']) +@require_api_key(0) +def api_home(): + return render_template('api_spec.html') + + +@bp.route('/api_spec.json', methods=['GET']) +@require_api_key(0) +def api_spec(): + return send_from_directory('static', 'api_spec.json') + + + @bp.route('/get_all_headsets', methods=['GET']) @require_api_key(0) def get_all_headsets(): @@ -48,8 +63,6 @@ def update_paring_code(): return 'Must supply hw_id', 400 if 'pairing_code' not in data: return 'Must supply pairing_code', 400 - if 'pairing_code' not in data: - return 'Must supply pairing_code', 400 conn, curr = connectToDB() @@ -73,6 +86,24 @@ def update_paring_code(): return 'Success' + + +@bp.route('/get_headset_details/', methods=['GET']) +@require_api_key(10) +def get_headset_details(hw_id): + return jsonify(get_headset_details_db(hw_id)) + + +def get_headset_details_db(hw_id): + conn, curr = connectToDB() + query = """ + SELECT * FROM `Headset` WHERE hw_id=%(hw_id)s; + """ + curr.execute(query, {'hw_id': hw_id}) + values = [dict(row) for row in curr.fetchall()] + curr.close() + return jsonify(values) + @bp.route('/get_room_details/', methods=['GET']) @require_api_key(10) @@ -91,13 +122,13 @@ def get_room_details_db(room_id): return jsonify(values) -@bp.route('/create_room', methods=['GET']) +@bp.route('/update_room/', methods=['POST']) @require_api_key(10) -def create_room(): - return jsonify(create_room_db()) +def update_room(room_id): + return jsonify(update_room_db(room_id, request.json)) -def create_room_db(): +def update_room_db(room_id, data): room_id = random.randint(0, 9999) conn, curr = connectToDB() query = """ diff --git a/velconnect/static/api_spec.json b/velconnect/static/api_spec.json new file mode 100644 index 0000000..1b041d3 --- /dev/null +++ b/velconnect/static/api_spec.json @@ -0,0 +1,134 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0", + "title": "VEL Connect API", + "description": "This API provides an interface with the database for pairing and controlling headsets while within a VEL app." + }, + "servers": [ + { + "url": "http://3.23.79.32/api/" + } + ], + "tags": [ + { + "name": "Read" + }, + { + "name": "Write" + } + ], + "paths": { + "/get_all_headsets": { + "get": { + "summary": "Get all headset data", + "description" : "Gets a list of all headset data that has been stored", + "tags": ["Read"], + "parameters": [ + ] + } + }, + "/pair_headset/{pairing_code}": { + "get": { + "summary": "Pair a headset by code", + "description" : "Tries to pair to a headset with a supplied pairing code. Returns the hw_id if successfully paired. Used by the website for pairing.", + "tags": ["Write"], + "parameters": [ + { + "name": "pairing_code", + "example": "1234", + "in": "path", + "description": "Pairing Code", + "required": true, + "schema": { + "type": "integer" + } + } + ] + } + }, + "/update_pairing_code": { + "post": { + "summary": "Update Pairing Code", + "description": "This is called by the VR application on login or when the pairing code is reset. If this is the first time this headset is seen, it also creates this headset in the database. A JSON body must be submitted with hw_id and pairing_code defined.", + "tags": ["Write"], + "parameters": [ + + ] + } + }, + "/get_headset_details/{hw_id}": { + "get": { + "summary": "Get Headset Details", + "description" : "Gets the info associated with a specific hardware id.", + "tags": ["Read"], + "parameters": [ + { + "name": "hw_id", + "example": "123456789", + "in": "path", + "description": "Hardware id of the device", + "required": true, + "schema": { + "type": "string" + } + } + ] + } + }, + "/get_room_details/{room_id}": { + "get": { + "summary": "Get Room Details", + "description" : "Gets the info associated with a specific room id. Used by the website to show initial data, and polled often by the headset.", + "tags": ["Read"], + "parameters": [ + { + "name": "room_id", + "example": "1234", + "in": "path", + "description": "Room id", + "required": true, + "schema": { + "type": "string" + } + } + ] + } + }, + "/update_room/{room_id}": { + "post": { + "summary": "Update Room Details", + "description" : "Sets the info associated with a specific room id. The room id is specified in the url and the data is specified in the JSON body. Used by both the website and headset.", + "tags": ["Write"], + "parameters": [ + { + "name": "room_id", + "example": "1234", + "in": "path", + "description": "Room id", + "required": true, + "schema": { + "type": "string" + } + } + ] + } + } + }, + "components": { + "schemas": { + }, + "securitySchemes": { + "api_key": { + "type": "apiKey", + "name": "x-api-key", + "in": "query" + } + } + }, + "security": [ + { + "BasicAuth": [] + } + ] + } \ No newline at end of file diff --git a/velconnect/static/favicons/android-chrome-192x192.png b/velconnect/static/favicons/android-chrome-192x192.png new file mode 100644 index 0000000..b3cd171 Binary files /dev/null and b/velconnect/static/favicons/android-chrome-192x192.png differ diff --git a/velconnect/static/favicons/android-chrome-256x256.png b/velconnect/static/favicons/android-chrome-256x256.png new file mode 100644 index 0000000..bfceabe Binary files /dev/null and b/velconnect/static/favicons/android-chrome-256x256.png differ diff --git a/velconnect/static/favicons/apple-touch-icon.png b/velconnect/static/favicons/apple-touch-icon.png new file mode 100644 index 0000000..ef6f509 Binary files /dev/null and b/velconnect/static/favicons/apple-touch-icon.png differ diff --git a/velconnect/static/favicons/browserconfig.xml b/velconnect/static/favicons/browserconfig.xml new file mode 100644 index 0000000..e8b57e5 --- /dev/null +++ b/velconnect/static/favicons/browserconfig.xml @@ -0,0 +1,9 @@ + + + + + + #b91d47 + + + diff --git a/velconnect/static/favicons/favicon-16x16.png b/velconnect/static/favicons/favicon-16x16.png new file mode 100644 index 0000000..c9c768a Binary files /dev/null and b/velconnect/static/favicons/favicon-16x16.png differ diff --git a/velconnect/static/favicons/favicon-32x32.png b/velconnect/static/favicons/favicon-32x32.png new file mode 100644 index 0000000..fd5a65e Binary files /dev/null and b/velconnect/static/favicons/favicon-32x32.png differ diff --git a/velconnect/static/favicons/favicon.ico b/velconnect/static/favicons/favicon.ico new file mode 100644 index 0000000..aa13620 Binary files /dev/null and b/velconnect/static/favicons/favicon.ico differ diff --git a/velconnect/static/favicons/mstile-150x150.png b/velconnect/static/favicons/mstile-150x150.png new file mode 100644 index 0000000..145dcc2 Binary files /dev/null and b/velconnect/static/favicons/mstile-150x150.png differ diff --git a/velconnect/static/favicons/safari-pinned-tab.svg b/velconnect/static/favicons/safari-pinned-tab.svg new file mode 100644 index 0000000..1cd7cf2 --- /dev/null +++ b/velconnect/static/favicons/safari-pinned-tab.svg @@ -0,0 +1,20 @@ + + + + +Created by potrace 1.14, written by Peter Selinger 2001-2017 + + + + + + + + + diff --git a/velconnect/static/favicons/site.webmanifest b/velconnect/static/favicons/site.webmanifest new file mode 100644 index 0000000..de65106 --- /dev/null +++ b/velconnect/static/favicons/site.webmanifest @@ -0,0 +1,19 @@ +{ + "name": "", + "short_name": "", + "icons": [ + { + "src": "/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/android-chrome-256x256.png", + "sizes": "256x256", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" +} diff --git a/velconnect/static/js/util.js b/velconnect/static/js/util.js new file mode 100644 index 0000000..8396602 --- /dev/null +++ b/velconnect/static/js/util.js @@ -0,0 +1,31 @@ + +function httpGetAsync(theUrl, callback, failCallback) { + var xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function () { + if (xmlHttp.readyState == 4) { + if (xmlHttp.status == 200) { + callback(xmlHttp.responseText); + } else { + failCallback(xmlHttp.status); + } + } + } + xmlHttp.open("GET", theUrl, true); // true for asynchronous + xmlHttp.send(null); +} + +function getCookie(cname) { + let name = cname + "="; + let decodedCookie = decodeURIComponent(document.cookie); + let ca = decodedCookie.split(';'); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') { + c = c.substring(1); + } + if (c.indexOf(name) == 0) { + return c.substring(name.length, c.length); + } + } + return ""; +} \ No newline at end of file diff --git a/velconnect/templates/api_spec.html b/velconnect/templates/api_spec.html new file mode 100644 index 0000000..081387a --- /dev/null +++ b/velconnect/templates/api_spec.html @@ -0,0 +1,24 @@ + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/velconnect/templates/failure.jinja b/velconnect/templates/failure.jinja index cc196a0..b9f3a2f 100644 --- a/velconnect/templates/failure.jinja +++ b/velconnect/templates/failure.jinja @@ -1,6 +1,16 @@ + + + + + + + + + + -
- Headset pairing. Wow so cool! 😋😎 +
+ +
+
â˜šī¸
+ + +
+ + \ No newline at end of file diff --git a/velconnect/templates/pair.jinja b/velconnect/templates/pair.jinja index 3df22c7..f5b3990 100644 --- a/velconnect/templates/pair.jinja +++ b/velconnect/templates/pair.jinja @@ -1,7 +1,19 @@ + + + + + + + + + + + +