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.

s2s.go 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package local
  2. import (
  3. "context"
  4. "io"
  5. "os"
  6. "path/filepath"
  7. stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types"
  8. jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
  9. )
  10. type S2STransfer struct {
  11. feat *jcstypes.S2STransferFeature
  12. detail *jcstypes.UserSpaceDetail
  13. localStg *jcstypes.LocalCred
  14. dstPath jcstypes.JPath
  15. }
  16. // 只有同一个机器的存储之间才可以进行数据直传
  17. func (*S2STransfer) CanTransfer(src, dst *jcstypes.UserSpaceDetail) bool {
  18. if stgtypes.FindFeature[*jcstypes.S2STransferFeature](dst) == nil {
  19. return false
  20. }
  21. _, ok := src.UserSpace.Storage.(*jcstypes.LocalType)
  22. if !ok {
  23. return false
  24. }
  25. if src.RecommendHub.HubID != dst.RecommendHub.HubID {
  26. return false
  27. }
  28. return true
  29. }
  30. // 执行数据直传
  31. func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetail, srcPath jcstypes.JPath, dstPath jcstypes.JPath) (stgtypes.FileInfo, error) {
  32. s.dstPath = dstPath
  33. copy, err := os.OpenFile(filepath.Join(s.localStg.RootDir, s.dstPath.JoinOSPath()), os.O_WRONLY|os.O_CREATE, 0644)
  34. if err != nil {
  35. return stgtypes.FileInfo{}, err
  36. }
  37. defer copy.Close()
  38. srcFile, err := os.Open(filepath.Join(s.localStg.RootDir, srcPath.JoinOSPath()))
  39. if err != nil {
  40. return stgtypes.FileInfo{}, err
  41. }
  42. defer srcFile.Close()
  43. n, err := io.Copy(copy, srcFile)
  44. if err != nil {
  45. return stgtypes.FileInfo{}, err
  46. }
  47. return stgtypes.FileInfo{
  48. Path: dstPath,
  49. Size: n,
  50. Hash: "",
  51. }, nil
  52. }
  53. func (s *S2STransfer) Close() {
  54. }

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