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.

object.go 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package services
  2. import (
  3. "fmt"
  4. "time"
  5. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  6. mytask "gitlink.org.cn/cloudream/storage/client/internal/task"
  7. stgglb "gitlink.org.cn/cloudream/storage/common/globals"
  8. "gitlink.org.cn/cloudream/storage/common/pkgs/db/model"
  9. "gitlink.org.cn/cloudream/storage/common/pkgs/downloader"
  10. "gitlink.org.cn/cloudream/storage/common/pkgs/iterator"
  11. coormq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/coordinator"
  12. )
  13. type ObjectService struct {
  14. *Service
  15. }
  16. func (svc *Service) ObjectSvc() *ObjectService {
  17. return &ObjectService{Service: svc}
  18. }
  19. func (svc *ObjectService) StartUploading(userID cdssdk.UserID, packageID cdssdk.PackageID, objIter iterator.UploadingObjectIterator, nodeAffinity *cdssdk.NodeID) (string, error) {
  20. tsk := svc.TaskMgr.StartNew(mytask.NewUploadObjects(userID, packageID, objIter, nodeAffinity))
  21. return tsk.ID(), nil
  22. }
  23. func (svc *ObjectService) WaitUploading(taskID string, waitTimeout time.Duration) (bool, *mytask.UploadObjectsResult, error) {
  24. tsk := svc.TaskMgr.FindByID(taskID)
  25. if tsk.WaitTimeout(waitTimeout) {
  26. updatePkgTask := tsk.Body().(*mytask.UploadObjects)
  27. return true, updatePkgTask.Result, tsk.Error()
  28. }
  29. return false, nil, nil
  30. }
  31. func (svc *ObjectService) UpdateInfo(userID cdssdk.UserID, updatings []cdssdk.UpdatingObject) ([]cdssdk.ObjectID, error) {
  32. coorCli, err := stgglb.CoordinatorMQPool.Acquire()
  33. if err != nil {
  34. return nil, fmt.Errorf("new coordinator client: %w", err)
  35. }
  36. defer stgglb.CoordinatorMQPool.Release(coorCli)
  37. resp, err := coorCli.UpdateObjectInfos(coormq.ReqUpdateObjectInfos(userID, updatings))
  38. if err != nil {
  39. return nil, fmt.Errorf("requsting to coodinator: %w", err)
  40. }
  41. return resp.Successes, nil
  42. }
  43. func (svc *ObjectService) Move(userID cdssdk.UserID, movings []cdssdk.MovingObject) ([]cdssdk.ObjectID, error) {
  44. coorCli, err := stgglb.CoordinatorMQPool.Acquire()
  45. if err != nil {
  46. return nil, fmt.Errorf("new coordinator client: %w", err)
  47. }
  48. defer stgglb.CoordinatorMQPool.Release(coorCli)
  49. resp, err := coorCli.MoveObjects(coormq.ReqMoveObjects(userID, movings))
  50. if err != nil {
  51. return nil, fmt.Errorf("requsting to coodinator: %w", err)
  52. }
  53. return resp.Successes, nil
  54. }
  55. func (svc *ObjectService) Download(userID cdssdk.UserID, req downloader.DownloadReqeust) (*downloader.Downloading, error) {
  56. // TODO 检查用户ID
  57. iter := svc.Downloader.DownloadObjects([]downloader.DownloadReqeust{req})
  58. downloading, err := iter.MoveNext()
  59. if downloading.Object == nil {
  60. return nil, fmt.Errorf("object not found")
  61. }
  62. if err != nil {
  63. return nil, err
  64. }
  65. return downloading, nil
  66. }
  67. func (svc *ObjectService) Delete(userID cdssdk.UserID, objectIDs []cdssdk.ObjectID) error {
  68. coorCli, err := stgglb.CoordinatorMQPool.Acquire()
  69. if err != nil {
  70. return fmt.Errorf("new coordinator client: %w", err)
  71. }
  72. defer stgglb.CoordinatorMQPool.Release(coorCli)
  73. _, err = coorCli.DeleteObjects(coormq.ReqDeleteObjects(userID, objectIDs))
  74. if err != nil {
  75. return fmt.Errorf("requsting to coodinator: %w", err)
  76. }
  77. return nil
  78. }
  79. func (svc *ObjectService) GetPackageObjects(userID cdssdk.UserID, packageID cdssdk.PackageID) ([]model.Object, error) {
  80. coorCli, err := stgglb.CoordinatorMQPool.Acquire()
  81. if err != nil {
  82. return nil, fmt.Errorf("new coordinator client: %w", err)
  83. }
  84. defer stgglb.CoordinatorMQPool.Release(coorCli)
  85. getResp, err := coorCli.GetPackageObjects(coormq.NewGetPackageObjects(userID, packageID))
  86. if err != nil {
  87. return nil, fmt.Errorf("requsting to coodinator: %w", err)
  88. }
  89. return getResp.Objects, nil
  90. }

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