storage #46
@@ -30,10 +30,10 @@ func StorageHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
r.Get("/list-content", handler.ListContent)
|
r.Get("/list-content", handler.ListContent)
|
||||||
r.Get("/download-file", handler.DownloadFile)
|
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("/create-folder", handler.CreateFolder)
|
||||||
r.Get("/delete-file", handler.DeleteFile)
|
r.Delete("/delete-file", handler.DeleteFile)
|
||||||
r.Get("/delete-folder", handler.DeleteFolder)
|
r.Delete("/delete-folder", handler.DeleteFolder)
|
||||||
|
|
||||||
return r
|
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)))
|
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 {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, 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)))
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
|
"github.com/gofiber/fiber/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UIStorageRepo interface {
|
type UIStorageRepo interface {
|
||||||
EntryInfo(abs_path string) (os.FileInfo, error)
|
EntryInfo(abs_path string) (os.FileInfo, error)
|
||||||
ListContent(abs_path string) (*[]model.EntryInList, error)
|
ListContent(abs_path string) (*[]model.EntryInList, error)
|
||||||
OpenFile(abs_path string) (*os.File, 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
|
CreateFolder(abs_path string) error
|
||||||
DeleteFile(abs_path string) error
|
DeleteFile(abs_path string) error
|
||||||
DeleteFolder(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)
|
return os.Open(abs_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *StorageRepo) UploadFile(abs_path string, f *multipart.FileHeader) error {
|
func (r *StorageRepo) UploadFile(c fiber.Ctx, abs_path string, f *multipart.FileHeader) error {
|
||||||
return nil
|
return c.SaveFile(f, abs_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *StorageRepo) CreateFolder(abs_path string) error {
|
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/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/repos/storageRepo"
|
"git.ma-al.com/goc_daniel/b2b/app/repos/storageRepo"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
"github.com/gofiber/fiber/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StorageService struct {
|
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
|
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)
|
info, err := s.storageRepo.EntryInfo(abs_path)
|
||||||
if err != nil || !info.IsDir() {
|
if err != nil || !info.IsDir() {
|
||||||
return responseErrors.ErrFolderDoesNotExist
|
return responseErrors.ErrFolderDoesNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name := f.Filename
|
||||||
if name == "" || name == "." || name == ".." || filepath.Base(name) != name {
|
if name == "" || name == "." || name == ".." || filepath.Base(name) != name {
|
||||||
return responseErrors.ErrBadAttribute
|
return responseErrors.ErrBadAttribute
|
||||||
}
|
}
|
||||||
@@ -66,7 +68,7 @@ func (s *StorageService) UploadFile(abs_path string, name string, f *multipart.F
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return responseErrors.ErrNameTaken
|
return responseErrors.ErrNameTaken
|
||||||
} else if os.IsNotExist(err) {
|
} else if os.IsNotExist(err) {
|
||||||
return s.storageRepo.UploadFile(abs_file_path, f)
|
return s.storageRepo.UploadFile(c, abs_file_path, f)
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: add-new-cart
|
name: add-new-cart
|
||||||
type: http
|
type: http
|
||||||
seq: 11
|
seq: 14
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: add-product-to-cart (1)
|
name: add-product-to-cart (1)
|
||||||
type: http
|
type: http
|
||||||
seq: 16
|
seq: 19
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: add-product-to-cart
|
name: add-product-to-cart
|
||||||
type: http
|
type: http
|
||||||
seq: 15
|
seq: 18
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: change-cart-name
|
name: change-cart-name
|
||||||
type: http
|
type: http
|
||||||
seq: 12
|
seq: 15
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
info:
|
info:
|
||||||
name: create-folder
|
name: create-folder
|
||||||
type: http
|
type: http
|
||||||
seq: 22
|
seq: 24
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
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:
|
params:
|
||||||
- name: path
|
- name: path
|
||||||
value: ""
|
value: ""
|
||||||
type: query
|
type: query
|
||||||
- name: name
|
- name: name
|
||||||
value: ../k
|
value: folder
|
||||||
type: query
|
type: query
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: create-index
|
name: create-index
|
||||||
type: http
|
type: http
|
||||||
seq: 7
|
seq: 10
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
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:
|
info:
|
||||||
name: delete-entry
|
name: delete-folder
|
||||||
type: http
|
type: http
|
||||||
seq: 23
|
seq: 26
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: DELETE
|
||||||
url: http://localhost:3000/api/v1/restricted/storage/delete-entry?path=folder2
|
url: http://localhost:3000/api/v1/restricted/storage/delete-folder?path=/folder/
|
||||||
params:
|
params:
|
||||||
- name: path
|
- name: path
|
||||||
value: folder2
|
value: /folder/
|
||||||
type: query
|
type: query
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: download-file
|
name: download-file
|
||||||
type: http
|
type: http
|
||||||
seq: 20
|
seq: 22
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: get-breadcrumb
|
name: get-breadcrumb
|
||||||
type: http
|
type: http
|
||||||
seq: 18
|
seq: 20
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: get-category-tree
|
name: get-category-tree
|
||||||
type: http
|
type: http
|
||||||
seq: 5
|
seq: 8
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
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:
|
info:
|
||||||
name: get-indexes
|
name: get-indexes
|
||||||
type: http
|
type: http
|
||||||
seq: 9
|
seq: 12
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: get-product-description
|
name: get-product-description
|
||||||
type: http
|
type: http
|
||||||
seq: 17
|
seq: 1
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: get_countries
|
name: get_countries
|
||||||
type: http
|
type: http
|
||||||
seq: 4
|
seq: 7
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: list-content
|
name: list-content
|
||||||
type: http
|
type: http
|
||||||
seq: 19
|
seq: 21
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: list-products
|
name: list-products
|
||||||
type: http
|
type: http
|
||||||
seq: 1
|
seq: 4
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: list-users
|
name: list-users
|
||||||
type: http
|
type: http
|
||||||
seq: 2
|
seq: 5
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: remove-index
|
name: remove-index
|
||||||
type: http
|
type: http
|
||||||
seq: 8
|
seq: 11
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: DELETE
|
method: DELETE
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: retrieve-cart
|
name: retrieve-cart
|
||||||
type: http
|
type: http
|
||||||
seq: 14
|
seq: 17
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: retrieve-carts-info
|
name: retrieve-carts-info
|
||||||
type: http
|
type: http
|
||||||
seq: 13
|
seq: 16
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: save-product-description
|
name: save-product-description
|
||||||
type: http
|
type: http
|
||||||
seq: 25
|
seq: 3
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: POST
|
method: POST
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: search
|
name: search
|
||||||
type: http
|
type: http
|
||||||
seq: 10
|
seq: 13
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: test
|
name: test
|
||||||
type: http
|
type: http
|
||||||
seq: 6
|
seq: 9
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: translate-product-description
|
name: translate-product-description
|
||||||
type: http
|
type: http
|
||||||
seq: 19
|
seq: 2
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: update-choice
|
name: update-choice
|
||||||
type: http
|
type: http
|
||||||
seq: 3
|
seq: 6
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: POST
|
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