Testing out the settings page
This commit is contained in:
parent
bfeb243f6c
commit
8e0bfc327f
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
||||||
config.yml
|
config.yml
|
||||||
tmp/
|
tmp/
|
||||||
.air.toml
|
.air.toml
|
||||||
|
/.dir-locals.el
|
||||||
|
|
10
configs/session.go
Normal file
10
configs/session.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package configs
|
||||||
|
|
||||||
|
import "github.com/gofiber/fiber/v2/middleware/session"
|
||||||
|
|
||||||
|
var Store *session.Store
|
||||||
|
|
||||||
|
func SetupStorage() {
|
||||||
|
Store = session.New()
|
||||||
|
Store.RegisterType("")
|
||||||
|
}
|
12
main.go
12
main.go
|
@ -6,13 +6,10 @@ import (
|
||||||
"pixivfe/handler"
|
"pixivfe/handler"
|
||||||
"pixivfe/views"
|
"pixivfe/views"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/cache"
|
"github.com/gofiber/fiber/v2/middleware/cache"
|
||||||
"github.com/gofiber/fiber/v2/middleware/csrf"
|
|
||||||
// "github.com/gofiber/fiber/v2/middleware/helmet"
|
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
"github.com/gofiber/fiber/v2/utils"
|
"github.com/gofiber/fiber/v2/utils"
|
||||||
"github.com/gofiber/template/jet/v2"
|
"github.com/gofiber/template/jet/v2"
|
||||||
|
@ -42,14 +39,6 @@ func setupRouter() *fiber.App {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
// server.Use(helmet.New())
|
|
||||||
server.Use(csrf.New(csrf.Config{
|
|
||||||
KeyLookup: "header:X-Csrf-Token", // string in the form of '<source>:<key>' that is used to extract token from the request
|
|
||||||
CookieName: "my_csrf_", // name of the session cookie
|
|
||||||
CookieSameSite: "Strict", // indicates if CSRF cookie is requested by SameSite
|
|
||||||
Expiration: 3 * time.Hour, // expiration is the duration before CSRF token will expire
|
|
||||||
KeyGenerator: utils.UUID, // creates a new CSRF token
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Static files
|
// Static files
|
||||||
server.Static("/favicon.ico", "./template/favicon.ico")
|
server.Static("/favicon.ico", "./template/favicon.ico")
|
||||||
|
@ -67,6 +56,7 @@ func setupRouter() *fiber.App {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := configs.ParseConfig()
|
err := configs.ParseConfig()
|
||||||
|
configs.SetupStorage()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
<a href="#" class="navbar-button">
|
<a href="#" class="navbar-button">
|
||||||
<img src="/assets/search.png" alt="Search" width="30" height="30" />
|
<img src="/assets/search.png" alt="Search" width="30" height="30" />
|
||||||
</a>
|
</a>
|
||||||
<a href="#" class="navbar-button">
|
<a href="/settings" class="navbar-button">
|
||||||
<img src="/assets/settings.png" alt="Settings" width="30" height="30" />
|
<img src="/assets/settings.png" alt="Settings" width="30" height="30" />
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -1,68 +1,40 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2>Settings</h2>
|
<h2>Settings</h2>
|
||||||
<form action="/settings" method="post">
|
<form action="/setting" method="post">
|
||||||
<fieldset class="settings-fieldset">
|
<fieldset class="settings-fieldset">
|
||||||
<legend>Proxy server {{ Settings.Proxy }}</legend>
|
<legend>Custom token</legend>
|
||||||
<input
|
<input type="text" name="token" autocomplete="off" />
|
||||||
type="radio"
|
<input type="submit" />
|
||||||
name="image-proxy-server"
|
</fieldset>
|
||||||
id="image-proxy-server"
|
</form>
|
||||||
value="i.pixiv.cat"
|
<form action="/setting" method="post">
|
||||||
/>
|
<fieldset class="settings-fieldset">
|
||||||
<label for="image-proxy-server">i.pixiv.cat</label>
|
<legend>Proxy server</legend>
|
||||||
<br />
|
<input type="radio" name="image-proxy-server" id="image-proxy-server" value="i.pixiv.cat" />
|
||||||
<input
|
<label for="image-proxy-server">i.pixiv.cat</label>
|
||||||
type="radio"
|
<br />
|
||||||
name="image-proxy-server"
|
<input type="radio" name="image-proxy-server" id="image-proxy-server" value="px2.rainchan.win" />
|
||||||
id="image-proxy-server"
|
<label for="image-proxy-server">px2.rainchan.win</label>
|
||||||
value="px2.rainchan.win"
|
<br />
|
||||||
/>
|
<input type="radio" name="image-proxy-server" id="image-proxy-server" value="px3.rainchan.win" />
|
||||||
<label for="image-proxy-server">px2.rainchan.win</label>
|
<label for="image-proxy-server">px3.rainchan.win</label>
|
||||||
<br />
|
<br />
|
||||||
<input
|
<input type="radio" name="image-proxy-server" id="image-proxy-server" value="px.s.rainchan.win" />
|
||||||
type="radio"
|
<label for="image-proxy-server">px.s.rainchan.win</label>
|
||||||
name="image-proxy-server"
|
<br />
|
||||||
id="image-proxy-server"
|
<input type="radio" name="image-proxy-server" id="image-proxy-server" value="sex.nyan.xyz" />
|
||||||
value="px3.rainchan.win"
|
<label for="image-proxy-server">___.nyan.xyz</label>
|
||||||
/>
|
<br />
|
||||||
<label for="image-proxy-server">px3.rainchan.win</label>
|
<input type="radio" name="image-proxy-server" id="image-proxy-server" value="pximg.wjghj.cn" />
|
||||||
<br />
|
<label for="image-proxy-server">pximg.wjghj.cn</label>
|
||||||
<input
|
<br />
|
||||||
type="radio"
|
<br />
|
||||||
name="image-proxy-server"
|
<label for="image-proxy-server">Custom image proxy server</label>
|
||||||
id="image-proxy-server"
|
<br />
|
||||||
value="px.s.rainchan.win"
|
<input type="text" name="image-proxy-server" id="image-proxy-server" placeholder="Paste the address here..."
|
||||||
/>
|
autocomplete="off" />
|
||||||
<label for="image-proxy-server">px.s.rainchan.win</label>
|
<br />
|
||||||
<br />
|
<input type="submit" value="Apply" />
|
||||||
<input
|
</fieldset>
|
||||||
type="radio"
|
</form>
|
||||||
name="image-proxy-server"
|
|
||||||
id="image-proxy-server"
|
|
||||||
value="sex.nyan.xyz"
|
|
||||||
/>
|
|
||||||
<label for="image-proxy-server">___.nyan.xyz</label>
|
|
||||||
<br />
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="image-proxy-server"
|
|
||||||
id="image-proxy-server"
|
|
||||||
value="pximg.wjghj.cn"
|
|
||||||
/>
|
|
||||||
<label for="image-proxy-server">pximg.wjghj.cn</label>
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<label for="image-proxy-server">Custom image proxy server</label>
|
|
||||||
<br />
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
name="image-proxy-server"
|
|
||||||
id="image-proxy-server"
|
|
||||||
placeholder="Paste the address here..."
|
|
||||||
autocomplete="off"
|
|
||||||
/>
|
|
||||||
<br />
|
|
||||||
<input type="submit" value="Apply" />
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -52,6 +52,16 @@ func index_page(c *fiber.Ctx) error {
|
||||||
// "Spotlights": spotlight,
|
// "Spotlights": spotlight,
|
||||||
// "Newest": newest,
|
// "Newest": newest,
|
||||||
// })
|
// })
|
||||||
|
sess, err := configs.Store.Get(c)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
token := sess.Get("token")
|
||||||
|
|
||||||
|
if token != nil {
|
||||||
|
println(token.(string))
|
||||||
|
}
|
||||||
|
|
||||||
return c.Render("temp", fiber.Map{"Title": "Landing"})
|
return c.Render("temp", fiber.Map{"Title": "Landing"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +175,28 @@ func discovery_page(c *fiber.Ctx) error {
|
||||||
return c.Render("discovery", fiber.Map{"Title": "Discovery", "Artworks": artworks})
|
return c.Render("discovery", fiber.Map{"Title": "Discovery", "Artworks": artworks})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func settings_page(c *fiber.Ctx) error {
|
||||||
|
return c.Render("settings", fiber.Map{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func settings_handler(c *fiber.Ctx) error {
|
||||||
|
sess, err := configs.Store.Get(c)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
token := c.FormValue("token")
|
||||||
|
if token != "" {
|
||||||
|
sess.Set("token", token)
|
||||||
|
|
||||||
|
if err := sess.Save(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return c.Redirect("/settings/", http.StatusAccepted)
|
||||||
|
}
|
||||||
|
return c.Redirect("/settings/", http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
||||||
// func not_found_page(c *fiber.Ctx) {
|
// func not_found_page(c *fiber.Ctx) {
|
||||||
// return c.Render(http.StatusNotFound, "error.html", fiber.Map{
|
// return c.Render(http.StatusNotFound, "error.html", fiber.Map{
|
||||||
// "Title": "Not found",
|
// "Title": "Not found",
|
||||||
|
@ -204,6 +236,9 @@ func SetupRoutes(r *fiber.App) {
|
||||||
r.Get("discovery", discovery_page)
|
r.Get("discovery", discovery_page)
|
||||||
r.Post("tags", search)
|
r.Post("tags", search)
|
||||||
|
|
||||||
|
r.Get("settings", settings_page)
|
||||||
|
r.Post("setting", settings_handler)
|
||||||
|
|
||||||
// 404 page
|
// 404 page
|
||||||
// r.NoRoute(not_found_page)
|
// r.NoRoute(not_found_page)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue