diff --git a/server/static/js/import.js b/server/static/js/import.js new file mode 100644 index 0000000..d291018 --- /dev/null +++ b/server/static/js/import.js @@ -0,0 +1,38 @@ +let importButton = document.getElementById('import'); + +importButton.addEventListener('click', importData); + +async function importData(event) { + let fileInput = document.createElement('input'); + fileInput.type = 'file'; + fileInput.accept = '.json'; + + fileInput.onchange = event => { + const file = event.target.files[0]; + if (file) { + const reader = new FileReader(); + + reader.onload = function(e) { + try { + const jsonData = JSON.parse(e.target.result); + sendJsonData(jsonData); + } catch (error) { + alert("Ошибка при чтении файла JSON: " + error.message); + } + }; + reader.readAsText(file); + } + } + fileInput.click() +} + +async function sendJsonData(jsonData) { + await fetch(new URL('/import_db', 'http://localhost:8000').href, { + method: "POST", + headers: { + 'Accept': 'application/json', + "Content-type": "application/json; charset=UTF-8" + }, + body: JSON.stringify(jsonData) + }); +} \ No newline at end of file diff --git a/server/templates/index.html b/server/templates/index.html index 6ae181e..016e92b 100644 --- a/server/templates/index.html +++ b/server/templates/index.html @@ -12,12 +12,13 @@
- +
Команда уже есть? Зайти в профиль
+ \ No newline at end of file diff --git a/server/web_server.py b/server/web_server.py index d4f7b9d..acd564b 100644 --- a/server/web_server.py +++ b/server/web_server.py @@ -518,12 +518,10 @@ def get_filtered_games(): return filtered_games - - - - @app.route('/import_db', methods=['POST']) def import_db(): + new_data = json.loads(flask.request.data) + print(new_data) return app.response_class(status=200) @app.route('/export_db', methods=['POST'])