25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

34 satır
904 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. remoteConverted := remoteUser.Source == common.UserSourceSynced &&
  21. remoteUser.RemoteUserId == item.TargetUserId
  22. return &VerifyResult{
  23. TargetUserExists: targetUser != nil,
  24. RemoteConverted: remoteConverted,
  25. QuotaMatched: targetUser != nil && remoteConverted && remoteUser.SyncedQuota >= item.SourceQuota,
  26. }, nil
  27. }