mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-02 15:06:23 -07:00
Enable processing of files with extensions explicitly allowed by the admin
This commit is contained in:
parent
ef5a9f49c3
commit
530011be61
4 changed files with 21 additions and 9 deletions
BIN
html/static/otherthumb.png
Normal file
BIN
html/static/otherthumb.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
@ -393,7 +393,16 @@ type UploadConfig struct {
|
|||
ExiftoolPath string
|
||||
}
|
||||
|
||||
func (uc *UploadConfig) AcceptexExtension(filename string) bool {
|
||||
func (uc *UploadConfig) AcceptedOtherExtension(ext string) bool {
|
||||
for _, allowedExt := range uc.AllowOtherExtensions {
|
||||
if ext == allowedExt {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (uc *UploadConfig) AcceptedExtension(filename string) bool {
|
||||
ext := strings.ToLower(path.Ext(filename))
|
||||
switch ext {
|
||||
// images
|
||||
|
@ -420,12 +429,7 @@ func (uc *UploadConfig) AcceptexExtension(filename string) bool {
|
|||
case ".zip":
|
||||
return uc.AllowUploadingZipFiles
|
||||
}
|
||||
for _, allowedExt := range uc.AllowOtherExtensions {
|
||||
if ext == allowedExt {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return uc.AcceptedOtherExtension(ext)
|
||||
}
|
||||
|
||||
type PostConfig struct {
|
||||
|
|
|
@ -60,7 +60,7 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
|
|||
gcutil.LogStr("originalFilename", upload.OriginalFilename, errEv, infoEv)
|
||||
|
||||
boardConfig := config.GetBoardConfig(postBoard.Dir)
|
||||
if !boardConfig.AcceptexExtension(upload.OriginalFilename) {
|
||||
if !boardConfig.AcceptedExtension(upload.OriginalFilename) {
|
||||
errEv.Caller().Msg("Upload filetype not supported")
|
||||
server.ServeError(writer, "Upload filetype not supported", wantsJSON, map[string]interface{}{
|
||||
"filename": upload.OriginalFilename,
|
||||
|
@ -190,7 +190,7 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
|
|||
upload.ThumbnailWidth, upload.ThumbnailHeight = getThumbnailSize(
|
||||
upload.Width, upload.Height, postBoard.Dir, thumbType)
|
||||
}
|
||||
} else if ext == ".pdf" || ext == ".zip" {
|
||||
} else if ext == ".pdf" || ext == ".zip" || boardConfig.AcceptedOtherExtension(ext) {
|
||||
stat, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
|
@ -212,8 +212,16 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
|
|||
switch ext {
|
||||
case ".pdf":
|
||||
staticThumbPath = "static/pdfthumb.png"
|
||||
case ".txt":
|
||||
staticThumbPath = "static/txtthumb.png"
|
||||
case ".gz":
|
||||
fallthrough
|
||||
case ".xz":
|
||||
fallthrough
|
||||
case ".zip":
|
||||
staticThumbPath = "static/archivethumb.png"
|
||||
default:
|
||||
staticThumbPath = "static/otherthumb.png"
|
||||
}
|
||||
originalThumbPath := path.Join(documentRoot, staticThumbPath)
|
||||
if _, err = os.Stat(originalThumbPath); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue