Spaces:
Running
Running
Upload 2 files
Browse files- src/api.rs +1 -0
- src/main.rs +9 -69
src/api.rs
CHANGED
|
@@ -123,6 +123,7 @@ impl APIClient {
|
|
| 123 |
.query(&[
|
| 124 |
("method", method),
|
| 125 |
("input", "3"),
|
|
|
|
| 126 |
("api_version", "1.0"),
|
| 127 |
("api_token", check_form),
|
| 128 |
("cid", cid.as_str()),
|
|
|
|
| 123 |
.query(&[
|
| 124 |
("method", method),
|
| 125 |
("input", "3"),
|
| 126 |
+
("output", "3"),
|
| 127 |
("api_version", "1.0"),
|
| 128 |
("api_token", check_form),
|
| 129 |
("cid", cid.as_str()),
|
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}},
|
|
@@ -1217,6 +1217,7 @@ async fn gw_light_call(
|
|
| 1217 |
.query(&[
|
| 1218 |
("method", method),
|
| 1219 |
("input", "3"),
|
|
|
|
| 1220 |
("api_version", "1.0"),
|
| 1221 |
("api_token", api_token),
|
| 1222 |
("cid", cid.as_str()),
|
|
@@ -1313,6 +1314,7 @@ async fn gw_light_call_custom(
|
|
| 1313 |
let mut qp: Vec<(&str, &str)> = vec![
|
| 1314 |
("method", method),
|
| 1315 |
("input", "3"),
|
|
|
|
| 1316 |
("api_version", "1.0"),
|
| 1317 |
("api_token", api_token),
|
| 1318 |
("cid", cid.as_str()),
|
|
@@ -1376,49 +1378,17 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
|
|
| 1376 |
return json_error(StatusCode::BAD_REQUEST, "Email and password_md5 required");
|
| 1377 |
}
|
| 1378 |
|
| 1379 |
-
|
| 1380 |
-
if worker_base().is_some() {
|
| 1381 |
-
match worker_login(&email, &pass).await {
|
| 1382 |
-
Ok(arl) => {
|
| 1383 |
-
return (StatusCode::OK, Json(json!({
|
| 1384 |
-
"arl": arl,
|
| 1385 |
-
"token": null,
|
| 1386 |
-
"uid": "",
|
| 1387 |
-
"access_token": null
|
| 1388 |
-
}))).into_response();
|
| 1389 |
-
}
|
| 1390 |
-
Err(e) => worker_err = Some(e),
|
| 1391 |
-
}
|
| 1392 |
-
}
|
| 1393 |
-
|
| 1394 |
-
match mobile_login(&email, &pass).await {
|
| 1395 |
Ok(arl) => (StatusCode::OK, Json(json!({
|
| 1396 |
"arl": arl,
|
| 1397 |
"token": null,
|
| 1398 |
"uid": "",
|
| 1399 |
"access_token": null
|
| 1400 |
}))).into_response(),
|
| 1401 |
-
Err(
|
| 1402 |
-
|
| 1403 |
-
|
| 1404 |
-
|
| 1405 |
-
"uid": "",
|
| 1406 |
-
"access_token": null
|
| 1407 |
-
}))).into_response(),
|
| 1408 |
-
Err(e2) => {
|
| 1409 |
-
if let Some(e0) = worker_err {
|
| 1410 |
-
json_error(
|
| 1411 |
-
StatusCode::UNAUTHORIZED,
|
| 1412 |
-
format!("login_failed; worker:{e0}; mobile:{e1}; web:{e2}"),
|
| 1413 |
-
)
|
| 1414 |
-
} else {
|
| 1415 |
-
json_error(
|
| 1416 |
-
StatusCode::UNAUTHORIZED,
|
| 1417 |
-
format!("login_failed; mobile:{e1}; web:{e2}; worker:worker:disabled"),
|
| 1418 |
-
)
|
| 1419 |
-
}
|
| 1420 |
-
}
|
| 1421 |
-
}
|
| 1422 |
}
|
| 1423 |
}
|
| 1424 |
|
|
@@ -1782,37 +1752,7 @@ async fn pair_complete(State(state): State<AppState>, Form(f): Form<PairComplete
|
|
| 1782 |
|
| 1783 |
let pass_md5 = format!("{:x}", md5::compute(password.as_bytes()));
|
| 1784 |
|
| 1785 |
-
let
|
| 1786 |
-
if worker_base().is_some() {
|
| 1787 |
-
match worker_login(&email, &pass_md5).await {
|
| 1788 |
-
Ok(arl) => {
|
| 1789 |
-
let mut map = state.pair.write().await;
|
| 1790 |
-
if let Some(s) = map.get_mut(&code) {
|
| 1791 |
-
s.arl = Some(arl);
|
| 1792 |
-
s.email = Some(email);
|
| 1793 |
-
s.error = None;
|
| 1794 |
-
}
|
| 1795 |
-
drop(map);
|
| 1796 |
-
pair_store_save(&state).await;
|
| 1797 |
-
return Html("<h3>Готово</h3><p>Вернись на ТВ — плагин подключится автоматически.</p>".to_string()).into_response();
|
| 1798 |
-
}
|
| 1799 |
-
Err(e) => worker_err = Some(e),
|
| 1800 |
-
}
|
| 1801 |
-
}
|
| 1802 |
-
|
| 1803 |
-
let res = match mobile_login(&email, &pass_md5).await {
|
| 1804 |
-
Ok(arl) => Ok(arl),
|
| 1805 |
-
Err(e1) => match web_login(&email, &pass_md5).await {
|
| 1806 |
-
Ok(arl) => Ok(arl),
|
| 1807 |
-
Err(e2) => {
|
| 1808 |
-
if let Some(e0) = worker_err {
|
| 1809 |
-
Err(format!("worker:{e0}; mobile:{e1}; web:{e2}"))
|
| 1810 |
-
} else {
|
| 1811 |
-
Err(format!("mobile:{e1}; web:{e2}; worker:worker:disabled"))
|
| 1812 |
-
}
|
| 1813 |
-
}
|
| 1814 |
-
},
|
| 1815 |
-
};
|
| 1816 |
|
| 1817 |
match res {
|
| 1818 |
Err(e) => {
|
|
|
|
| 1 |
+
use axum::{
|
| 2 |
routing::{get, post},
|
| 3 |
http::StatusCode,
|
| 4 |
http::{HeaderMap, Method, header::{RANGE, CONTENT_RANGE, ACCEPT_RANGES, CONTENT_LENGTH, CONTENT_TYPE}},
|
|
|
|
| 1217 |
.query(&[
|
| 1218 |
("method", method),
|
| 1219 |
("input", "3"),
|
| 1220 |
+
("output", "3"),
|
| 1221 |
("api_version", "1.0"),
|
| 1222 |
("api_token", api_token),
|
| 1223 |
("cid", cid.as_str()),
|
|
|
|
| 1314 |
let mut qp: Vec<(&str, &str)> = vec![
|
| 1315 |
("method", method),
|
| 1316 |
("input", "3"),
|
| 1317 |
+
("output", "3"),
|
| 1318 |
("api_version", "1.0"),
|
| 1319 |
("api_token", api_token),
|
| 1320 |
("cid", cid.as_str()),
|
|
|
|
| 1378 |
return json_error(StatusCode::BAD_REQUEST, "Email and password_md5 required");
|
| 1379 |
}
|
| 1380 |
|
| 1381 |
+
match web_login(&email, &pass).await {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1382 |
Ok(arl) => (StatusCode::OK, Json(json!({
|
| 1383 |
"arl": arl,
|
| 1384 |
"token": null,
|
| 1385 |
"uid": "",
|
| 1386 |
"access_token": null
|
| 1387 |
}))).into_response(),
|
| 1388 |
+
Err(e) => json_error(
|
| 1389 |
+
StatusCode::UNAUTHORIZED,
|
| 1390 |
+
format!("login_failed; web:{e}"),
|
| 1391 |
+
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1392 |
}
|
| 1393 |
}
|
| 1394 |
|
|
|
|
| 1752 |
|
| 1753 |
let pass_md5 = format!("{:x}", md5::compute(password.as_bytes()));
|
| 1754 |
|
| 1755 |
+
let res = web_login(&email, &pass_md5).await;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1756 |
|
| 1757 |
match res {
|
| 1758 |
Err(e) => {
|