mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
Remove duplicated imports and fix cookies?
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"codeberg.org/vnpower/pixivfe/v2/session"
|
||||
"net/http"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"codeberg.org/vnpower/pixivfe/v2/core"
|
||||
"codeberg.org/vnpower/pixivfe/v2/session"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func PromptUserToLoginPage(c *http.Request) error {
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SPximgProxy(c *http.Request) error {
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"codeberg.org/vnpower/pixivfe/v2/utils"
|
||||
|
||||
"github.com/CloudyKit/jet/v6"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// global variable, yes.
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"codeberg.org/vnpower/pixivfe/v2/config"
|
||||
httpc "codeberg.org/vnpower/pixivfe/v2/core"
|
||||
"codeberg.org/vnpower/pixivfe/v2/session"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// todo: allow clear proxy
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"codeberg.org/vnpower/pixivfe/v2/core"
|
||||
"codeberg.org/vnpower/pixivfe/v2/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func TagPage(c *http.Request) error {
|
||||
|
||||
+17
-10
@@ -38,37 +38,44 @@ var AllCookieNames []CookieName = []CookieName{
|
||||
}
|
||||
|
||||
func GetCookie(c *http.Request, name CookieName, defaultValue ...string) string {
|
||||
return c.Cookies(string(name), defaultValue...)
|
||||
//return c.Cookies(string(name), defaultValue...)
|
||||
if cookie, err := c.Cookie(string(name)); err != nil {
|
||||
return cookie.Value
|
||||
}
|
||||
|
||||
// TODO: Hard-coded?
|
||||
return defaultValue[0]
|
||||
}
|
||||
|
||||
func SetCookie(c *http.Request, name CookieName, value string) {
|
||||
cookie := fiber.Cookie{
|
||||
cookie := http.Cookie{
|
||||
Name: string(name),
|
||||
Value: value,
|
||||
Path: "/",
|
||||
// expires in 30 days from now
|
||||
Expires: c.Context().Time().Add(30 * (24 * time.Hour)),
|
||||
HTTPOnly: true,
|
||||
// Expires: c.Context().Time().Add(30 * (24 * time.Hour)),
|
||||
Expires: time.Now().Add(30 * (24 * time.Hour)),
|
||||
HttpOnly: true,
|
||||
Secure: true,
|
||||
SameSite: fiber.CookieSameSiteStrictMode, // bye-bye cross site forgery
|
||||
SameSite: http.SameSiteStrictMode, // bye-bye cross site forgery
|
||||
}
|
||||
c.Cookie(&cookie)
|
||||
c.AddCookie(&cookie)
|
||||
}
|
||||
|
||||
var CookieExpireDelete = time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||
|
||||
func ClearCookie(c *http.Request, name CookieName) {
|
||||
cookie := fiber.Cookie{
|
||||
cookie := http.Cookie{
|
||||
Name: string(name),
|
||||
Value: "",
|
||||
Path: "/",
|
||||
// expires in 30 days from now
|
||||
Expires: CookieExpireDelete,
|
||||
HTTPOnly: true,
|
||||
HttpOnly: true,
|
||||
Secure: true,
|
||||
SameSite: fiber.CookieSameSiteStrictMode,
|
||||
SameSite: http.SameSiteStrictMode,
|
||||
}
|
||||
c.Cookie(&cookie)
|
||||
c.AddCookie(&cookie)
|
||||
}
|
||||
|
||||
func ClearAllCookies(c *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user