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{ upload := &gcsql.Upload{
OriginalFilename: html.EscapeString(handler.Filename), OriginalFilename: html.EscapeString(handler.Filename),
FileSize: int(handler.Size),
} }
gcutil.LogStr("originalFilename", upload.OriginalFilename, errEv, infoEv) 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() Str("filePath", filePath).Send()
return err 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 // Get image width and height, as well as thumbnail width and height
upload.Width = img.Bounds().Max.X 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") 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 { if post.ThreadID == 0 {
// OP // OP
upload.ThumbnailWidth = boardConfig.ThumbWidth upload.ThumbnailWidth = boardConfig.ThumbWidth
@ -43,7 +35,8 @@ func processOther(upload *gcsql.Upload, post *gcsql.Post, board string, filePath
} }
staticThumbPath := path.Join("static/", cfgThumb) staticThumbPath := path.Join("static/", cfgThumb)
originalThumbPath := path.Join(config.GetSystemCriticalConfig().DocumentRoot, staticThumbPath) 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() errEv.Err(err).Str("originalThumbPath", originalThumbPath).Send()
return err return err
} }

View file

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