added visual feedback to website and added a response in the server
This commit is contained in:
parent
2b77a349fa
commit
2e9d90a0ae
3 changed files with 34 additions and 2 deletions
2
main.cpp
2
main.cpp
|
@ -5,6 +5,7 @@
|
||||||
#include <print>
|
#include <print>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
int atoi_newline(const char *data)
|
int atoi_newline(const char *data)
|
||||||
{
|
{
|
||||||
|
@ -337,6 +338,7 @@ int main()
|
||||||
char *end = search_substring(chunk, final_boundary.c_str(), file_size);
|
char *end = search_substring(chunk, final_boundary.c_str(), file_size);
|
||||||
write_file(filename, chunk, end);
|
write_file(filename, chunk, end);
|
||||||
free(chunk);
|
free(chunk);
|
||||||
|
netlib::send_packet(std::make_tuple(std::string("HTTP/1.1 200 OK\r\n")), user);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
2
netlib
2
netlib
|
@ -1 +1 @@
|
||||||
Subproject commit 81313776bc951f88387f0a9f7cec06fb04d1fcb9
|
Subproject commit 344f771aa83755fa6acdcd74a621362adc1fd5b7
|
32
test.html
32
test.html
|
@ -20,6 +20,11 @@
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
transition: background-color 0.3s, border-color 0.3s;
|
transition: background-color 0.3s, border-color 0.3s;
|
||||||
}
|
}
|
||||||
|
#drop_zone.dragover
|
||||||
|
{
|
||||||
|
border-color: green;
|
||||||
|
background-color: #e0ffe0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -29,9 +34,12 @@
|
||||||
ondrop="dropHandler(event);"
|
ondrop="dropHandler(event);"
|
||||||
ondragover="dragOverHandler(event);"
|
ondragover="dragOverHandler(event);"
|
||||||
ondragenter="dragEnterHandler(event);"
|
ondragenter="dragEnterHandler(event);"
|
||||||
|
ondragleave="dragLeaveHandler(event);"
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="status"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const dropZone = document.getElementById('drop_zone');
|
const dropZone = document.getElementById('drop_zone');
|
||||||
|
|
||||||
|
@ -67,9 +75,18 @@
|
||||||
}
|
}
|
||||||
function dragEnterHandler(ev)
|
function dragEnterHandler(ev)
|
||||||
{
|
{
|
||||||
|
document.getElementById('drop_zone').classList.add('dragover');
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dragLeaveHandler(ev)
|
||||||
|
{
|
||||||
|
if (ev.target === document.getElementById('drop_zone'))
|
||||||
|
{
|
||||||
|
document.getElementById('drop_zone').classList.remove('dragover');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function uploadFile(file)
|
function uploadFile(file)
|
||||||
{
|
{
|
||||||
|
@ -79,12 +96,25 @@
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
formData.append('uploadedFile', file, file.name);
|
formData.append('uploadedFile', file, file.name);
|
||||||
|
document.getElementById('status').textContent = 'se esta subiendo el archivo';
|
||||||
fetch(url,
|
fetch(url,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
|
.then(
|
||||||
|
response =>
|
||||||
|
{
|
||||||
|
if (response.ok)
|
||||||
|
{
|
||||||
|
document.getElementById('status').textContent = 'se subio el archivo';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
document.getElementById('status').textContent = 'Hubo un error subiendo el archivo';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue