diff --git a/velconnect/routes/api.py b/velconnect/routes/api.py index 4096c6e..1dbafb2 100644 --- a/velconnect/routes/api.py +++ b/velconnect/routes/api.py @@ -394,3 +394,23 @@ async def get_all_files(): for f in data: parse_data(f) return data + + +@router.get("/get_all_images") +async def get_all_images(): + data = db.query(""" + SELECT * + FROM `DataBlock` + WHERE visibility='public' AND category='file'; + """) + data = [dict(f) for f in data] + for f in data: + parse_data(f) + images = [] + for f in data: + if f['data']['filename'].endswith('.png') or f['data']['filename'].endswith('.jpg'): + images.append({ + 'key': f['id'], + 'filename': f['data']['filename'] + }) + return images diff --git a/velconnect/templates/index.html b/velconnect/templates/index.html index 6dcab85..2d8365b 100644 --- a/velconnect/templates/index.html +++ b/velconnect/templates/index.html @@ -161,6 +161,20 @@ +
+
+
+
Upload File
+ + +
+
+
+
+
+ +
@@ -185,18 +199,18 @@
-
-
-
Carpet Color
- - -
-
-
-
-
+ + + + + + + + + + + +
@@ -252,6 +266,7 @@ let set_tv_url = document.getElementById('set_tv_url'); let set_carpet_color = document.getElementById('set_carpet_color'); let set_avatar_url = document.getElementById('set_avatar_url'); + let upload_file_button = document.getElementById('upload_file_button'); // check cookie @@ -349,6 +364,18 @@ .catch(_ => console.log('fail')); } + + function uploadFile(file) { + let formData = new FormData(); + formData.append("file", file); + fetch('/api/upload_file', { + method: 'POST', + body: formData + }) + .then(_ => console.log('success')) + .catch(_ => console.log('fail')); + } + if (set_room_id) { set_room_id.addEventListener('click', () => { setDeviceField({"current_room": current_room.value}); @@ -379,6 +406,11 @@ setDeviceData({"avatar_url": document.getElementById('avatar_url').value}); }); } + if (upload_file_button) { + upload_file_button.addEventListener('click', () => { + uploadFile(document.getElementById('upload_file').files[0]); + }); + } } else { window.location.href = "/pair"; diff --git a/velconnect/templates/pair.html b/velconnect/templates/pair.html index 95161b7..e9d419b 100644 --- a/velconnect/templates/pair.html +++ b/velconnect/templates/pair.html @@ -92,9 +92,8 @@ window.location.href = "/failure?code=1"; console.error(resp); } else { - let respData = JSON.parse(resp); - if (respData['hw_id'] !== '') { - setCookie('hw_id', respData['hw_id'], 60); + if (resp['hw_id'] !== '') { + setCookie('hw_id', resp['hw_id'], 60); window.location.href = "/"; } }