fix: reduce memory usage
Some checks failed
Format and Lint / format-check (push) Failing after 4s
Format and Lint / test (push) Successful in 53s

This commit is contained in:
Максим Слипенко 2025-01-08 15:30:48 +03:00
parent 0d56779189
commit 939f14eb86
2 changed files with 4 additions and 4 deletions

View file

@ -46,7 +46,7 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
return
}
err := r.ParseMultipartForm(10240 << 20)
err := r.ParseMultipartForm(10 << 20)
if err != nil {
render.Render(w, r, &commonErrors.ErrResponse{
HTTPStatusCode: http.StatusBadRequest,
@ -57,7 +57,7 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
files := r.MultipartForm.File["files"]
for _, fileHeader := range files {
if fileHeader.Size > (1024 << 20) {
if fileHeader.Size > (4096 << 20) {
render.Render(w, r, &commonErrors.ErrResponse{
HTTPStatusCode: http.StatusBadRequest,
StatusText: "File too large",

View file

@ -86,7 +86,6 @@ func (s *Service) Upload(input *TaskUploadInput) error {
if err != nil {
return fmt.Errorf("can't open fileHeader %w", err)
}
defer file.Close()
if !strings.HasSuffix(fileHeader.Filename, ".rpm") {
return fmt.Errorf("invalid file type: only .rpm files are allowed")
@ -107,12 +106,13 @@ func (s *Service) Upload(input *TaskUploadInput) error {
if err != nil {
return err
}
defer outFile.Close()
_, err = io.Copy(outFile, file)
if err != nil {
return err
}
outFile.Close()
file.Close()
pkg, err := rpm.Open(filePath)
if err != nil {