recycleactor commited on
Commit
43fdbc3
·
verified ·
1 Parent(s): 46efca0

Upload main.rs

Browse files
Files changed (1) hide show
  1. src/main.rs +24 -12
src/main.rs CHANGED
@@ -1088,14 +1088,20 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
1088
 
1089
  let mut access_token_out: Option<String> = None;
1090
  let mut oauth_uid: Option<String> = None;
1091
- if let Ok(access_token) = oauth_access_token(&client, &email, &pass).await {
1092
- oauth_uid = api_deezer_get(&client, "/user/me", &access_token, &[])
1093
- .await
1094
- .ok()
1095
- .and_then(|v| v.get("id").and_then(|x| x.as_i64()))
1096
- .filter(|id| *id > 0)
1097
- .map(|id| id.to_string());
1098
- access_token_out = Some(access_token);
 
 
 
 
 
 
1099
  }
1100
 
1101
  let mut gw_token: Option<String> = None;
@@ -1152,9 +1158,11 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
1152
  let uid_out = gw_uid.or(oauth_uid).unwrap_or_default();
1153
 
1154
  if gw_token.is_none() && access_token_out.is_none() {
 
 
1155
  return json_error(
1156
  StatusCode::UNAUTHORIZED,
1157
- gw_err.unwrap_or_else(|| "login_failed".to_string()),
1158
  );
1159
  }
1160
 
@@ -1378,9 +1386,11 @@ async fn pair_complete(State(state): State<AppState>, Form(f): Form<PairComplete
1378
  let mut arl_out: Option<String> = None;
1379
  let mut access_token_out: Option<String> = None;
1380
  let mut gw_err: Option<String> = None;
 
1381
 
1382
- if let Ok(t) = oauth_access_token(&client, &email, &pass_md5).await {
1383
- access_token_out = Some(t);
 
1384
  }
1385
 
1386
  if let Ok(ud) = gw_light_call(&client, &jar, "deezer.getUserData", "null", json!({})).await {
@@ -1430,7 +1440,9 @@ async fn pair_complete(State(state): State<AppState>, Form(f): Form<PairComplete
1430
  }
1431
 
1432
  if gw_token.is_none() && access_token_out.is_none() {
1433
- let msg = gw_err.unwrap_or_else(|| "login_failed".to_string());
 
 
1434
  let mut map = state.pair.write().await;
1435
  if let Some(s) = map.get_mut(&code) {
1436
  s.error = Some(msg.clone());
 
1088
 
1089
  let mut access_token_out: Option<String> = None;
1090
  let mut oauth_uid: Option<String> = None;
1091
+ let mut oauth_err: Option<String> = None;
1092
+ match oauth_access_token(&client, &email, &pass).await {
1093
+ Ok(access_token) => {
1094
+ oauth_uid = api_deezer_get(&client, "/user/me", &access_token, &[])
1095
+ .await
1096
+ .ok()
1097
+ .and_then(|v| v.get("id").and_then(|x| x.as_i64()))
1098
+ .filter(|id| *id > 0)
1099
+ .map(|id| id.to_string());
1100
+ access_token_out = Some(access_token);
1101
+ }
1102
+ Err(e) => {
1103
+ oauth_err = Some(e);
1104
+ }
1105
  }
1106
 
1107
  let mut gw_token: Option<String> = None;
 
1158
  let uid_out = gw_uid.or(oauth_uid).unwrap_or_default();
1159
 
1160
  if gw_token.is_none() && access_token_out.is_none() {
1161
+ let gw_msg = gw_err.unwrap_or_else(|| "gw:none".to_string());
1162
+ let oauth_msg = oauth_err.unwrap_or_else(|| "oauth:none".to_string());
1163
  return json_error(
1164
  StatusCode::UNAUTHORIZED,
1165
+ format!("login_failed; {oauth_msg}; {gw_msg}"),
1166
  );
1167
  }
1168
 
 
1386
  let mut arl_out: Option<String> = None;
1387
  let mut access_token_out: Option<String> = None;
1388
  let mut gw_err: Option<String> = None;
1389
+ let mut oauth_err: Option<String> = None;
1390
 
1391
+ match oauth_access_token(&client, &email, &pass_md5).await {
1392
+ Ok(t) => access_token_out = Some(t),
1393
+ Err(e) => oauth_err = Some(e),
1394
  }
1395
 
1396
  if let Ok(ud) = gw_light_call(&client, &jar, "deezer.getUserData", "null", json!({})).await {
 
1440
  }
1441
 
1442
  if gw_token.is_none() && access_token_out.is_none() {
1443
+ let gw_msg = gw_err.unwrap_or_else(|| "gw:none".to_string());
1444
+ let oauth_msg = oauth_err.unwrap_or_else(|| "oauth:none".to_string());
1445
+ let msg = format!("login_failed; {oauth_msg}; {gw_msg}");
1446
  let mut map = state.pair.write().await;
1447
  if let Some(s) = map.get_mut(&code) {
1448
  s.error = Some(msg.clone());