deleting and uploading files

This commit is contained in:
Daniel Goc
2026-04-02 11:26:58 +02:00
parent b9bc121d43
commit 833f4a5a07
31 changed files with 88 additions and 62 deletions

View File

@@ -9,6 +9,7 @@ import (
"git.ma-al.com/goc_daniel/b2b/app/model"
"git.ma-al.com/goc_daniel/b2b/app/repos/storageRepo"
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
"github.com/gofiber/fiber/v3"
)
type StorageService struct {
@@ -45,12 +46,13 @@ func (s *StorageService) DownloadFilePrep(abs_path string) (*os.File, string, in
return f, filepath.Base(abs_path), info.Size(), nil
}
func (s *StorageService) UploadFile(abs_path string, name string, f *multipart.FileHeader) error {
func (s *StorageService) UploadFile(c fiber.Ctx, abs_path string, f *multipart.FileHeader) error {
info, err := s.storageRepo.EntryInfo(abs_path)
if err != nil || !info.IsDir() {
return responseErrors.ErrFolderDoesNotExist
}
name := f.Filename
if name == "" || name == "." || name == ".." || filepath.Base(name) != name {
return responseErrors.ErrBadAttribute
}
@@ -66,7 +68,7 @@ func (s *StorageService) UploadFile(abs_path string, name string, f *multipart.F
if err == nil {
return responseErrors.ErrNameTaken
} else if os.IsNotExist(err) {
return s.storageRepo.UploadFile(abs_file_path, f)
return s.storageRepo.UploadFile(c, abs_file_path, f)
} else {
return err
}