|
|
|
@ -82,11 +82,31 @@ var htmlTitle string = `<!DOCTYPE html>
|
|
|
|
|
padding: 12px;
|
|
|
|
|
text-align: left;
|
|
|
|
|
border-bottom: 1px solid #ddd;
|
|
|
|
|
position: relative;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
th:hover {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
background-color: #ddd;
|
|
|
|
|
th[data-sort]:before {
|
|
|
|
|
content: "▼";
|
|
|
|
|
display: inline-block;
|
|
|
|
|
height: 20px;
|
|
|
|
|
width: 20px;
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
position: absolute;
|
|
|
|
|
right: 0;
|
|
|
|
|
top: 50%%;
|
|
|
|
|
transform: translateY(-50%%);
|
|
|
|
|
opacity: 0.3;
|
|
|
|
|
transition: all 0.2s ease-in-out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
th[data-sort].asc:before {
|
|
|
|
|
content: "▲";
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
th:hover:before {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.filename {
|
|
|
|
@ -112,49 +132,69 @@ var htmlTitle string = `<!DOCTYPE html>
|
|
|
|
|
<table>
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th onclick="sortTable(0)">Name</th>
|
|
|
|
|
<th onclick="sortTable(1)">Modified</th>
|
|
|
|
|
<th onclick="sortTable(2)">Size</th>
|
|
|
|
|
<th onclick="sortTable(3)">Type</th>
|
|
|
|
|
<th data-sort="name" class="asc">Name</th>
|
|
|
|
|
<th data-sort="modified">Modified</th>
|
|
|
|
|
<th data-sort="size">Size</th>
|
|
|
|
|
<th data-sort="type">Type</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>`
|
|
|
|
|
|
|
|
|
|
var htmlTail = ` </tbody>
|
|
|
|
|
</table>
|
|
|
|
|
<hr />
|
|
|
|
|
<pre>
|
|
|
|
|
<h2 style="text-align: center;">B612.Me © Apache 2.0 License</h2>
|
|
|
|
|
</pre>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
function sortTable(n) {
|
|
|
|
|
const table = document.querySelector('table');
|
|
|
|
|
const rows = table.rows;
|
|
|
|
|
let switching = true;
|
|
|
|
|
let shouldSwitch = false;
|
|
|
|
|
let direction = 'asc';
|
|
|
|
|
let switchcount = 0;
|
|
|
|
|
|
|
|
|
|
function sortTable(th, n) {
|
|
|
|
|
const table = document.querySelector('table');
|
|
|
|
|
const rows = table.rows;
|
|
|
|
|
let switching = true;
|
|
|
|
|
let shouldSwitch = false;
|
|
|
|
|
let direction = 'asc';
|
|
|
|
|
let switchcount = 0;
|
|
|
|
|
|
|
|
|
|
while (switching) {
|
|
|
|
|
switching = false;
|
|
|
|
|
let i;
|
|
|
|
|
for (i = 1; i < rows.length - 1; i++) {
|
|
|
|
|
shouldSwitch = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const x = rows[i].getElementsByTagName("td")[n];
|
|
|
|
|
const y = rows[i + 1].getElementsByTagName("td")[n];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let xValue, yValue;
|
|
|
|
|
if (n === 2) { // size sorting
|
|
|
|
|
if (x.innerText==="-") {
|
|
|
|
|
xValue=-1;
|
|
|
|
|
}else{
|
|
|
|
|
xValue = parseInt(x.innerText.split(' ')[0]);
|
|
|
|
|
}
|
|
|
|
|
if (y.innerText==="-") {
|
|
|
|
|
yValue=-1;
|
|
|
|
|
}else{
|
|
|
|
|
yValue = parseInt(y.innerText.split(' ')[0]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
xValue = x.innerText.toLowerCase();
|
|
|
|
|
yValue = y.innerText.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (direction === 'asc') {
|
|
|
|
|
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
|
|
|
|
|
if (xValue > yValue) {
|
|
|
|
|
shouldSwitch = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (direction === 'desc') {
|
|
|
|
|
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
|
|
|
|
|
if (xValue < yValue) {
|
|
|
|
|
shouldSwitch = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (shouldSwitch) {
|
|
|
|
|
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
|
|
|
|
|
switching = true;
|
|
|
|
@ -166,6 +206,51 @@ var htmlTail = ` </tbody>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update sort class
|
|
|
|
|
const ths = table.getElementsByTagName('th');
|
|
|
|
|
for (let i = 0; i < ths.length; i++) {
|
|
|
|
|
const currentTh = ths[i];
|
|
|
|
|
if (currentTh !== th) {
|
|
|
|
|
currentTh.classList.remove('asc');
|
|
|
|
|
} else {
|
|
|
|
|
currentTh.classList.toggle('asc');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// hide arrow on non-sorting columns
|
|
|
|
|
const sortableThs = table.querySelectorAll('thead th[data-sort]');
|
|
|
|
|
for (let i = 0; i < sortableThs.length; i++) {
|
|
|
|
|
const sortableTh = sortableThs[i];
|
|
|
|
|
if (sortableTh !== th) {
|
|
|
|
|
sortableTh.classList.remove('asc');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add sorting event listener to thead
|
|
|
|
|
const ths = document.querySelectorAll('table th[data-sort]');
|
|
|
|
|
for (let i = 0; i < ths.length; i++) {
|
|
|
|
|
const th = ths[i];
|
|
|
|
|
th.addEventListener('click', () => {
|
|
|
|
|
const sortType = th.getAttribute('data-sort');
|
|
|
|
|
let columnIndex;
|
|
|
|
|
switch (sortType) {
|
|
|
|
|
case 'name':
|
|
|
|
|
columnIndex = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 'modified':
|
|
|
|
|
columnIndex = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'size':
|
|
|
|
|
columnIndex = 2;
|
|
|
|
|
break;
|
|
|
|
|
case 'type':
|
|
|
|
|
columnIndex = 3;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
sortTable(th, columnIndex);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
@ -444,14 +529,14 @@ func (h *HttpServer) getFolder(log *starlog.StarLogger, w http.ResponseWriter, r
|
|
|
|
|
if h.uploadFolder != "" {
|
|
|
|
|
upload = `<a href=/b612?upload=true>Upload Web Page Is Openned!</a>`
|
|
|
|
|
}
|
|
|
|
|
w.Write([]byte(fmt.Sprintf(htmlTitle, r.URL.Path, version, r.URL.Path, upload)))
|
|
|
|
|
w.Write([]byte(fmt.Sprintf(htmlTitle, r.URL.Path, version, "Index of "+r.URL.Path, upload)))
|
|
|
|
|
if r.URL.Path != "/" {
|
|
|
|
|
p := r.URL.Path
|
|
|
|
|
if p[len(p)-1:] != "/" {
|
|
|
|
|
p += "/"
|
|
|
|
|
}
|
|
|
|
|
w.Write([]byte(fmt.Sprintf(`<tr><td><a class="filename" href="%s">%s</a></td><td>%s</td><td>%s</td><td class="filetype">%s</td></tr>`,
|
|
|
|
|
p+"..", "..", "-", "-", "上层文件夹")))
|
|
|
|
|
p+"..", "../", "-", "-", "上层文件夹")))
|
|
|
|
|
}
|
|
|
|
|
if r.URL.Path == "/" {
|
|
|
|
|
r.URL.Path = ""
|
|
|
|
@ -466,7 +551,7 @@ func (h *HttpServer) getFolder(log *starlog.StarLogger, w http.ResponseWriter, r
|
|
|
|
|
r.URL.Path+"/"+v.Name(), v.Name(), v.ModTime().Format("2006-01-02 15:04:05"), fmt.Sprintf("%d (%s)", v.Size(), h.trimSize(v.Size())), h.FileType(v.Name()))))
|
|
|
|
|
} else {
|
|
|
|
|
w.Write([]byte(fmt.Sprintf(`<tr><td><a class="filename" href="%s">%s</a></td><td>%s</td><td>%s</td><td class="filetype">%s</td></tr>`,
|
|
|
|
|
r.URL.Path+"/"+v.Name(), v.Name(), v.ModTime().Format("2006-01-02 15:04:05"), "-", "文件夹")))
|
|
|
|
|
r.URL.Path+"/"+v.Name(), v.Name()+"/", v.ModTime().Format("2006-01-02 15:04:05"), "-", "文件夹")))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -477,6 +562,7 @@ func (h *HttpServer) getFolder(log *starlog.StarLogger, w http.ResponseWriter, r
|
|
|
|
|
func (h *HttpServer) getFile(log *starlog.StarLogger, w http.ResponseWriter, r *http.Request, fullpath string) error {
|
|
|
|
|
if !staros.Exists(fullpath) {
|
|
|
|
|
w.WriteHeader(404)
|
|
|
|
|
w.Write([]byte(`<html><title>B612 Http Server</title><body><h1 "style="text-align: center;">404 NOT FOUND</h1><hr ></body></html>`))
|
|
|
|
|
return errors.New("File Not Found! 404 ERROR")
|
|
|
|
|
}
|
|
|
|
|
//starlog.Debugln(r.Header)
|
|
|
|
@ -485,7 +571,7 @@ func (h *HttpServer) getFile(log *starlog.StarLogger, w http.ResponseWriter, r *
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorf("Failed to open file %s,reason:%v\n", r.URL.Path, err)
|
|
|
|
|
w.WriteHeader(502)
|
|
|
|
|
w.Write([]byte("<h1>502 SERVER ERROR</h1>"))
|
|
|
|
|
w.Write([]byte(`<html><title>B612 Http Server</title><body><h1 "style="text-align: center;">502 SERVER ERROR</h1><hr ></body></html>`))
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer fp.Close()
|
|
|
|
@ -495,11 +581,11 @@ func (h *HttpServer) getFile(log *starlog.StarLogger, w http.ResponseWriter, r *
|
|
|
|
|
var tani string
|
|
|
|
|
tani = fmt.Sprintf("%v Byte", transferData)
|
|
|
|
|
if f64 := float64(transferData) / 1024; f64 > 1 {
|
|
|
|
|
tani = fmt.Sprintf("%v KB", f64)
|
|
|
|
|
tani = fmt.Sprintf("%v KiB", f64)
|
|
|
|
|
if f64 = float64(f64) / 1024; f64 > 1 {
|
|
|
|
|
tani = fmt.Sprintf("%v MB", f64)
|
|
|
|
|
tani = fmt.Sprintf("%v MiB", f64)
|
|
|
|
|
if f64 = float64(f64) / 1024; f64 > 1 {
|
|
|
|
|
tani = fmt.Sprintf("%v GB", f64)
|
|
|
|
|
tani = fmt.Sprintf("%v GiB", f64)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -575,11 +661,11 @@ func (h *HttpServer) trimSize(size int64) string {
|
|
|
|
|
var tani string
|
|
|
|
|
tani = fmt.Sprintf("%v Byte", size)
|
|
|
|
|
if f64 := float64(size) / 1024; f64 > 1 {
|
|
|
|
|
tani = fmt.Sprintf("%.3f KB", math.Trunc(f64*1e3+0.5)*1e-3)
|
|
|
|
|
tani = fmt.Sprintf("%.3f KiB", math.Trunc(f64*1e3+0.5)*1e-3)
|
|
|
|
|
if f64 = float64(f64) / 1024; f64 > 1 {
|
|
|
|
|
tani = fmt.Sprintf("%.3f MB", math.Trunc(f64*1e3+0.5)*1e-3)
|
|
|
|
|
tani = fmt.Sprintf("%.3f MiB", math.Trunc(f64*1e3+0.5)*1e-3)
|
|
|
|
|
if f64 = float64(f64) / 1024; f64 > 1 {
|
|
|
|
|
tani = fmt.Sprintf("%.3f GB", math.Trunc(f64*1e3+0.5)*1e-3)
|
|
|
|
|
tani = fmt.Sprintf("%.3f GiB", math.Trunc(f64*1e3+0.5)*1e-3)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|