You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_space.go 2.5 kB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package http
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/gin-gonic/gin"
  6. "gitlink.org.cn/cloudream/common/consts/errorcode"
  7. "gitlink.org.cn/cloudream/common/pkgs/logger"
  8. cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
  9. )
  10. type UserSpaceService struct {
  11. *Server
  12. }
  13. func (s *Server) UserSpace() *UserSpaceService {
  14. return &UserSpaceService{
  15. Server: s,
  16. }
  17. }
  18. func (s *UserSpaceService) LoadPackage(ctx *gin.Context) {
  19. log := logger.WithField("HTTP", "UserSpace.LoadPackage")
  20. var req cliapi.UserSpaceLoadPackageReq
  21. if err := ctx.ShouldBindJSON(&req); err != nil {
  22. log.Warnf("binding body: %s", err.Error())
  23. ctx.JSON(http.StatusBadRequest, Failed(errorcode.BadArgument, "missing argument or invalid argument"))
  24. return
  25. }
  26. err := s.svc.UserSpaceSvc().LoadPackage(req.PackageID, req.UserSpaceID, req.RootPath)
  27. if err != nil {
  28. log.Warnf("loading package: %s", err.Error())
  29. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, "loading package failed"))
  30. return
  31. }
  32. ctx.JSON(http.StatusOK, OK(cliapi.UserSpaceLoadPackageResp{}))
  33. }
  34. func (s *UserSpaceService) CreatePackage(ctx *gin.Context) {
  35. log := logger.WithField("HTTP", "UserSpace.CreatePackage")
  36. var req cliapi.UserSpaceCreatePackageReq
  37. if err := ctx.ShouldBindJSON(&req); err != nil {
  38. log.Warnf("binding body: %s", err.Error())
  39. ctx.JSON(http.StatusBadRequest, Failed(errorcode.BadArgument, "missing argument or invalid argument"))
  40. return
  41. }
  42. pkg, err := s.svc.Uploader.UserSpaceUpload(req.UserSpaceID, req.Path, req.BucketID, req.Name, req.SpaceAffinity)
  43. if err != nil {
  44. log.Warnf("userspace create package: %s", err.Error())
  45. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, fmt.Sprintf("userspace create package: %v", err)))
  46. return
  47. }
  48. ctx.JSON(http.StatusOK, OK(cliapi.UserSpaceCreatePackageResp{
  49. Package: *pkg,
  50. }))
  51. }
  52. func (s *UserSpaceService) Get(ctx *gin.Context) {
  53. log := logger.WithField("HTTP", "UserSpace.Get")
  54. var req cliapi.UserSpaceGet
  55. if err := ctx.ShouldBindQuery(&req); err != nil {
  56. log.Warnf("binding query: %s", err.Error())
  57. ctx.JSON(http.StatusBadRequest, Failed(errorcode.BadArgument, "missing argument or invalid argument"))
  58. return
  59. }
  60. info, err := s.svc.UserSpaceSvc().Get(req.UserSpaceID)
  61. if err != nil {
  62. log.Warnf("getting info: %s", err.Error())
  63. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, "get userspace inf failed"))
  64. return
  65. }
  66. ctx.JSON(http.StatusOK, OK(cliapi.UserSpaceGetResp{
  67. UserSpace: info,
  68. }))
  69. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。