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.

cache.go 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. cdssdk "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 *cdssdk.UserID `json:"userID" binding:"required"`
  20. PackageID *cdssdk.PackageID `json:"packageID" binding:"required"`
  21. NodeID *cdssdk.NodeID `json:"nodeID" binding:"required"`
  22. }
  23. type CacheMovePackageResp = cdssdk.CacheMovePackageResp
  24. func (s *CacheService) MovePackage(ctx *gin.Context) {
  25. log := logger.WithField("HTTP", "Cache.LoadPackage")
  26. var req CacheMovePackageReq
  27. if err := ctx.ShouldBindJSON(&req); err != nil {
  28. log.Warnf("binding body: %s", err.Error())
  29. ctx.JSON(http.StatusBadRequest, Failed(errorcode.BadArgument, "missing argument or invalid argument"))
  30. return
  31. }
  32. taskID, err := s.svc.CacheSvc().StartCacheMovePackage(*req.UserID, *req.PackageID, *req.NodeID)
  33. if err != nil {
  34. log.Warnf("start cache move package: %s", err.Error())
  35. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, "cache move package failed"))
  36. return
  37. }
  38. for {
  39. complete, err := s.svc.CacheSvc().WaitCacheMovePackage(*req.NodeID, taskID, time.Second*10)
  40. if complete {
  41. if err != nil {
  42. log.Warnf("moving complete with: %s", err.Error())
  43. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, "cache move package failed"))
  44. return
  45. }
  46. ctx.JSON(http.StatusOK, OK(CacheMovePackageResp{}))
  47. return
  48. }
  49. if err != nil {
  50. log.Warnf("wait moving: %s", err.Error())
  51. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, "cache move package failed"))
  52. return
  53. }
  54. }
  55. }

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