|
- package user_migration
-
- import (
- "github.com/QuantumNous/new-api/common"
- "github.com/QuantumNous/new-api/model"
- )
-
- type VerifyResult struct {
- TargetUserExists bool `json:"target_user_exists"`
- RemoteConverted bool `json:"remote_converted"`
- QuotaMatched bool `json:"quota_matched"`
- }
-
- func (s *Service) VerifyItem(item *model.UserMigrationItem) (*VerifyResult, error) {
- targetUser, err := model.GetUserById(item.TargetUserId, true)
- if err != nil {
- return nil, err
- }
-
- remoteUser, err := s.client.GetUser(item.SourceUserId)
- if err != nil {
- return nil, err
- }
-
- remoteConverted := remoteUser.Source == common.UserSourceSynced &&
- remoteUser.RemoteUserId == item.TargetUserId
-
- return &VerifyResult{
- TargetUserExists: targetUser != nil,
- RemoteConverted: remoteConverted,
- QuotaMatched: targetUser != nil && remoteConverted && remoteUser.SyncedQuota >= item.SourceQuota,
- }, nil
- }
|