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.9 kB

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

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