|
|
@ -82,11 +82,31 @@ var htmlTitle string = `<!DOCTYPE html>
|
|
|
|
padding: 12px;
|
|
|
|
padding: 12px;
|
|
|
|
text-align: left;
|
|
|
|
text-align: left;
|
|
|
|
border-bottom: 1px solid #ddd;
|
|
|
|
border-bottom: 1px solid #ddd;
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
th:hover {
|
|
|
|
th[data-sort]:before {
|
|
|
|
cursor: pointer;
|
|
|
|
content: "▼";
|
|
|
|
background-color: #ddd;
|
|
|
|
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 {
|
|
|
|
.filename {
|
|
|
@ -112,20 +132,23 @@ var htmlTitle string = `<!DOCTYPE html>
|
|
|
|
<table>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<tr>
|
|
|
|
<th onclick="sortTable(0)">Name</th>
|
|
|
|
<th data-sort="name" class="asc">Name</th>
|
|
|
|
<th onclick="sortTable(1)">Modified</th>
|
|
|
|
<th data-sort="modified">Modified</th>
|
|
|
|
<th onclick="sortTable(2)">Size</th>
|
|
|
|
<th data-sort="size">Size</th>
|
|
|
|
<th onclick="sortTable(3)">Type</th>
|
|
|
|
<th data-sort="type">Type</th>
|
|
|
|
</tr>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</thead>
|
|
|
|
<tbody>`
|
|
|
|
<tbody>`
|
|
|
|
|
|
|
|
|
|
|
|
var htmlTail = ` </tbody>
|
|
|
|
var htmlTail = ` </tbody>
|
|
|
|
</table>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
|
|
|
<h2 style="text-align: center;">B612.Me © Apache 2.0 License</h2>
|
|
|
|
|
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
function sortTable(n) {
|
|
|
|
function sortTable(th, n) {
|
|
|
|
const table = document.querySelector('table');
|
|
|
|
const table = document.querySelector('table');
|
|
|
|
const rows = table.rows;
|
|
|
|
const rows = table.rows;
|
|
|
|
let switching = true;
|
|
|
|
let switching = true;
|
|
|
@ -142,13 +165,30 @@ var htmlTail = ` </tbody>
|
|
|
|
const x = rows[i].getElementsByTagName("td")[n];
|
|
|
|
const x = rows[i].getElementsByTagName("td")[n];
|
|
|
|
const y = rows[i + 1].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 (direction === 'asc') {
|
|
|
|
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
|
|
|
|
if (xValue > yValue) {
|
|
|
|
shouldSwitch = true;
|
|
|
|
shouldSwitch = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (direction === 'desc') {
|
|
|
|
} else if (direction === 'desc') {
|
|
|
|
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
|
|
|
|
if (xValue < yValue) {
|
|
|
|
shouldSwitch = true;
|
|
|
|
shouldSwitch = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -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>
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</body>
|
|
|
@ -444,14 +529,14 @@ func (h *HttpServer) getFolder(log *starlog.StarLogger, w http.ResponseWriter, r
|
|
|
|
if h.uploadFolder != "" {
|
|
|
|
if h.uploadFolder != "" {
|
|
|
|
upload = `<a href=/b612?upload=true>Upload Web Page Is Openned!</a>`
|
|
|
|
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 != "/" {
|
|
|
|
if r.URL.Path != "/" {
|
|
|
|
p := r.URL.Path
|
|
|
|
p := r.URL.Path
|
|
|
|
if p[len(p)-1:] != "/" {
|
|
|
|
if p[len(p)-1:] != "/" {
|
|
|
|
p += "/"
|
|
|
|
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>`,
|
|
|
|
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 == "/" {
|
|
|
|
if r.URL.Path == "/" {
|
|
|
|
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()))))
|
|
|
|
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 {
|
|
|
|
} 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>`,
|
|
|
|
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 {
|
|
|
|
func (h *HttpServer) getFile(log *starlog.StarLogger, w http.ResponseWriter, r *http.Request, fullpath string) error {
|
|
|
|
if !staros.Exists(fullpath) {
|
|
|
|
if !staros.Exists(fullpath) {
|
|
|
|
w.WriteHeader(404)
|
|
|
|
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")
|
|
|
|
return errors.New("File Not Found! 404 ERROR")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//starlog.Debugln(r.Header)
|
|
|
|
//starlog.Debugln(r.Header)
|
|
|
@ -485,7 +571,7 @@ func (h *HttpServer) getFile(log *starlog.StarLogger, w http.ResponseWriter, r *
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Failed to open file %s,reason:%v\n", r.URL.Path, err)
|
|
|
|
log.Errorf("Failed to open file %s,reason:%v\n", r.URL.Path, err)
|
|
|
|
w.WriteHeader(502)
|
|
|
|
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
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer fp.Close()
|
|
|
|
defer fp.Close()
|
|
|
@ -495,11 +581,11 @@ func (h *HttpServer) getFile(log *starlog.StarLogger, w http.ResponseWriter, r *
|
|
|
|
var tani string
|
|
|
|
var tani string
|
|
|
|
tani = fmt.Sprintf("%v Byte", transferData)
|
|
|
|
tani = fmt.Sprintf("%v Byte", transferData)
|
|
|
|
if f64 := float64(transferData) / 1024; f64 > 1 {
|
|
|
|
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 {
|
|
|
|
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 {
|
|
|
|
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
|
|
|
|
var tani string
|
|
|
|
tani = fmt.Sprintf("%v Byte", size)
|
|
|
|
tani = fmt.Sprintf("%v Byte", size)
|
|
|
|
if f64 := float64(size) / 1024; f64 > 1 {
|
|
|
|
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 {
|
|
|
|
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 {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|