added copying and moving

This commit is contained in:
Daniel Goc
2026-04-03 11:25:16 +02:00
parent 395d670298
commit a988bbbc33
7 changed files with 201 additions and 0 deletions

View File

@@ -30,6 +30,8 @@ func StorageHandlerRoutes(r fiber.Router) fiber.Router {
r.Get("/list-content/*", handler.ListContent)
r.Get("/download-file/*", handler.DownloadFile)
r.Get("/move/*", handler.Move)
r.Get("/copy/*", handler.Copy)
r.Post("/upload-file/*", handler.UploadFile)
r.Get("/create-folder/*", handler.CreateFolder)
r.Delete("/delete-file/*", handler.DeleteFile)
@@ -38,6 +40,50 @@ func StorageHandlerRoutes(r fiber.Router) fiber.Router {
return r
}
func (h *StorageHandler) Move(c fiber.Ctx) error {
src_abs_path, err := h.storageService.AbsPath(h.config.Storage.RootFolder, c.Params("*"))
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
}
dest_abs_path, err := h.storageService.AbsPath(h.config.Storage.RootFolder, c.Query("dest_path"))
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
}
err = h.storageService.Move(src_abs_path, dest_abs_path)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
}
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
}
func (h *StorageHandler) Copy(c fiber.Ctx) error {
src_abs_path, err := h.storageService.AbsPath(h.config.Storage.RootFolder, c.Params("*"))
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
}
dest_abs_path, err := h.storageService.AbsPath(h.config.Storage.RootFolder, c.Query("dest_path"))
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
}
err = h.storageService.Copy(src_abs_path, dest_abs_path)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
}
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
}
// accepted path looks like e.g. "/folder1/" or "folder1"
func (h *StorageHandler) ListContent(c fiber.Ctx) error {
// relative path defaults to root directory