diff --git a/ec2.py b/ec2.py index 7d9f2d7..bdf7faa 100644 --- a/ec2.py +++ b/ec2.py @@ -215,6 +215,43 @@ def run_instance(ec2_client, launch_template_id, subnet_id): return instance_id +def create_js_scripts(ip): + js_content = r""" + document.getElementById('uploadForm').addEventListener('submit', function (event) { + event.preventDefault(); + + const fileInput = document.getElementById('file'); + const file = fileInput.files[0]; + + if (file) { + const formData = new FormData(); + formData.append('file', file); + fetch('http://""" + ip + """/invoice', { + method: 'POST', + body: formData, + }) + .then(response => response.json()) + .then(data => { + document.getElementById('responseMessage').innerHTML = ` +
Plik został pomyślnie przesłany!
+${{JSON.stringify(data, null, 2)}}+ `; + }) + .catch(error => { + document.getElementById('responseMessage').innerHTML = ` +
Błąd podczas przesyłania pliku: ${error.message}
+ `; + }); + } else { + alert('Proszę wybrać plik!'); + } + }); + """ + + with open('scripts.js', 'w') as js_file: + js_file.write(js_content) + print(f"Generated scripts.js with ip: {ip}") + def main(): # Create EC2 client ec2_client = boto3.client('ec2', region_name=REGION) diff --git a/index.html b/index.html new file mode 100644 index 0000000..80f002a --- /dev/null +++ b/index.html @@ -0,0 +1,22 @@ + + + + + +