Add Update Button

This commit is contained in:
Pablu23
2024-05-30 20:36:03 +02:00
parent 8de5bb0fdc
commit 16be88a849
3 changed files with 189 additions and 167 deletions

View File

@@ -18,8 +18,12 @@ import (
"time" "time"
) )
func (s *Server) HandleUpdate(w http.ResponseWriter, r *http.Request){
s.UpdateMangaList()
http.Redirect(w, r, "/", http.StatusFound)
}
func (s *Server) HandleLoginPost(w http.ResponseWriter, r *http.Request) { func (s *Server) HandleLoginPost(w http.ResponseWriter, r *http.Request) {
fmt.Println("Setting auth")
secret := r.PostFormValue("secret") secret := r.PostFormValue("secret")
http.SetCookie(w, &http.Cookie{ http.SetCookie(w, &http.Cookie{
Name: "auth", Name: "auth",

View File

@@ -67,6 +67,7 @@ func (s *Server) RegisterRoutes() {
s.mux.HandleFunc("/favicon.ico", s.HandleFavicon) s.mux.HandleFunc("/favicon.ico", s.HandleFavicon)
s.mux.HandleFunc("POST /setting/", s.HandleSetting) s.mux.HandleFunc("POST /setting/", s.HandleSetting)
s.mux.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet) s.mux.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet)
s.mux.HandleFunc("GET /update", s.HandleUpdate)
} }
func (s *Server) StartTLS(port int, certFile, keyFile string) error { func (s *Server) StartTLS(port int, certFile, keyFile string) error {
@@ -89,11 +90,7 @@ func (s *Server) Start(port int) error {
return server.ListenAndServe() return server.ListenAndServe()
} }
func (s *Server) RegisterUpdater(interval time.Duration) { func (s *Server) UpdateMangaList() {
go func(s *Server) {
for {
select {
case <-time.After(interval):
var all []*database.Manga var all []*database.Manga
s.DbMgr.Db.Find(&all) s.DbMgr.Db.Find(&all)
for _, m := range all { for _, m := range all {
@@ -105,6 +102,14 @@ func (s *Server) RegisterUpdater(interval time.Duration) {
s.DbMgr.Db.Save(m) s.DbMgr.Db.Save(m)
} }
} }
}
func (s *Server) RegisterUpdater(interval time.Duration) {
go func(s *Server) {
for {
select {
case <-time.After(interval):
s.UpdateMangaList()
} }
} }
}(s) }(s)

View File

@@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<!--suppress CssUnusedSymbol --> <!--suppress CssUnusedSymbol -->
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Main Menu</title> <title>Main Menu</title>
@@ -31,7 +32,7 @@
color: #FFFFFF; color: #FFFFFF;
cursor: pointer; cursor: pointer;
flex-shrink: 0; flex-shrink: 0;
font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif; font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
font-size: 16px; font-size: 16px;
font-weight: 500; font-weight: 500;
height: 4rem; height: 4rem;
@@ -53,12 +54,13 @@
.button-36 { .button-36 {
padding: 0 2.6rem; padding: 0 2.6rem;
} }
.button-delete{
.button-delete {
padding: 0 2.6rem; padding: 0 2.6rem;
} }
} }
.button-delete{ .button-delete {
background-image: linear-gradient(92.88deg, #f44336 9.16%, #f44336 43.89%, #f44336 64.72%); background-image: linear-gradient(92.88deg, #f44336 9.16%, #f44336 43.89%, #f44336 64.72%);
border-radius: 8px; border-radius: 8px;
border-style: none; border-style: none;
@@ -66,7 +68,7 @@
color: #FFFFFF; color: #FFFFFF;
cursor: pointer; cursor: pointer;
flex-shrink: 0; flex-shrink: 0;
font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif; font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
font-size: 16px; font-size: 16px;
font-weight: 500; font-weight: 500;
height: 4rem; height: 4rem;
@@ -84,18 +86,22 @@
transition-duration: .1s; transition-duration: .1s;
} }
.table-left{ .table-left {
text-align: left; text-align: left;
} }
.thumbnail{ .thumbnail {
border: 1px solid #ddd; /* Gray border */ border: 1px solid #ddd;
border-radius: 4px; /* Rounded border */ /* Gray border */
padding: 5px; /* Some padding */ border-radius: 4px;
width: 150px; /* Set a small width */ /* Rounded border */
padding: 5px;
/* Some padding */
width: 150px;
/* Set a small width */
} }
.thumbnail:hover{ .thumbnail:hover {
box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5); box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5);
} }
@@ -103,7 +109,7 @@
width: 100%; width: 100%;
} }
td{ td {
text-align: center; text-align: center;
} }
@@ -119,10 +125,10 @@
margin-bottom: 10px; margin-bottom: 10px;
margin-top: 10px; margin-top: 10px;
} }
</style> </style>
</head> </head>
<body class="{{(index .Settings "theme").Value}}">
<body class="{{(index .Settings " theme").Value}}">
<form method="post" action="/new/"> <form method="post" action="/new/">
<label> <label>
New Sub Url New Sub Url
@@ -131,11 +137,17 @@
<input type="submit" value="Open" class="button-36"> <input type="submit" value="Open" class="button-36">
</form> </form>
<a href="/update">
<button class="button-36">
Update Chapters
</button>
</a>
<form method="post" action="/setting/"> <form method="post" action="/setting/">
<label for="theme">Theme</label> <label for="theme">Theme</label>
<select onchange="this.form.submit()" id="theme" name="theme"> <select onchange="this.form.submit()" id="theme" name="theme">
<option {{if eq (index .Settings "theme").Value "white"}} selected {{end}} value="white">White</option> <option {{if eq (index .Settings "theme" ).Value "white" }} selected {{end}} value="white">White</option>
<option {{if eq (index .Settings "theme").Value "dark"}} selected {{end}} value="dark">Dark</option> <option {{if eq (index .Settings "theme" ).Value "dark" }} selected {{end}} value="dark">Dark</option>
</select> </select>
<input type="hidden" name="setting" value="theme"> <input type="hidden" name="setting" value="theme">
</form> </form>
@@ -153,7 +165,7 @@
<tr> <tr>
<td> <td>
<a target="_blank" href="/img/{{.ThumbnailUrl}}"> <a target="_blank" href="/img/{{.ThumbnailUrl}}">
<img class="thumbnail" src="/img/{{.ThumbnailUrl}}" alt="img_{{.ThumbnailUrl}}"/> <img class="thumbnail" src="/img/{{.ThumbnailUrl}}" alt="img_{{.ThumbnailUrl}}" />
</a> </a>
</td> </td>
<td class="table-left">{{.Title}}</td> <td class="table-left">{{.Title}}</td>
@@ -176,4 +188,5 @@
{{end}} {{end}}
</table> </table>
</body> </body>
</html> </html>