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

Don't depend on each file handler function to get file size

This commit is contained in:
Eggbertx 2023-07-14 08:38:21 -07:00
parent cfbe7a8ffb
commit b0e81aac99
4 changed files with 3 additions and 19 deletions

View file

@ -71,6 +71,7 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
}
upload := &gcsql.Upload{
OriginalFilename: html.EscapeString(handler.Filename),
FileSize: int(handler.Size),
}
gcutil.LogStr("originalFilename", upload.OriginalFilename, errEv, infoEv)

View file

@ -54,14 +54,6 @@ func processImage(upload *gcsql.Upload, post *gcsql.Post, board string, filePath
Str("filePath", filePath).Send()
return err
}
// Get image filesize
stat, err := os.Stat(filePath)
if err != nil {
errEv.Err(err).Caller().
Str("filePath", filePath).Send()
return err
}
upload.FileSize = int(stat.Size())
// Get image width and height, as well as thumbnail width and height
upload.Width = img.Bounds().Max.X

View file

@ -24,14 +24,6 @@ func processOther(upload *gcsql.Upload, post *gcsql.Post, board string, filePath
}
infoEv.Str("post", "withOther")
stat, err := os.Stat(filePath)
if err != nil {
errEv.Err(err).Caller().
Str("filePath", filePath).Send()
return err
}
upload.FileSize = int(stat.Size())
if post.ThreadID == 0 {
// OP
upload.ThumbnailWidth = boardConfig.ThumbWidth
@ -43,7 +35,8 @@ func processOther(upload *gcsql.Upload, post *gcsql.Post, board string, filePath
}
staticThumbPath := path.Join("static/", cfgThumb)
originalThumbPath := path.Join(config.GetSystemCriticalConfig().DocumentRoot, staticThumbPath)
if _, err = os.Stat(originalThumbPath); err != nil {
_, err := os.Stat(originalThumbPath)
if err != nil {
errEv.Err(err).Str("originalThumbPath", originalThumbPath).Send()
return err
}

View file

@ -58,8 +58,6 @@ func processVideo(upload *gcsql.Upload, post *gcsql.Post, board string, filePath
upload.Width = value
case "height":
upload.Height = value
case "size":
upload.FileSize = value
}
}
thumbType := ThumbnailReply