mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
update settings page
- allow clearing image proxy - allow clearing all settings
This commit is contained in:
+12
-5
@@ -16,6 +16,9 @@ const (
|
||||
Cookie_ImageProxy CookieName = "__Host-pixivfe-ImageProxy"
|
||||
)
|
||||
|
||||
// Go can't make this a const...
|
||||
var AllCookieNames = []CookieName{Cookie_Token, Cookie_CSRF, Cookie_ImageProxy}
|
||||
|
||||
func GetCookie(c *fiber.Ctx, name CookieName, defaultValue ...string) string {
|
||||
return c.Cookies(string(name), defaultValue...)
|
||||
}
|
||||
@@ -24,20 +27,24 @@ func SetCookie(c *fiber.Ctx, name CookieName, value string) {
|
||||
cookie := fiber.Cookie{
|
||||
Name: string(name),
|
||||
Value: value,
|
||||
Path: "/",
|
||||
Path: "/",
|
||||
// expires in 30 days from now
|
||||
Expires: c.Context().Time().Add(30 * (24 * time.Hour)),
|
||||
Expires: c.Context().Time().Add(30 * (24 * time.Hour)),
|
||||
HTTPOnly: true,
|
||||
Secure: true,
|
||||
Secure: true,
|
||||
SameSite: fiber.CookieSameSiteStrictMode, // bye-bye cross site forgery
|
||||
}
|
||||
c.Cookie(&cookie)
|
||||
}
|
||||
|
||||
func ClearCookie(c *fiber.Ctx, name CookieName) {
|
||||
c.ClearCookie(string(name))
|
||||
// c.ClearCookie(string(name)) // gofiber bug
|
||||
SetCookie(c, name, "")
|
||||
}
|
||||
|
||||
func ClearAllCookies(c *fiber.Ctx) {
|
||||
c.ClearCookie()
|
||||
// c.ClearCookie() // gofiber bug
|
||||
for _, name := range AllCookieNames {
|
||||
SetCookie(c, name, "")
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -5,9 +5,7 @@
|
||||
/settings/
|
||||
|
||||
- [x] Merge login page with settings page
|
||||
- [ ] Persistence
|
||||
A JSON file to store values.
|
||||
This way, values set by users won't be lost after restarts.
|
||||
- [x] Persistence (http-only secure cookies)
|
||||
- [User Settings](user-customization.md)
|
||||
|
||||
/novel/
|
||||
|
||||
+19
-2
@@ -71,9 +71,10 @@ func setImageServer(c *fiber.Ctx) error {
|
||||
token := c.FormValue("image-proxy")
|
||||
if token != "" {
|
||||
session.SetCookie(c, session.Cookie_ImageProxy, token)
|
||||
return nil
|
||||
} else {
|
||||
session.ClearCookie(c, session.Cookie_ImageProxy)
|
||||
}
|
||||
return errors.New("You submitted an empty/invalid form.")
|
||||
return nil
|
||||
}
|
||||
|
||||
func setLogout(c *fiber.Ctx) error {
|
||||
@@ -81,8 +82,22 @@ func setLogout(c *fiber.Ctx) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resetAll(c *fiber.Ctx) error {
|
||||
session.ClearAllCookies(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
func SettingsPage(c *fiber.Ctx) error {
|
||||
cookies := []fiber.Map{}
|
||||
for _, name := range session.AllCookieNames {
|
||||
value := session.GetCookie(c, name)
|
||||
cookies = append(cookies, fiber.Map{
|
||||
"Key": name,
|
||||
"Value": value,
|
||||
})
|
||||
}
|
||||
return c.Render("pages/settings", fiber.Map{
|
||||
"CookieList": cookies,
|
||||
"ProxyList": doc.BuiltinProxyList,
|
||||
})
|
||||
}
|
||||
@@ -98,6 +113,8 @@ func SettingsPost(c *fiber.Ctx) error {
|
||||
err = setToken(c)
|
||||
case "logout":
|
||||
err = setLogout(c)
|
||||
case "reset-all":
|
||||
err = resetAll(c)
|
||||
default:
|
||||
err = errors.New("no such setting available")
|
||||
}
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
<div class="container" data-hx-boost="false">
|
||||
<h2>Current Settings</h2>
|
||||
{{ range CookieList }}
|
||||
<div>
|
||||
<span>{{.Key}}</span>=<span>{{.Value}}</span>
|
||||
</div>
|
||||
{{ end }}
|
||||
<form action="/settings/reset-all" method="post">
|
||||
<input type="submit" value="Reset All" />
|
||||
</form>
|
||||
<h2>Login</h2>
|
||||
<p>Supported features (for now):</p>
|
||||
<ul>
|
||||
@@ -31,27 +40,30 @@
|
||||
<form action="/settings/logout" method="post">
|
||||
<input type="submit" value="Logout!" />
|
||||
</form>
|
||||
<hr />
|
||||
|
||||
<h2>Image proxy server</h2>
|
||||
<div class="form-field">
|
||||
<form action="/settings/image_server" method="post">
|
||||
{{ range ProxyList }}
|
||||
<label>
|
||||
<input type="radio" name="image-proxy" required="true" value="{{.}}" />
|
||||
{{filterWordsIDK: .}}
|
||||
</label>
|
||||
{{ end }}
|
||||
<input type="submit" value="Use Selected Proxy" />
|
||||
</form>
|
||||
<br />
|
||||
<form action="/settings/image_server" method="post">
|
||||
<label for="image-proxy">
|
||||
Custom image proxy server
|
||||
<input type="text" name="image-proxy" required="true" placeholder="https://example.com"
|
||||
autocomplete="off" />
|
||||
</label>
|
||||
<input type="submit" value="Use Custom Proxy" />
|
||||
</form>
|
||||
</div>
|
||||
<hr />
|
||||
<h2>Image proxy server</h2>
|
||||
<div class="form-field">
|
||||
<form action="/settings/image_server" method="post">
|
||||
<label>
|
||||
<input type="radio" name="image-proxy" required="true" value="" />
|
||||
No (use built-in proxy)
|
||||
</label>
|
||||
{{ range ProxyList }}
|
||||
<label>
|
||||
<input type="radio" name="image-proxy" required="true" value="{{.}}" />
|
||||
{{filterWordsIDK: .}}
|
||||
</label>
|
||||
{{ end }}
|
||||
<input type="submit" value="Use Selected Proxy" />
|
||||
</form>
|
||||
<br />
|
||||
<form action="/settings/image_server" method="post">
|
||||
<label for="image-proxy">
|
||||
Custom image proxy server
|
||||
<input type="text" name="image-proxy" required="true" placeholder="https://example.com"
|
||||
autocomplete="off" />
|
||||
</label>
|
||||
<input type="submit" value="Use Custom Proxy" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user