mirror of
https://github.com/nxshock/simplefileshare.git
synced 2025-07-02 00:13:36 +05:00
Import project
This commit is contained in:
parent
f0e39831c2
commit
1b0cbbf5cd
13 changed files with 588 additions and 0 deletions
178
index.htm
Normal file
178
index.htm
Normal file
|
@ -0,0 +1,178 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title>File Storage</title>
|
||||
<style>
|
||||
* {
|
||||
font-family: Verdana;
|
||||
font-size: 16px;
|
||||
color: #444;
|
||||
margin: .5em;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #fafafa;
|
||||
display: flex;
|
||||
justify-content: start;
|
||||
flex-wrap: nowrap;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #07a;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
svg, img {
|
||||
vertical-align: middle;
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
header {
|
||||
background-color: #eee;
|
||||
border-bottom: 1px solid #ddd;
|
||||
padding: .5em;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
footer {
|
||||
background-color: #eee;
|
||||
border-top: 1px solid #ddd;
|
||||
padding: .5em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 1em;
|
||||
font-size: 150%;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
background-color: #dde;
|
||||
}
|
||||
|
||||
th, td {
|
||||
border: 1px solid #777;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
td:nth-child(2), td:nth-child(3) {
|
||||
width: 10em;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
form {
|
||||
width: calc(100% - 1em);
|
||||
}
|
||||
|
||||
form > input {
|
||||
width: calc(100% - 2em);
|
||||
padding: .5em;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: .5em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
pre {
|
||||
margin: 0;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
input[type="file"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
label {
|
||||
margin: 0;
|
||||
padding: .5em;
|
||||
border: 1px solid #ccc;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<span>File Storage</span>
|
||||
<label>
|
||||
<input id="file-uploader" type="file" id="upload-button">
|
||||
Загрузить файл
|
||||
</label>
|
||||
</header>
|
||||
<main>
|
||||
<table>
|
||||
<col width="*">
|
||||
<col width="0">
|
||||
<col width="0">
|
||||
<tr>
|
||||
<th>Имя</th>
|
||||
<th>Размер</th>
|
||||
<th>Дата</th>
|
||||
</tr>
|
||||
{{range .}} <tr>
|
||||
<td><a href="/download?filename={{.Name}}">{{.Name}}</a></td>
|
||||
<td><pre>{{.Size}}</pre></td>
|
||||
<td>{{.Date}}</td>
|
||||
</tr>
|
||||
{{end}} </table>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<script type="text/javascript">
|
||||
function myProgressHandler(event) {
|
||||
var p = Math.floor(event.loaded/event.total*100);
|
||||
document.querySelector("label").innerHTML = 'Загрузка: ' + p + '%...';
|
||||
}
|
||||
|
||||
function myOnLoadHandler(event) {
|
||||
const response = event.currentTarget;
|
||||
if (response.status != 200) {
|
||||
alert('Ошибка при загрузке файла:\n' + response.responseText);
|
||||
}
|
||||
document.querySelector("label").innerHTML = 'Загрузка завершена.';
|
||||
location.reload();
|
||||
}
|
||||
|
||||
document.getElementById("file-uploader").addEventListener('change', (e) => {
|
||||
var file = document.getElementById("file-uploader").files[0];
|
||||
var formData = new FormData;
|
||||
formData.append('file', file);
|
||||
var ajax = new XMLHttpRequest;
|
||||
ajax.upload.addEventListener("progress", myProgressHandler, false);
|
||||
ajax.addEventListener('load', myOnLoadHandler, false);
|
||||
ajax.open('POST', '/upload', true);
|
||||
ajax.send(formData);
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue