diff --git a/routes/actions.go b/routes/actions.go index 9c70473..ebdfe33 100644 --- a/routes/actions.go +++ b/routes/actions.go @@ -8,7 +8,6 @@ import ( "net/http" "codeberg.org/vnpower/pixivfe/v2/session" - "net/http" "github.com/tidwall/gjson" ) diff --git a/routes/personal.go b/routes/personal.go index e627148..39cda86 100644 --- a/routes/personal.go +++ b/routes/personal.go @@ -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 { diff --git a/routes/proxy.go b/routes/proxy.go index 6afffce..f3c5792 100644 --- a/routes/proxy.go +++ b/routes/proxy.go @@ -4,8 +4,6 @@ import ( "fmt" "io" "net/http" - - "net/http" ) func SPximgProxy(c *http.Request) error { diff --git a/routes/render.go b/routes/render.go index ccd2c47..db90e9e 100644 --- a/routes/render.go +++ b/routes/render.go @@ -12,7 +12,6 @@ import ( "codeberg.org/vnpower/pixivfe/v2/utils" "github.com/CloudyKit/jet/v6" - "net/http" ) // global variable, yes. diff --git a/routes/settings.go b/routes/settings.go index 505999e..43213ad 100644 --- a/routes/settings.go +++ b/routes/settings.go @@ -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 diff --git a/routes/tag.go b/routes/tag.go index fe4be91..bdcecdc 100644 --- a/routes/tag.go +++ b/routes/tag.go @@ -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 { diff --git a/session/cookie.go b/session/cookie.go index 7dcf90f..27bdafb 100644 --- a/session/cookie.go +++ b/session/cookie.go @@ -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) {