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.

cacah.go 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package http
  2. import (
  3. "net/http"
  4. "time"
  5. "github.com/gin-gonic/gin"
  6. "gitlink.org.cn/cloudream/common/consts/errorcode"
  7. "gitlink.org.cn/cloudream/common/pkgs/logger"
  8. stgsdk "gitlink.org.cn/cloudream/common/sdks/storage"
  9. )
  10. type CacheService struct {
  11. *Server
  12. }
  13. func (s *Server) CacheSvc() *CacheService {
  14. return &CacheService{
  15. Server: s,
  16. }
  17. }
  18. type CacheMovePackageReq struct {
  19. UserID *int64 `json:"userID" binding:"required"`
  20. PackageID *int64 `json:"packageID" binding:"required"`
  21. NodeID *int64 `json:"nodeID" binding:"required"`
  22. }
  23. type CacheMovePackageResp struct {
  24. CacheInfos []stgsdk.ObjectCacheInfo `json:"cacheInfos"`
  25. }
  26. func (s *CacheService) MovePackage(ctx *gin.Context) {
  27. log := logger.WithField("HTTP", "Cache.LoadPackage")
  28. var req CacheMovePackageReq
  29. if err := ctx.ShouldBindJSON(&req); err != nil {
  30. log.Warnf("binding body: %s", err.Error())
  31. ctx.JSON(http.StatusBadRequest, Failed(errorcode.BadArgument, "missing argument or invalid argument"))
  32. return
  33. }
  34. taskID, err := s.svc.CacheSvc().StartCacheMovePackage(*req.UserID, *req.PackageID, *req.NodeID)
  35. if err != nil {
  36. log.Warnf("start cache move package: %s", err.Error())
  37. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, "cache move package failed"))
  38. return
  39. }
  40. for {
  41. complete, cacheInfos, err := s.svc.CacheSvc().WaitCacheMovePackage(*req.NodeID, taskID, time.Second*10)
  42. if complete {
  43. if err != nil {
  44. log.Warnf("moving complete with: %s", err.Error())
  45. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, "cache move package failed"))
  46. return
  47. }
  48. ctx.JSON(http.StatusOK, OK(CacheMovePackageResp{
  49. CacheInfos: cacheInfos,
  50. }))
  51. return
  52. }
  53. if err != nil {
  54. log.Warnf("wait moving: %s", err.Error())
  55. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, "cache move package failed"))
  56. return
  57. }
  58. }
  59. }

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