deleting and uploading files
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user