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

7 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package http
  2. /*
  3. import (
  4. "net/http"
  5. "time"
  6. "github.com/gin-gonic/gin"
  7. "gitlink.org.cn/cloudream/common/consts/errorcode"
  8. "gitlink.org.cn/cloudream/common/pkgs/logger"
  9. cdssdk "gitlink.org.cn/cloudream/jcs-pub/client/types"
  10. cdsapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
  11. )
  12. type CacheService struct {
  13. *Server
  14. }
  15. func (s *Server) Cache() *CacheService {
  16. return &CacheService{
  17. Server: s,
  18. }
  19. }
  20. type CacheMovePackageReq struct {
  21. UserID cdssdk.UserID `json:"userID" binding:"required"`
  22. PackageID cdssdk.PackageID `json:"packageID" binding:"required"`
  23. StorageID cdssdk.StorageID `json:"storageID" binding:"required"`
  24. }
  25. type CacheMovePackageResp = cdsapi.CacheMovePackageResp
  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. hubID, taskID, err := s.svc.CacheSvc().StartCacheMovePackage(req.PackageID, req.StorageID)
  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, err := s.svc.CacheSvc().WaitCacheMovePackage(hubID, 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. return
  50. }
  51. if err != nil {
  52. log.Warnf("wait moving: %s", err.Error())
  53. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, "cache move package failed"))
  54. return
  55. }
  56. }
  57. }
  58. */

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