Main Menu Dirty
This commit is contained in:
48
server.go
48
server.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"golang.org/x/text/language"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
@@ -10,6 +11,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@@ -78,7 +81,7 @@ func (s *Server) HandleNext(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
go s.LoadNext()
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||
http.Redirect(w, r, "/current/", http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
func (s *Server) LoadNext() {
|
||||
@@ -181,7 +184,7 @@ func (s *Server) HandlePrev(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
go s.LoadPrev()
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||
http.Redirect(w, r, "/current/", http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
func (s *Server) HandleCurrent(w http.ResponseWriter, _ *http.Request) {
|
||||
@@ -253,7 +256,7 @@ func (s *Server) HandleNew(w http.ResponseWriter, r *http.Request) {
|
||||
go s.LoadNext()
|
||||
go s.LoadPrev()
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||
http.Redirect(w, r, "/current/", http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
func (s *Server) LoadCurr() {
|
||||
@@ -304,3 +307,42 @@ func (s *Server) AppendImagesToBuf(html string) ([]Image, error) {
|
||||
wg.Wait()
|
||||
return images, nil
|
||||
}
|
||||
|
||||
func (s *Server) HandleMenu(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.Must(template.ParseFiles("menu.gohtml"))
|
||||
|
||||
all := s.DbMgr.Mangas.All()
|
||||
l := len(all)
|
||||
mangaViewModels := make([]MangaViewModel, l)
|
||||
|
||||
for i, manga := range all {
|
||||
title := cases.Title(language.English, cases.Compact).String(strings.Replace(manga.Title, "-", " ", -1))
|
||||
|
||||
mangaViewModels[i] = MangaViewModel{
|
||||
Title: title,
|
||||
Number: manga.LatestChapter.Value.Number,
|
||||
// I Hate this time Format... 15 = hh, 04 = mm, 02 = DD, 01 = MM, 06 == YY
|
||||
LastTime: time.Unix(manga.TimeStampUnix, 0).Format("15:04 (02-01-06)"),
|
||||
Url: manga.LatestChapter.Value.Url,
|
||||
}
|
||||
}
|
||||
|
||||
menuViewModel := MenuViewModel{
|
||||
Mangas: mangaViewModels,
|
||||
}
|
||||
|
||||
err := tmpl.Execute(w, menuViewModel)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) HandleExit(w http.ResponseWriter, r *http.Request) {
|
||||
err := s.DbMgr.Save()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user