Compare commits
No commits in common. "10a3f0927dd8bae263a499563ec2857649d06b0a" and "fa1e3d126f148f19f9888fb14a41be577ef1878b" have entirely different histories.
10a3f0927d
...
fa1e3d126f
112
cmd/info.go
112
cmd/info.go
|
@ -19,64 +19,7 @@ import (
|
||||||
"seedno.de/seednode/roulette/types"
|
"seedno.de/seednode/roulette/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func paginate(page int, fileCount int, ending bool) string {
|
func serveIndexHtml(args []string, index *fileIndex, paginate bool) httprouter.Handle {
|
||||||
var html strings.Builder
|
|
||||||
|
|
||||||
var firstPage int = 1
|
|
||||||
var lastPage int
|
|
||||||
|
|
||||||
if fileCount%PageLength == 0 {
|
|
||||||
lastPage = fileCount / PageLength
|
|
||||||
} else {
|
|
||||||
lastPage = (fileCount / PageLength) + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
var prevStatus, nextStatus string = "", ""
|
|
||||||
|
|
||||||
if page <= 1 {
|
|
||||||
prevStatus = " disabled"
|
|
||||||
}
|
|
||||||
|
|
||||||
if page >= lastPage {
|
|
||||||
nextStatus = " disabled"
|
|
||||||
}
|
|
||||||
|
|
||||||
prevPage := page - 1
|
|
||||||
if prevPage < 1 {
|
|
||||||
prevPage = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPage := page + 1
|
|
||||||
if nextPage > lastPage {
|
|
||||||
nextPage = fileCount / PageLength
|
|
||||||
}
|
|
||||||
|
|
||||||
if ending {
|
|
||||||
html.WriteString("<tr><td style=\"border-bottom:none;\">")
|
|
||||||
} else {
|
|
||||||
html.WriteString("<tr><td>")
|
|
||||||
}
|
|
||||||
|
|
||||||
html.WriteString(fmt.Sprintf("<button onclick=\"window.location.href = '/html/%d';\">First</button>",
|
|
||||||
firstPage))
|
|
||||||
|
|
||||||
html.WriteString(fmt.Sprintf("<button onclick=\"window.location.href = '/html/%d';\"%s>Prev</button>",
|
|
||||||
prevPage,
|
|
||||||
prevStatus))
|
|
||||||
|
|
||||||
html.WriteString(fmt.Sprintf("<button onclick=\"window.location.href = '/html/%d';\"%s>Next</button>",
|
|
||||||
nextPage,
|
|
||||||
nextStatus))
|
|
||||||
|
|
||||||
html.WriteString(fmt.Sprintf("<button onclick=\"window.location.href = '/html/%d';\">Last</button>",
|
|
||||||
lastPage))
|
|
||||||
|
|
||||||
html.WriteString("</td></tr>\n")
|
|
||||||
|
|
||||||
return html.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func serveIndexHtml(args []string, index *fileIndex, shouldPaginate bool) httprouter.Handle {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
|
||||||
|
@ -113,13 +56,8 @@ func serveIndexHtml(args []string, index *fileIndex, shouldPaginate bool) httpro
|
||||||
htmlBody.WriteString(`<!DOCTYPE html><html lang="en"><head>`)
|
htmlBody.WriteString(`<!DOCTYPE html><html lang="en"><head>`)
|
||||||
htmlBody.WriteString(faviconHtml)
|
htmlBody.WriteString(faviconHtml)
|
||||||
htmlBody.WriteString(`<style>a{text-decoration:none;height:100%;width:100%;color:inherit;cursor:pointer}`)
|
htmlBody.WriteString(`<style>a{text-decoration:none;height:100%;width:100%;color:inherit;cursor:pointer}`)
|
||||||
htmlBody.WriteString(`table,td,tr{border:none;}td{border-bottom:1px solid black;}td{white-space:nowrap;padding:.5em}</style>`)
|
htmlBody.WriteString(`table,td,tr{border:1px solid black;border-collapse:collapse}td{white-space:nowrap;padding:.5em}</style>`)
|
||||||
htmlBody.WriteString(fmt.Sprintf("<title>Index contains %d files</title></head><body><table>", fileCount))
|
htmlBody.WriteString(fmt.Sprintf("<title>Index contains %d files</title></head><body><table>", fileCount))
|
||||||
|
|
||||||
if shouldPaginate {
|
|
||||||
htmlBody.WriteString(paginate(page, fileCount, false))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(indexDump) > 0 {
|
if len(indexDump) > 0 {
|
||||||
for _, v := range indexDump[startIndex:stopIndex] {
|
for _, v := range indexDump[startIndex:stopIndex] {
|
||||||
var shouldSort = ""
|
var shouldSort = ""
|
||||||
|
@ -130,9 +68,51 @@ func serveIndexHtml(args []string, index *fileIndex, shouldPaginate bool) httpro
|
||||||
htmlBody.WriteString(fmt.Sprintf("<tr><td><a href=\"%s%s%s%s\">%s</a></td></tr>\n", Prefix, mediaPrefix, v, shouldSort, v))
|
htmlBody.WriteString(fmt.Sprintf("<tr><td><a href=\"%s%s%s%s\">%s</a></td></tr>\n", Prefix, mediaPrefix, v, shouldSort, v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if PageLength != 0 {
|
||||||
|
var firstPage int = 1
|
||||||
|
var lastPage int
|
||||||
|
|
||||||
if shouldPaginate {
|
if fileCount%PageLength == 0 {
|
||||||
htmlBody.WriteString(paginate(page, fileCount, true))
|
lastPage = fileCount / PageLength
|
||||||
|
} else {
|
||||||
|
lastPage = (fileCount / PageLength) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if paginate {
|
||||||
|
var prevStatus, nextStatus string = "", ""
|
||||||
|
|
||||||
|
if page <= 1 {
|
||||||
|
prevStatus = " disabled"
|
||||||
|
}
|
||||||
|
|
||||||
|
if page >= lastPage {
|
||||||
|
nextStatus = " disabled"
|
||||||
|
}
|
||||||
|
|
||||||
|
prevPage := page - 1
|
||||||
|
if prevPage < 1 {
|
||||||
|
prevPage = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
nextPage := page + 1
|
||||||
|
if nextPage > lastPage {
|
||||||
|
nextPage = fileCount / PageLength
|
||||||
|
}
|
||||||
|
|
||||||
|
htmlBody.WriteString(fmt.Sprintf("<button onclick=\"window.location.href = '/html/%d';\">First</button>",
|
||||||
|
firstPage))
|
||||||
|
|
||||||
|
htmlBody.WriteString(fmt.Sprintf("<button onclick=\"window.location.href = '/html/%d';\"%s>Prev</button>",
|
||||||
|
prevPage,
|
||||||
|
prevStatus))
|
||||||
|
|
||||||
|
htmlBody.WriteString(fmt.Sprintf("<button onclick=\"window.location.href = '/html/%d';\"%s>Next</button>",
|
||||||
|
nextPage,
|
||||||
|
nextStatus))
|
||||||
|
|
||||||
|
htmlBody.WriteString(fmt.Sprintf("<button onclick=\"window.location.href = '/html/%d';\">Last</button>",
|
||||||
|
lastPage))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
htmlBody.WriteString(`</table></body></html>`)
|
htmlBody.WriteString(`</table></body></html>`)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReleaseVersion string = "2.1.0"
|
ReleaseVersion string = "2.0.3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
14
cmd/web.go
14
cmd/web.go
|
@ -385,6 +385,13 @@ func redirectRoot() httprouter.Handle {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServePage(args []string) error {
|
func ServePage(args []string) error {
|
||||||
|
if Verbose {
|
||||||
|
fmt.Printf("%s | START: roulette v%s\n",
|
||||||
|
time.Now().Format(logDate),
|
||||||
|
ReleaseVersion,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
timeZone := os.Getenv("TZ")
|
timeZone := os.Getenv("TZ")
|
||||||
if timeZone != "" {
|
if timeZone != "" {
|
||||||
var err error
|
var err error
|
||||||
|
@ -394,13 +401,6 @@ func ServePage(args []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if Verbose {
|
|
||||||
fmt.Printf("%s | START: roulette v%s\n",
|
|
||||||
time.Now().Format(logDate),
|
|
||||||
ReleaseVersion,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
bindHost, err := net.LookupHost(Bind)
|
bindHost, err := net.LookupHost(Bind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue