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.

storage.go 1.8 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package services
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "time"
  6. "github.com/jmoiron/sqlx"
  7. "gitlink.org.cn/cloudream/common/consts/errorcode"
  8. "gitlink.org.cn/cloudream/common/pkgs/logger"
  9. "gitlink.org.cn/cloudream/common/pkgs/mq"
  10. coormq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/coordinator"
  11. )
  12. func (svc *Service) GetStorageInfo(msg *coormq.GetStorageInfo) (*coormq.GetStorageInfoResp, *mq.CodeMessage) {
  13. stg, err := svc.db.Storage().GetUserStorage(svc.db.SQLCtx(), msg.UserID, msg.StorageID)
  14. if err != nil {
  15. logger.Warnf("getting user storage: %s", err.Error())
  16. return nil, mq.Failed(errorcode.OperationFailed, "get user storage failed")
  17. }
  18. return mq.ReplyOK(coormq.NewGetStorageInfoResp(stg.StorageID, stg.Name, stg.NodeID, stg.Directory, stg.State))
  19. }
  20. func (svc *Service) StoragePackageLoaded(msg *coormq.StoragePackageLoaded) (*coormq.StoragePackageLoadedResp, *mq.CodeMessage) {
  21. // TODO: 对于的storage中已经存在的文件,直接覆盖已有文件
  22. err := svc.db.DoTx(sql.LevelDefault, func(tx *sqlx.Tx) error {
  23. err := svc.db.StoragePackage().Create(tx, msg.StorageID, msg.PackageID, msg.UserID)
  24. if err != nil {
  25. return fmt.Errorf("creating storage package: %w", err)
  26. }
  27. err = svc.db.StoragePackageLog().Create(tx, msg.StorageID, msg.PackageID, msg.UserID, time.Now())
  28. if err != nil {
  29. return fmt.Errorf("creating storage package log: %w", err)
  30. }
  31. return nil
  32. })
  33. if err != nil {
  34. logger.WithField("UserID", msg.UserID).
  35. WithField("StorageID", msg.StorageID).
  36. WithField("PackageID", msg.PackageID).
  37. Warnf("user load package to storage failed, err: %s", err.Error())
  38. return nil, mq.Failed(errorcode.OperationFailed, "user load package to storage failed")
  39. }
  40. return mq.ReplyOK(coormq.NewStoragePackageLoadedResp())
  41. }

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