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.

pub_shards.go 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package rpc
  2. import (
  3. "context"
  4. "gitlink.org.cn/cloudream/jcs-pub/common/ecode"
  5. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc"
  6. hubrpc "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc/hub"
  7. )
  8. func (svc *Service) PubShardsStore(ctx context.Context, msg *hubrpc.PubShardsStore) (*hubrpc.PubShardsStoreResp, *rpc.CodeError) {
  9. authInfo, ok := rpc.GetAuthInfo(ctx)
  10. if !ok {
  11. return nil, rpc.Failed(ecode.Unauthorized, "unauthorized")
  12. }
  13. pubShards, cerr := svc.pubShards.GetOrLoad(msg.PubShardsID, msg.Password)
  14. if cerr != nil {
  15. return nil, rpc.Failed(ecode.OperationFailed, "load pub shards store: %v", cerr)
  16. }
  17. info, err := pubShards.StoreShard(authInfo.UserID, msg.Path, msg.Hash, msg.Size)
  18. if err != nil {
  19. return nil, rpc.Failed(ecode.OperationFailed, "store file: %v", err)
  20. }
  21. return &hubrpc.PubShardsStoreResp{
  22. Info: info,
  23. }, nil
  24. }
  25. func (svc *Service) PubShardsInfo(ctx context.Context, msg *hubrpc.PubShardsInfo) (*hubrpc.PubShardsInfoResp, *rpc.CodeError) {
  26. pubShards, err := svc.pubShards.GetOrLoad(msg.PubShardsID, msg.Password)
  27. if err != nil {
  28. return nil, rpc.Failed(ecode.OperationFailed, "load pub shards store: %v", err)
  29. }
  30. info, err := pubShards.InfoShard(msg.FileHash)
  31. if err != nil {
  32. return nil, rpc.Failed(ecode.OperationFailed, err.Error())
  33. }
  34. return &hubrpc.PubShardsInfoResp{
  35. Info: info,
  36. }, nil
  37. }
  38. func (svc *Service) PubShardsListAll(ctx context.Context, msg *hubrpc.PubShardsListAll) (*hubrpc.PubShardsListAllResp, *rpc.CodeError) {
  39. authInfo, ok := rpc.GetAuthInfo(ctx)
  40. if !ok {
  41. return nil, rpc.Failed(ecode.Unauthorized, "unauthorized")
  42. }
  43. pubShards, err := svc.pubShards.GetOrLoad(msg.PubShardsID, msg.Password)
  44. if err != nil {
  45. return nil, rpc.Failed(ecode.OperationFailed, "load pub shards store: %v", err)
  46. }
  47. infos, err := pubShards.ListUserAll(authInfo.UserID)
  48. if err != nil {
  49. return nil, rpc.Failed(ecode.OperationFailed, "list all: %v", err)
  50. }
  51. return &hubrpc.PubShardsListAllResp{
  52. Infos: infos,
  53. }, nil
  54. }
  55. func (svc *Service) PubShardsGC(ctx context.Context, msg *hubrpc.PubShardsGC) (*hubrpc.PubShardsGCResp, *rpc.CodeError) {
  56. authInfo, ok := rpc.GetAuthInfo(ctx)
  57. if !ok {
  58. return nil, rpc.Failed(ecode.Unauthorized, "unauthorized")
  59. }
  60. pubShards, err := svc.pubShards.GetOrLoad(msg.PubShardsID, msg.Password)
  61. if err != nil {
  62. return nil, rpc.Failed(ecode.OperationFailed, "load pub shards store: %v", err)
  63. }
  64. err = pubShards.GC(authInfo.UserID, msg.FileHashes)
  65. if err != nil {
  66. return nil, rpc.Failed(ecode.OperationFailed, "reset hashes: %v", err)
  67. }
  68. return &hubrpc.PubShardsGCResp{}, nil
  69. }
  70. func (svc *Service) PubShardsStats(ctx context.Context, msg *hubrpc.PubShardsStats) (*hubrpc.PubShardsStatsResp, *rpc.CodeError) {
  71. authInfo, ok := rpc.GetAuthInfo(ctx)
  72. if !ok {
  73. return nil, rpc.Failed(ecode.Unauthorized, "unauthorized")
  74. }
  75. pubShards, err := svc.pubShards.GetOrLoad(msg.PubShardsID, msg.Password)
  76. if err != nil {
  77. return nil, rpc.Failed(ecode.OperationFailed, "load pub shards store: %v", err)
  78. }
  79. stats := pubShards.GetUserStats(authInfo.UserID)
  80. return &hubrpc.PubShardsStatsResp{
  81. Stats: stats,
  82. }, nil
  83. }

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