fix: handle string ID in Todoist user info response
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 6s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 6s
This commit is contained in:
@@ -5888,21 +5888,34 @@ func getTodoistUserInfo(accessToken string) (struct {
|
|||||||
|
|
||||||
log.Printf("Todoist API: parsed response keys: %v", getMapKeys(result))
|
log.Printf("Todoist API: parsed response keys: %v", getMapKeys(result))
|
||||||
|
|
||||||
|
// Функция для извлечения ID из разных типов
|
||||||
|
extractID := func(idValue interface{}) int64 {
|
||||||
|
switch v := idValue.(type) {
|
||||||
|
case float64:
|
||||||
|
return int64(v)
|
||||||
|
case int64:
|
||||||
|
return v
|
||||||
|
case int:
|
||||||
|
return int64(v)
|
||||||
|
case string:
|
||||||
|
if id, err := strconv.ParseInt(v, 10, 64); err == nil {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// Проверяем разные варианты структуры ответа
|
// Проверяем разные варианты структуры ответа
|
||||||
if userObj, ok := result["user"].(map[string]interface{}); ok {
|
if userObj, ok := result["user"].(map[string]interface{}); ok {
|
||||||
// Один объект user
|
// Один объект user
|
||||||
if id, ok := userObj["id"].(float64); ok {
|
userInfo.ID = extractID(userObj["id"])
|
||||||
userInfo.ID = int64(id)
|
|
||||||
}
|
|
||||||
if email, ok := userObj["email"].(string); ok {
|
if email, ok := userObj["email"].(string); ok {
|
||||||
userInfo.Email = email
|
userInfo.Email = email
|
||||||
}
|
}
|
||||||
} else if usersArr, ok := result["user"].([]interface{}); ok && len(usersArr) > 0 {
|
} else if usersArr, ok := result["user"].([]interface{}); ok && len(usersArr) > 0 {
|
||||||
// Массив users, берем первый
|
// Массив users, берем первый
|
||||||
if userObj, ok := usersArr[0].(map[string]interface{}); ok {
|
if userObj, ok := usersArr[0].(map[string]interface{}); ok {
|
||||||
if id, ok := userObj["id"].(float64); ok {
|
userInfo.ID = extractID(userObj["id"])
|
||||||
userInfo.ID = int64(id)
|
|
||||||
}
|
|
||||||
if email, ok := userObj["email"].(string); ok {
|
if email, ok := userObj["email"].(string); ok {
|
||||||
userInfo.Email = email
|
userInfo.Email = email
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user