mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-30 09:56:23 -07:00
Show error if spoilered file is uploaded on a board (or site) that doesn't allow it
This commit is contained in:
parent
e27d020d54
commit
9a1784dbbe
2 changed files with 12 additions and 4 deletions
|
@ -420,7 +420,7 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
if !captchaSuccess {
|
||||
server.ServeError(writer, "Missing or invalid captcha response", wantsJSON, nil)
|
||||
errEv.Msg("Missing or invalid captcha response")
|
||||
warnEv.Msg("Missing or invalid captcha response")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -434,12 +434,12 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
_, _, err = request.FormFile("imagefile")
|
||||
noFile := errors.Is(err, http.ErrMissingFile)
|
||||
if noFile && post.ThreadID == 0 && boardConfig.NewThreadsRequireUpload {
|
||||
errEv.Caller().Msg("New thread rejected (NewThreadsRequireUpload set in config)")
|
||||
warnEv.Caller().Msg("New thread rejected (NewThreadsRequireUpload set in config)")
|
||||
server.ServeError(writer, "Upload required for new threads", wantsJSON, nil)
|
||||
return
|
||||
}
|
||||
if post.MessageRaw == "" && noFile {
|
||||
errEv.Caller().Msg("New post rejected (no file and message is blank)")
|
||||
warnEv.Caller().Msg("New post rejected (no file and message is blank)")
|
||||
server.ServeError(writer, "Your post must have an upload or a comment", wantsJSON, nil)
|
||||
return
|
||||
}
|
||||
|
@ -455,7 +455,6 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
|
||||
upload, err := uploads.AttachUploadFromRequest(request, writer, post, board, infoEv, errEv)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
// got an error receiving the upload or the upload was rejected
|
||||
server.ServeError(writer, err.Error(), wantsJSON, nil)
|
||||
return
|
||||
|
|
|
@ -30,6 +30,7 @@ var (
|
|||
VideoExtensions = []string{
|
||||
".mp4", ".webm",
|
||||
}
|
||||
ErrSpoileredImagesNotAllowed = errors.New("spoilered images are not allowed on this board")
|
||||
)
|
||||
|
||||
type UploadHandler func(upload *gcsql.Upload, post *gcsql.Post, board string, filePath string, thumbPath string, catalogThumbPath string, infoEv *zerolog.Event, accessEv *zerolog.Event, errEv *zerolog.Event) error
|
||||
|
@ -142,6 +143,14 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
|
|||
|
||||
upload.IsSpoilered = request.FormValue("spoiler") == "on"
|
||||
gcutil.LogBool("isSpoiler", upload.IsSpoilered, infoEv, accessEv, errEv)
|
||||
if upload.IsSpoilered && !boardConfig.EnableSpoileredImages {
|
||||
gcutil.LogWarning().
|
||||
Str("IP", gcutil.GetRealIP(request)).
|
||||
Str("userAgent", request.UserAgent()).
|
||||
Str("board", postBoard.Dir).
|
||||
Msg("User attempted to post a spoilered file on a board that doesn't allow it")
|
||||
return nil, ErrSpoileredImagesNotAllowed
|
||||
}
|
||||
|
||||
uploadHandler, ok := uploadHandlers[ext]
|
||||
if !ok {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue