1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-26 10:36:23 -07:00

Use CookieMaxAge when making a post

This commit is contained in:
Eggbertx 2025-03-03 20:58:05 -08:00
parent b0e88c551d
commit 82099a76a7
3 changed files with 34 additions and 17 deletions

View file

@ -9,6 +9,7 @@ import (
"path"
"strings"
"testing"
"time"
"github.com/Eggbertx/durationutil"
"github.com/gochan-org/gochan/pkg/gcutil"
@ -335,6 +336,16 @@ type SiteConfig struct {
// FingerprintHashLength is the length of the hash used for image fingerprinting
// Default: 16
FingerprintHashLength int
cookieMaxAgeDuration time.Duration
}
func (sc *SiteConfig) CookieMaxAgeDuration() (time.Duration, error) {
var err error
if sc.cookieMaxAgeDuration == 0 {
sc.cookieMaxAgeDuration, err = durationutil.ParseLongerDuration(sc.CookieMaxAge)
}
return sc.cookieMaxAgeDuration, err
}
type CaptchaConfig struct {
@ -468,9 +479,9 @@ type Style struct {
}
type UploadConfig struct {
// RejectDuplicateImages determines whether to reject images that have already been uploaded
// RejectDuplicateUploads determines whether to reject images and videos that have already been uploaded
// Default: false
RejectDuplicateImages bool
RejectDuplicateUploads bool
// ThumbWidth is the maximum width that thumbnails in the top thread post will be scaled down to
// Default: 200

View file

@ -221,15 +221,6 @@ func NewBoardSimple(dir string, title string, subtitle string, description strin
RequireFile: false,
EnableCatalog: true,
}
// board.ShowID = false
// board.EnableSpoileredImages = true
// board.Worksafe = true
// board.ThreadsPerPage = 20
// board.Cooldowns = BoardCooldowns{
// NewThread: 30,
// Reply: 7,
// ImageReply: 7,
// }
return board, CreateBoard(board, appendToAllBoards)
}

View file

@ -131,20 +131,30 @@ func HandleFilterAction(filter *gcsql.Filter, post *gcsql.Post, upload *gcsql.Up
}
func setCookies(writer http.ResponseWriter, request *http.Request) {
maxAge, err := config.GetSiteConfig().CookieMaxAgeDuration()
if err != nil {
gcutil.LogError(err).Caller().
Str("IP", gcutil.GetRealIP(request)).
Str("userAgent", request.UserAgent()).
Str("cookieMaxAge", config.GetSiteConfig().CookieMaxAge).
Msg("Unable to parse configured cookie max age duration")
maxAge = yearInSeconds
}
http.SetCookie(writer, &http.Cookie{
Name: "email",
Value: url.QueryEscape(request.PostFormValue("postemail")),
MaxAge: yearInSeconds,
MaxAge: int(maxAge),
})
http.SetCookie(writer, &http.Cookie{
Name: "name",
Value: url.QueryEscape(request.PostFormValue("postname")),
MaxAge: yearInSeconds,
MaxAge: int(maxAge),
})
http.SetCookie(writer, &http.Cookie{
Name: "password",
Value: url.QueryEscape(request.PostFormValue("postpassword")),
MaxAge: yearInSeconds,
MaxAge: int(maxAge),
})
}
@ -248,10 +258,15 @@ func getRedirectURL(post *gcsql.Post, board *gcsql.Board, request *http.Request)
// MakePost is called when a user accesses /post. Parse form data, then insert and build
func MakePost(writer http.ResponseWriter, request *http.Request) {
request.ParseMultipartForm(maxFormBytes)
wantsJSON := serverutil.IsRequestingJSON(request)
infoEv, errEv := gcutil.LogRequest(request)
err := request.ParseMultipartForm(maxFormBytes)
if err != nil {
errEv.Err(err).Caller().Msg("Error parsing form data")
server.ServeError(writer, "Error parsing form data", serverutil.IsRequestingJSON(request), nil)
return
}
defer request.MultipartForm.RemoveAll()
wantsJSON := serverutil.IsRequestingJSON(request)
refererResult, err := serverutil.CheckReferer(request)
if err != nil {