diff --git a/html/html.go b/html/html.go index 0ae268e..9f6fa2c 100644 --- a/html/html.go +++ b/html/html.go @@ -14,7 +14,28 @@ type Entry struct { Size int64 } -func FileListPage(req string, entries []Entry) string { +func FileListPage(req string, entries []Entry, big_preview_mode bool) string { + headerCSS1 := "" + if !big_preview_mode { + headerCSS1 = "display: flex;" + } else { + headerCSS1 = "width: 320px;" + } + headerCSS2 := "" + if !big_preview_mode { + headerCSS2 = `width: 48px;height: 48px;` + } else { + headerCSS2 = `width: 256px;height: 256px;` + } + linkSuffixToggle := "" + linkSuffix := "" + if big_preview_mode { + linkSuffixToggle = "" + linkSuffix = "?big_preview=true" + } else { + linkSuffixToggle = "?big_preview=true" + linkSuffix = "" + } header := fmt.Sprintf(` @@ -58,6 +79,7 @@ func FileListPage(req string, entries []Entry) string { } #footer { text-align: left; + margin-bottom: 64px; } a { color: var(--text-color); @@ -65,15 +87,15 @@ func FileListPage(req string, entries []Entry) string { font-size: 32px; } .entry { - display: flex; + %s } .entry-name { margin-left: 16px; margin-right: auto; } .entry-icon{ - width: 48px; - height: 48px; + %s + image-rendering: pixelated; } #leech { image-rendering: pixelated; @@ -81,6 +103,16 @@ func FileListPage(req string, entries []Entry) string { height:256px; width:auto; } + .left-entry{ + margin-right: auto; + } + .row { + display: flex; + } + #toggle-big-preview-link { + text-decoration-line: underline; + text-decoration-style: wavy; + } %s | leech.ontake.dev @@ -94,9 +126,9 @@ func FileListPage(req string, entries []Entry) string { -
`, req, req) +
`, headerCSS1, headerCSS2, req, req) - footer := `

` + footer := fmt.Sprintf(`

`, linkSuffixToggle) body := "" entriesWithParent := []Entry{} @@ -108,7 +140,7 @@ func FileListPage(req string, entries []Entry) string { }) } entriesWithParent = append(entriesWithParent, entries...) - for _, dirEntry := range entriesWithParent { + for i, dirEntry := range entriesWithParent { formattedSize := "" if dirEntry.Size != -1 { formattedSize = humanize.Bytes(uint64(dirEntry.Size)) @@ -133,7 +165,21 @@ func FileListPage(req string, entries []Entry) string { if dirEntry.IsDir { icon = "/assets/images/diricon.png" } - body += fmt.Sprintf(`
%s
%s
`, link, icon, dirEntry.Name, formattedSize) + newLine := "" + alignCSSClass := "" + if big_preview_mode { + if i%2 == 0 { + alignCSSClass = `class="left-entry"` + if i != 0 { + newLine += "" + } + newLine += "
" + } + } + body += fmt.Sprintf(`%s
%s
%s
`, newLine, link, linkSuffix, alignCSSClass, icon, dirEntry.Name, formattedSize) + } + if big_preview_mode { + body += "
" } return header + body + footer } diff --git a/route/route.go b/route/route.go index af32439..474c87f 100644 --- a/route/route.go +++ b/route/route.go @@ -43,6 +43,7 @@ func HandleList(c *fiber.Ctx) error { if err != nil { return c.Status(fiber.StatusInternalServerError).SendString(err.Error()) } + bigPreview := c.QueryBool("big_preview") c.Set(fiber.HeaderContentType, fiber.MIMETextHTML) if req == "" { keys := make([]string, 0, len(config.Config.ServeDirs)) @@ -64,7 +65,7 @@ func HandleList(c *fiber.Ctx) error { }) } - return c.SendString(html.FileListPage(req, entries)) + return c.SendString(html.FileListPage(req, entries, bigPreview)) } else { pathSlice := strings.Split(req, "/") pathBase, ok := config.Config.ServeDirs[pathSlice[0]] @@ -94,7 +95,7 @@ func HandleList(c *fiber.Ctx) error { IsDir: f.IsDir(), }) } - return c.SendString(html.FileListPage(req, entries)) + return c.SendString(html.FileListPage(req, entries, bigPreview)) } else { return c.Status(fiber.StatusNotFound).SendString("Sorry can't find that!") }