This commit is contained in:
dzikafoczka 2024-12-21 22:11:18 +01:00
parent 73816593ef
commit fa5cc38d44
2 changed files with 59 additions and 0 deletions

37
ec2.py
View File

@ -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 = `
<p>Plik został pomyślnie przesłany!</p>
<pre>${{JSON.stringify(data, null, 2)}}</pre>
`;
})
.catch(error => {
document.getElementById('responseMessage').innerHTML = `
<p>Błąd podczas przesyłania pliku: ${error.message}</p>
`;
});
} 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)

22
index.html Normal file
View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload PDF</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Prześlij plik PDF</h1>
<form id="uploadForm" enctype="multipart/form-data">
<label for="file">Wybierz plik PDF:</label>
<input type="file" id="file" name="file" accept=".pdf" required>
<button type="submit">Wyślij</button>
</form>
<div id="responseMessage"></div>
</div>
<script src="scripts.js"></script>
</body>
</html>