Skip to content

Commit 44b39bd

Browse files
committed
feat(vercel): add artist api routes handlers
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
1 parent a8be8cc commit 44b39bd

File tree

5 files changed

+180
-1
lines changed

5 files changed

+180
-1
lines changed

Cargo.toml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ tracing-subscriber = "0.3.17"
2424
url = "2.4.1"
2525
vercel_runtime = "1.0.2"
2626

27-
27+
# home
2828
[[bin]]
2929
name = "home"
3030
path = "api/home.rs"
3131

32+
# modules
3233
[[bin]]
3334
name = "modules"
3435
path = "api/modules.rs"
3536

37+
# song
3638
[[bin]]
3739
name = "song_details"
3840
path = "api/song/details.rs"
@@ -41,6 +43,7 @@ path = "api/song/details.rs"
4143
name = "song_reco"
4244
path = "api/song/recommend.rs"
4345

46+
# album
4447
[[bin]]
4548
name = "album_details"
4649
path = "api/album/details.rs"
@@ -53,10 +56,24 @@ path = "api/album/recommend.rs"
5356
name = "album_same_year"
5457
path = "api/album/same_year.rs"
5558

59+
# playlist
5660
[[bin]]
5761
name = "playlist_details"
5862
path = "api/playlist/details.rs"
5963

6064
[[bin]]
6165
name = "playlist_reco"
6266
path = "api/playlist/recommend.rs"
67+
68+
# artist
69+
[[bin]]
70+
name = "artist_details"
71+
path = "api/artist/details.rs"
72+
73+
[[bin]]
74+
name = "artist_reco"
75+
path = "api/artist/recommend.rs"
76+
77+
[[bin]]
78+
name = "artist_songs_albums"
79+
path = "api/artist/songs_albums.rs"

api/artist/details.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use axum::extract::Query;
2+
use jiosaavn::handlers::{artist_details_handler, ArtistParams};
3+
use serde_json::json;
4+
use std::collections::HashMap;
5+
use url::Url;
6+
use vercel_runtime::{run, Body, Error, Request, Response};
7+
8+
#[tokio::main]
9+
async fn main() -> Result<(), Error> {
10+
run(handler).await
11+
}
12+
13+
pub async fn handler(req: Request) -> Result<Response<Body>, Error> {
14+
let hash_query: HashMap<String, String> = Url::parse(&req.uri().to_string())
15+
.unwrap()
16+
.query_pairs()
17+
.into_owned()
18+
.collect();
19+
20+
let id = hash_query.get("id").cloned();
21+
let token = hash_query.get("token").cloned();
22+
let link = hash_query.get("link").cloned();
23+
let page = hash_query.get("page").cloned();
24+
let n_song = hash_query.get("n_song").cloned();
25+
let n_album = hash_query.get("n_album").cloned();
26+
27+
let raw = hash_query.get("raw").cloned();
28+
let camel = hash_query.get("camel").cloned();
29+
30+
let params = ArtistParams {
31+
id,
32+
link,
33+
token,
34+
song_id: None,
35+
artist_id: None,
36+
page,
37+
n_song,
38+
n_album,
39+
cat: None,
40+
sort: None,
41+
lang: None,
42+
raw,
43+
camel,
44+
};
45+
46+
let (status, payload) = artist_details_handler(Query(params)).await;
47+
48+
Ok(Response::builder()
49+
.status(status)
50+
.header("Content-Type", "application/json")
51+
.body(json!(payload.0).to_string().into())?)
52+
}

api/artist/recommend.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use axum::extract::Query;
2+
use jiosaavn::handlers::{recommend_artists_songs_handler, ArtistParams};
3+
use serde_json::json;
4+
use std::collections::HashMap;
5+
use url::Url;
6+
use vercel_runtime::{run, Body, Error, Request, Response};
7+
8+
#[tokio::main]
9+
async fn main() -> Result<(), Error> {
10+
run(handler).await
11+
}
12+
13+
pub async fn handler(req: Request) -> Result<Response<Body>, Error> {
14+
let hash_query: HashMap<String, String> = Url::parse(&req.uri().to_string())
15+
.unwrap()
16+
.query_pairs()
17+
.into_owned()
18+
.collect();
19+
20+
let artist_id = hash_query.get("artist_id").cloned();
21+
let song_id = hash_query.get("song_id").cloned();
22+
let lang = hash_query.get("lang").cloned();
23+
let page = hash_query.get("page").cloned();
24+
let cat = hash_query.get("cat").cloned();
25+
let sort = hash_query.get("sort").cloned();
26+
27+
let raw = hash_query.get("raw").cloned();
28+
let camel = hash_query.get("camel").cloned();
29+
30+
let params = ArtistParams {
31+
id: None,
32+
link: None,
33+
token: None,
34+
song_id,
35+
artist_id,
36+
page,
37+
n_song: None,
38+
n_album: None,
39+
cat,
40+
sort,
41+
lang,
42+
raw,
43+
camel,
44+
};
45+
let (status, payload) = recommend_artists_songs_handler(Query(params)).await;
46+
47+
Ok(Response::builder()
48+
.status(status)
49+
.header("Content-Type", "application/json")
50+
.body(json!(payload.0).to_string().into())?)
51+
}

api/artist/songs_albums.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use axum::extract::{Path, Query};
2+
use jiosaavn::handlers::{artist_songs_albums_handler, ArtistParams};
3+
use serde_json::json;
4+
use std::collections::HashMap;
5+
use url::Url;
6+
use vercel_runtime::{run, Body, Error, Request, Response};
7+
8+
#[tokio::main]
9+
async fn main() -> Result<(), Error> {
10+
run(handler).await
11+
}
12+
13+
pub async fn handler(req: Request) -> Result<Response<Body>, Error> {
14+
let parsed_url = Url::parse(&req.uri().to_string()).unwrap();
15+
16+
let path = parsed_url.path().split("/").last().unwrap().to_string();
17+
18+
let hash_query: HashMap<String, String> = parsed_url.query_pairs().into_owned().collect();
19+
20+
let id = hash_query.get("id").cloned();
21+
let page = hash_query.get("page").cloned();
22+
let cat = hash_query.get("cat").cloned();
23+
let sort = hash_query.get("sort").cloned();
24+
25+
let raw = hash_query.get("raw").cloned();
26+
let camel = hash_query.get("camel").cloned();
27+
28+
let params = ArtistParams {
29+
id,
30+
link: None,
31+
token: None,
32+
song_id: None,
33+
artist_id: None,
34+
page,
35+
n_song: None,
36+
n_album: None,
37+
cat,
38+
sort,
39+
lang: None,
40+
raw,
41+
camel,
42+
};
43+
44+
let (status, payload) = artist_songs_albums_handler(Query(params), Path(path)).await;
45+
46+
Ok(Response::builder()
47+
.status(status)
48+
.header("Content-Type", "application/json")
49+
.body(json!(payload.0).to_string().into())?)
50+
}

vercel.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
{
1414
"source": "/playlist/recommend",
1515
"destination": "/api/playlist/recommend.rs"
16+
},
17+
{ "source": "/artist", "destination": "/api/artist/details.rs" },
18+
{
19+
"source": "/artist/(recommend|top-songs)",
20+
"destination": "/api/artist/recommend.rs"
21+
},
22+
{
23+
"source": "/artist/(songs|albums)",
24+
"destination": "/api/artist/songs_albums.rs"
1625
}
1726
],
1827
"headers": [

0 commit comments

Comments
 (0)