package dirserv import ( "fmt" "mime" "path/filepath" "strings" "imuslab.com/arozos/mod/filesystem/arozfs" "imuslab.com/arozos/mod/filesystem/hidden" ) func getPageHeader(pathname string) string { return ` Index of ` + pathname + `

Index of ` + pathname + `


` } func getItemHTML(displayText string, link string, isDir bool, modTime string, size string) string { icon := "📄" downloadBtn := "" hiddenStyle := "" if isDir { icon = "📁" isHidden, _ := hidden.IsHidden(link, true) if isHidden { //Hidden folder icon = "📁" hiddenStyle = "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)) //Check if hidden file isHidden, _ := hidden.IsHidden(link, true) if isHidden { //Hidden folder hiddenStyle = "filter: alpha(opacity=50); opacity: 0.5; zoom: 1;" } downloadBtn = `Download` } return `` } func getBackButton(currentPath string) string { backPath := arozfs.ToSlash(filepath.Dir(currentPath)) return `` } func getPageFooter() string { return `
Name Last Modify Size
` + icon + ` ` + displayText + ` ` + modTime + ` ` + size + ` ` + downloadBtn + `
Back

` } /* 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]) }