recycleactor commited on
Commit
ce54b28
·
verified ·
1 Parent(s): d7e1569

Upload main.rs

Browse files
Files changed (1) hide show
  1. src/main.rs +35 -0
src/main.rs CHANGED
@@ -1744,6 +1744,40 @@ async fn oauth_arl(Json(req): Json<OauthArlReq>) -> impl IntoResponse {
1744
  (StatusCode::OK, Json(json!({ "arl": arl }))).into_response()
1745
  }
1746
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1747
  #[tokio::main]
1748
  async fn main() {
1749
  let bind_addr = std::env::var("BIND_ADDR").unwrap_or("[::]".to_string());
@@ -1782,6 +1816,7 @@ async fn main() {
1782
  .route("/oauth/playlists", post(oauth_playlists))
1783
  .route("/oauth/playlist_tracks", post(oauth_playlist_tracks))
1784
  .route("/oauth/arl", post(oauth_arl))
 
1785
  .with_state(state)
1786
  .layer(cors)
1787
  .layer(CompressionLayer::new())
 
1744
  (StatusCode::OK, Json(json!({ "arl": arl }))).into_response()
1745
  }
1746
 
1747
+ #[derive(Debug, Deserialize)]
1748
+ struct OauthFlowReq {
1749
+ access_token: String,
1750
+ limit: Option<u32>,
1751
+ }
1752
+
1753
+ async fn oauth_flow(Json(req): Json<OauthFlowReq>) -> impl IntoResponse {
1754
+ let token = req.access_token.trim().to_string();
1755
+ if token.is_empty() {
1756
+ return json_error(StatusCode::BAD_REQUEST, "access_token required");
1757
+ }
1758
+ let limit = req.limit.unwrap_or(40).clamp(1, 100).to_string();
1759
+ let client = reqwest::Client::builder()
1760
+ .timeout(std::time::Duration::from_secs(15))
1761
+ .build()
1762
+ .unwrap();
1763
+
1764
+ let me = match api_deezer_get(&client, "/user/me", &token, &[]).await {
1765
+ Ok(v) => v,
1766
+ Err(e) => return json_error(StatusCode::SERVICE_UNAVAILABLE, e),
1767
+ };
1768
+ let uid = me.get("id").and_then(|x| x.as_i64()).unwrap_or(0);
1769
+ if uid <= 0 {
1770
+ return json_error(StatusCode::SERVICE_UNAVAILABLE, "api:no_user_id");
1771
+ }
1772
+
1773
+ let path = format!("/user/{uid}/flow");
1774
+ let extra = [("limit", limit)];
1775
+ match api_deezer_get(&client, &path, &token, &extra).await {
1776
+ Ok(v) => (StatusCode::OK, Json(v)).into_response(),
1777
+ Err(e) => json_error(StatusCode::SERVICE_UNAVAILABLE, e),
1778
+ }
1779
+ }
1780
+
1781
  #[tokio::main]
1782
  async fn main() {
1783
  let bind_addr = std::env::var("BIND_ADDR").unwrap_or("[::]".to_string());
 
1816
  .route("/oauth/playlists", post(oauth_playlists))
1817
  .route("/oauth/playlist_tracks", post(oauth_playlist_tracks))
1818
  .route("/oauth/arl", post(oauth_arl))
1819
+ .route("/oauth/flow", post(oauth_flow))
1820
  .with_state(state)
1821
  .layer(cors)
1822
  .layer(CompressionLayer::new())