Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

32 строки
838 B

  1. package user_migration
  2. import (
  3. "github.com/QuantumNous/new-api/common"
  4. "github.com/QuantumNous/new-api/model"
  5. )
  6. type VerifyResult struct {
  7. TargetUserExists bool `json:"target_user_exists"`
  8. RemoteConverted bool `json:"remote_converted"`
  9. QuotaMatched bool `json:"quota_matched"`
  10. }
  11. func (s *Service) VerifyItem(item *model.UserMigrationItem) (*VerifyResult, error) {
  12. targetUser, err := model.GetUserById(item.TargetUserId, true)
  13. if err != nil {
  14. return nil, err
  15. }
  16. remoteUser, err := s.client.GetUser(item.SourceUserId)
  17. if err != nil {
  18. return nil, err
  19. }
  20. return &VerifyResult{
  21. TargetUserExists: targetUser != nil,
  22. RemoteConverted: remoteUser.Source == common.UserSourceSynced &&
  23. remoteUser.RemoteUserId == item.TargetUserId,
  24. QuotaMatched: targetUser != nil && targetUser.Quota >= item.SourceQuota,
  25. }, nil
  26. }