Spaces:
Paused
Paused
Upload 2 files
Browse files- src/main.rs +1 -81
src/main.rs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
routing::{get, post},
|
| 3 |
http::StatusCode,
|
| 4 |
http::{HeaderMap, Method, header::{RANGE, CONTENT_RANGE, ACCEPT_RANGES, CONTENT_LENGTH, CONTENT_TYPE}},
|
|
@@ -27,34 +27,6 @@ use tokio::sync::{Mutex, RwLock};
|
|
| 27 |
|
| 28 |
type BoxErr = Box<dyn std::error::Error + Send + Sync + 'static>;
|
| 29 |
|
| 30 |
-
// #region debug-point A:debug-server
|
| 31 |
-
async fn debug_event(hypothesis_id: &str, location: &str, msg: &str, data: serde_json::Value) {
|
| 32 |
-
let payload = json!({
|
| 33 |
-
"sessionId": "login-gateway-output",
|
| 34 |
-
"runId": "pre-fix",
|
| 35 |
-
"hypothesisId": hypothesis_id,
|
| 36 |
-
"location": location,
|
| 37 |
-
"msg": msg,
|
| 38 |
-
"data": data,
|
| 39 |
-
"ts": SystemTime::now()
|
| 40 |
-
.duration_since(UNIX_EPOCH)
|
| 41 |
-
.map(|d| d.as_millis())
|
| 42 |
-
.unwrap_or(0),
|
| 43 |
-
});
|
| 44 |
-
if let Ok(c) = reqwest::Client::builder()
|
| 45 |
-
.no_proxy()
|
| 46 |
-
.timeout(std::time::Duration::from_secs(2))
|
| 47 |
-
.build()
|
| 48 |
-
{
|
| 49 |
-
let _ = c
|
| 50 |
-
.post("http://192.168.8.103:7777/event")
|
| 51 |
-
.json(&payload)
|
| 52 |
-
.send()
|
| 53 |
-
.await;
|
| 54 |
-
}
|
| 55 |
-
}
|
| 56 |
-
// #endregion
|
| 57 |
-
|
| 58 |
mod api;
|
| 59 |
use api::{APIClient, APIError, Format};
|
| 60 |
|
|
@@ -1053,18 +1025,6 @@ async fn web_login(email: &str, password_md5: &str) -> Result<String, String> {
|
|
| 1053 |
let url_deezer = "https://www.deezer.com".parse::<Url>().map_err(|_| "web:url".to_string())?;
|
| 1054 |
jar.add_cookie_str("comeback=1; Domain=.deezer.com; Path=/", &url_deezer);
|
| 1055 |
|
| 1056 |
-
// #region debug-point B:web-login-entry
|
| 1057 |
-
debug_event(
|
| 1058 |
-
"B",
|
| 1059 |
-
"src/main.rs:web_login:entry",
|
| 1060 |
-
"[DEBUG] web_login entry",
|
| 1061 |
-
json!({
|
| 1062 |
-
"email_len": email.len(),
|
| 1063 |
-
"password_md5_len": password_md5.len(),
|
| 1064 |
-
}),
|
| 1065 |
-
).await;
|
| 1066 |
-
// #endregion
|
| 1067 |
-
|
| 1068 |
let client = reqwest::Client::builder()
|
| 1069 |
.no_proxy()
|
| 1070 |
.cookie_provider(jar.clone())
|
|
@@ -1100,17 +1060,6 @@ async fn web_login(email: &str, password_md5: &str) -> Result<String, String> {
|
|
| 1100 |
return Err("web:no_checkForm".to_string());
|
| 1101 |
}
|
| 1102 |
|
| 1103 |
-
// #region debug-point C:web-login-checkform
|
| 1104 |
-
debug_event(
|
| 1105 |
-
"C",
|
| 1106 |
-
"src/main.rs:web_login:checkform",
|
| 1107 |
-
"[DEBUG] web_login checkForm received",
|
| 1108 |
-
json!({
|
| 1109 |
-
"check_form_len": check_form.len(),
|
| 1110 |
-
}),
|
| 1111 |
-
).await;
|
| 1112 |
-
// #endregion
|
| 1113 |
-
|
| 1114 |
let _ = gw_light_call_custom(
|
| 1115 |
&client,
|
| 1116 |
"user.checkCredentials",
|
|
@@ -1373,23 +1322,6 @@ async fn gw_light_call_custom(
|
|
| 1373 |
qp.push(("gateway_input", gi));
|
| 1374 |
}
|
| 1375 |
|
| 1376 |
-
// #region debug-point D:gw-light-query
|
| 1377 |
-
debug_event(
|
| 1378 |
-
"D",
|
| 1379 |
-
"src/main.rs:gw_light_call_custom:request",
|
| 1380 |
-
"[DEBUG] gw_light_call_custom request",
|
| 1381 |
-
json!({
|
| 1382 |
-
"method": method,
|
| 1383 |
-
"use_get": use_get || method == "user.getArl",
|
| 1384 |
-
"api_token_is_null": api_token == "null",
|
| 1385 |
-
"gateway_input": gateway_input.unwrap_or(""),
|
| 1386 |
-
"has_output_3": qp.iter().any(|(k, v)| *k == "output" && *v == "3"),
|
| 1387 |
-
"qp": qp.iter().map(|(k, v)| format!("{k}={v}")).collect::<Vec<_>>(),
|
| 1388 |
-
"param_keys": params.as_object().map(|m| m.keys().cloned().collect::<Vec<_>>()).unwrap_or_default(),
|
| 1389 |
-
}),
|
| 1390 |
-
).await;
|
| 1391 |
-
// #endregion
|
| 1392 |
-
|
| 1393 |
let r = req
|
| 1394 |
.query(&qp)
|
| 1395 |
.header(ACCEPT, "*/*")
|
|
@@ -1413,18 +1345,6 @@ async fn gw_light_call_custom(
|
|
| 1413 |
|
| 1414 |
let status = r.status();
|
| 1415 |
let text = r.text().await.map_err(|_| "read".to_string())?;
|
| 1416 |
-
// #region debug-point E:gw-light-response
|
| 1417 |
-
debug_event(
|
| 1418 |
-
"E",
|
| 1419 |
-
"src/main.rs:gw_light_call_custom:response",
|
| 1420 |
-
"[DEBUG] gw_light_call_custom response",
|
| 1421 |
-
json!({
|
| 1422 |
-
"method": method,
|
| 1423 |
-
"status": status.as_u16(),
|
| 1424 |
-
"body_prefix": text.chars().take(220).collect::<String>(),
|
| 1425 |
-
}),
|
| 1426 |
-
).await;
|
| 1427 |
-
// #endregion
|
| 1428 |
if status.as_u16() == 403 && text.to_ascii_lowercase().contains("access denied") {
|
| 1429 |
return Err("blocked:403".to_string());
|
| 1430 |
}
|
|
|
|
| 1 |
+
use axum::{
|
| 2 |
routing::{get, post},
|
| 3 |
http::StatusCode,
|
| 4 |
http::{HeaderMap, Method, header::{RANGE, CONTENT_RANGE, ACCEPT_RANGES, CONTENT_LENGTH, CONTENT_TYPE}},
|
|
|
|
| 27 |
|
| 28 |
type BoxErr = Box<dyn std::error::Error + Send + Sync + 'static>;
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
mod api;
|
| 31 |
use api::{APIClient, APIError, Format};
|
| 32 |
|
|
|
|
| 1025 |
let url_deezer = "https://www.deezer.com".parse::<Url>().map_err(|_| "web:url".to_string())?;
|
| 1026 |
jar.add_cookie_str("comeback=1; Domain=.deezer.com; Path=/", &url_deezer);
|
| 1027 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1028 |
let client = reqwest::Client::builder()
|
| 1029 |
.no_proxy()
|
| 1030 |
.cookie_provider(jar.clone())
|
|
|
|
| 1060 |
return Err("web:no_checkForm".to_string());
|
| 1061 |
}
|
| 1062 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1063 |
let _ = gw_light_call_custom(
|
| 1064 |
&client,
|
| 1065 |
"user.checkCredentials",
|
|
|
|
| 1322 |
qp.push(("gateway_input", gi));
|
| 1323 |
}
|
| 1324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1325 |
let r = req
|
| 1326 |
.query(&qp)
|
| 1327 |
.header(ACCEPT, "*/*")
|
|
|
|
| 1345 |
|
| 1346 |
let status = r.status();
|
| 1347 |
let text = r.text().await.map_err(|_| "read".to_string())?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1348 |
if status.as_u16() == 403 && text.to_ascii_lowercase().contains("access denied") {
|
| 1349 |
return Err("blocked:403".to_string());
|
| 1350 |
}
|