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.7 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package mq
  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. err := svc.db.DoTx(sql.LevelSerializable, func(tx *sqlx.Tx) error {
  22. err := svc.db.StoragePackage().Create(tx, msg.StorageID, msg.PackageID, msg.UserID)
  23. if err != nil {
  24. return fmt.Errorf("creating storage package: %w", err)
  25. }
  26. err = svc.db.StoragePackageLog().Create(tx, msg.StorageID, msg.PackageID, msg.UserID, time.Now())
  27. if err != nil {
  28. return fmt.Errorf("creating storage package log: %w", err)
  29. }
  30. return nil
  31. })
  32. if err != nil {
  33. logger.WithField("UserID", msg.UserID).
  34. WithField("StorageID", msg.StorageID).
  35. WithField("PackageID", msg.PackageID).
  36. Warn(err.Error())
  37. return nil, mq.Failed(errorcode.OperationFailed, "user load package to storage failed")
  38. }
  39. return mq.ReplyOK(coormq.NewStoragePackageLoadedResp())
  40. }

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