package dirserv
import (
"fmt"
"mime"
"path/filepath"
"strings"
"imuslab.com/arozos/mod/filesystem/arozfs"
)
func getPageHeader(pathname string) string {
return `
Index of ` + pathname + `
Index of ` + pathname + `
|
Name |
Last Modifiy |
Size |
|
`
}
func getItemHTML(displayText string, link string, isDir bool, modTime string, size string) string {
icon := "🗋"
downloadBtn := ""
hidden := ""
if isDir {
icon = "🗀"
if strings.HasPrefix(displayText, ".") {
//Hidden folder
icon = "🖿"
hidden = "filter: alpha(opacity=50); opacity: 0.5; zoom: 1;"
}
size = "-"
} else {
fileMime := mime.TypeByExtension(filepath.Ext(link))
if strings.HasPrefix(fileMime, "audio/") {
icon = "♫"
} else if strings.HasPrefix(fileMime, "video/") {
icon = "🎞"
} else if strings.HasPrefix(fileMime, "image/") {
icon = "🖻"
} else if strings.HasPrefix(fileMime, "text/") {
icon = "🗎"
}
//fmt.Println(fileMime, filepath.Ext(displayText))
downloadBtn = `Download`
}
return `
` + icon + ` |
` + displayText + ` |
` + modTime + ` |
` + size + ` |
` + downloadBtn + ` |
`
}
func getBackButton(currentPath string) string {
backPath := arozfs.ToSlash(filepath.Dir(currentPath))
return `
← |
Back |
`
}
func getPageFooter() string {
return `
`
}
/*
Utilities
*/
func byteCountIEC(b int64) string {
const unit = 1024
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB",
float64(b)/float64(div), "KMGTPE"[exp])
}