deleting and uploading files
This commit is contained in:
@@ -30,10 +30,10 @@ func StorageHandlerRoutes(r fiber.Router) fiber.Router {
|
||||
r.Get("/list-content", handler.ListContent)
|
||||
r.Get("/download-file", handler.DownloadFile)
|
||||
|
||||
r.Post("/upload-file", handler.CreateFolder)
|
||||
r.Post("/upload-file", handler.UploadFile)
|
||||
r.Get("/create-folder", handler.CreateFolder)
|
||||
r.Get("/delete-file", handler.DeleteFile)
|
||||
r.Get("/delete-folder", handler.DeleteFolder)
|
||||
r.Delete("/delete-file", handler.DeleteFile)
|
||||
r.Delete("/delete-folder", handler.DeleteFolder)
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -88,12 +88,11 @@ func (h *StorageHandler) UploadFile(c fiber.Ctx) error {
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrMissingFileFieldDocument)))
|
||||
}
|
||||
|
||||
err = h.storageService.UploadFile(abs_path, c.Query("name"), f)
|
||||
err = h.storageService.UploadFile(c, abs_path, f)
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||
}
|
||||
err = c.SaveFile(f, abs_path)
|
||||
|
||||
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ import (
|
||||
"os"
|
||||
|
||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
type UIStorageRepo interface {
|
||||
EntryInfo(abs_path string) (os.FileInfo, error)
|
||||
ListContent(abs_path string) (*[]model.EntryInList, error)
|
||||
OpenFile(abs_path string) (*os.File, error)
|
||||
UploadFile(abs_path string, f *multipart.FileHeader) error
|
||||
UploadFile(c fiber.Ctx, abs_path string, f *multipart.FileHeader) error
|
||||
CreateFolder(abs_path string) error
|
||||
DeleteFile(abs_path string) error
|
||||
DeleteFolder(abs_path string) error
|
||||
@@ -50,8 +51,8 @@ func (r *StorageRepo) OpenFile(abs_path string) (*os.File, error) {
|
||||
return os.Open(abs_path)
|
||||
}
|
||||
|
||||
func (r *StorageRepo) UploadFile(abs_path string, f *multipart.FileHeader) error {
|
||||
return nil
|
||||
func (r *StorageRepo) UploadFile(c fiber.Ctx, abs_path string, f *multipart.FileHeader) error {
|
||||
return c.SaveFile(f, abs_path)
|
||||
}
|
||||
|
||||
func (r *StorageRepo) CreateFolder(abs_path string) error {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: add-new-cart
|
||||
type: http
|
||||
seq: 11
|
||||
seq: 14
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: add-product-to-cart (1)
|
||||
type: http
|
||||
seq: 16
|
||||
seq: 19
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: add-product-to-cart
|
||||
type: http
|
||||
seq: 15
|
||||
seq: 18
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: change-cart-name
|
||||
type: http
|
||||
seq: 12
|
||||
seq: 15
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
info:
|
||||
name: create-folder
|
||||
type: http
|
||||
seq: 22
|
||||
seq: 24
|
||||
|
||||
http:
|
||||
method: GET
|
||||
url: http://localhost:3000/api/v1/restricted/storage/create-folder?path&name=../k
|
||||
url: http://localhost:3000/api/v1/restricted/storage/create-folder?path=&name=folder
|
||||
params:
|
||||
- name: path
|
||||
value: ""
|
||||
type: query
|
||||
- name: name
|
||||
value: ../k
|
||||
value: folder
|
||||
type: query
|
||||
auth: inherit
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: create-index
|
||||
type: http
|
||||
seq: 7
|
||||
seq: 10
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
19
bruno/b2b-daniel/delete-file.yml
Normal file
19
bruno/b2b-daniel/delete-file.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
info:
|
||||
name: delete-file
|
||||
type: http
|
||||
seq: 25
|
||||
|
||||
http:
|
||||
method: DELETE
|
||||
url: http://localhost:3000/api/v1/restricted/storage/delete-file?path=/folder/test.txt
|
||||
params:
|
||||
- name: path
|
||||
value: /folder/test.txt
|
||||
type: query
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
@@ -1,14 +1,14 @@
|
||||
info:
|
||||
name: delete-entry
|
||||
name: delete-folder
|
||||
type: http
|
||||
seq: 23
|
||||
seq: 26
|
||||
|
||||
http:
|
||||
method: GET
|
||||
url: http://localhost:3000/api/v1/restricted/storage/delete-entry?path=folder2
|
||||
method: DELETE
|
||||
url: http://localhost:3000/api/v1/restricted/storage/delete-folder?path=/folder/
|
||||
params:
|
||||
- name: path
|
||||
value: folder2
|
||||
value: /folder/
|
||||
type: query
|
||||
auth: inherit
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: download-file
|
||||
type: http
|
||||
seq: 20
|
||||
seq: 22
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: get-breadcrumb
|
||||
type: http
|
||||
seq: 18
|
||||
seq: 20
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: get-category-tree
|
||||
type: http
|
||||
seq: 5
|
||||
seq: 8
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
info:
|
||||
name: get-description
|
||||
type: http
|
||||
seq: 24
|
||||
|
||||
http:
|
||||
method: GET
|
||||
url: http://localhost:3000/api/v1/restricted/product-translation/get-product-description?productID=51&productLangID=2
|
||||
params:
|
||||
- name: productID
|
||||
value: "51"
|
||||
type: query
|
||||
- name: productLangID
|
||||
value: "2"
|
||||
type: query
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: get-indexes
|
||||
type: http
|
||||
seq: 9
|
||||
seq: 12
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: get-product-description
|
||||
type: http
|
||||
seq: 17
|
||||
seq: 1
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: get_countries
|
||||
type: http
|
||||
seq: 4
|
||||
seq: 7
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: list-content
|
||||
type: http
|
||||
seq: 19
|
||||
seq: 21
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: list-products
|
||||
type: http
|
||||
seq: 1
|
||||
seq: 4
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: list-users
|
||||
type: http
|
||||
seq: 2
|
||||
seq: 5
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: remove-index
|
||||
type: http
|
||||
seq: 8
|
||||
seq: 11
|
||||
|
||||
http:
|
||||
method: DELETE
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: retrieve-cart
|
||||
type: http
|
||||
seq: 14
|
||||
seq: 17
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: retrieve-carts-info
|
||||
type: http
|
||||
seq: 13
|
||||
seq: 16
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: save-product-description
|
||||
type: http
|
||||
seq: 25
|
||||
seq: 3
|
||||
|
||||
http:
|
||||
method: POST
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: search
|
||||
type: http
|
||||
seq: 10
|
||||
seq: 13
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: test
|
||||
type: http
|
||||
seq: 6
|
||||
seq: 9
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: translate-product-description
|
||||
type: http
|
||||
seq: 19
|
||||
seq: 2
|
||||
|
||||
http:
|
||||
method: GET
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
info:
|
||||
name: update-choice
|
||||
type: http
|
||||
seq: 3
|
||||
seq: 6
|
||||
|
||||
http:
|
||||
method: POST
|
||||
|
||||
26
bruno/b2b-daniel/upload-file.yml
Normal file
26
bruno/b2b-daniel/upload-file.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
info:
|
||||
name: upload-file
|
||||
type: http
|
||||
seq: 23
|
||||
|
||||
http:
|
||||
method: POST
|
||||
url: http://localhost:3000/api/v1/restricted/storage/upload-file?path=folder/
|
||||
params:
|
||||
- name: path
|
||||
value: folder/
|
||||
type: query
|
||||
body:
|
||||
type: multipart-form
|
||||
data:
|
||||
- name: document
|
||||
type: file
|
||||
value:
|
||||
- /home/daniel/coding/work/b2b/storage/folder1/test.txt
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
1
storage/test.txt
Normal file
1
storage/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
This is a test.
|
||||
Reference in New Issue
Block a user