Compare commits
8
Commits
main
...
919803a2cc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
919803a2cc
|
||
|
|
7478f353ce
|
||
|
|
6955c781c3
|
||
|
|
3cd5817a14
|
||
|
|
8e40744859
|
||
|
|
f235073641
|
||
|
|
5a4ba40064
|
||
|
|
0f1c3bb70f
|
Generated
+2
-2
@@ -1937,8 +1937,8 @@ checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "labyrinth"
|
name = "labyrinth"
|
||||||
version = "0.0.2"
|
version = "0.0.3"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/labyrinth.git?tag=v0.0.2-1-84f98521c8-928#84f98521c8c98693e422db48eb0aa7c124c2586b"
|
source = "git+ssh://git@git.kundeng.us/phoenix/labyrinth.git?tag=v0.0.3-3-f99a77ece0-928#f99a77ece0d066ee96867936eb280db367354e0a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-config",
|
"aws-config",
|
||||||
"aws-sdk-s3",
|
"aws-sdk-s3",
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
|||||||
simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.1-main-b690995806-680" }
|
simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.1-main-b690995806-680" }
|
||||||
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.3-main-fe9d101bd0-111" }
|
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.3-main-fe9d101bd0-111" }
|
||||||
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" }
|
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" }
|
||||||
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.2-1-84f98521c8-928" }
|
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.3-3-f99a77ece0-928" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
common-multipart-rfc7578 = { version = "0.7.0" }
|
common-multipart-rfc7578 = { version = "0.7.0" }
|
||||||
|
|||||||
@@ -212,6 +212,31 @@ pub mod endpoint {
|
|||||||
match lr.upload(&file_path, &data).await {
|
match lr.upload(&file_path, &data).await {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
println!("Result: {res:?}");
|
println!("Result: {res:?}");
|
||||||
|
|
||||||
|
println!("Downloading file");
|
||||||
|
match lr.download(&file_path).await {
|
||||||
|
Ok(res) => {
|
||||||
|
if res.is_empty() {
|
||||||
|
println!("This should not be empty");
|
||||||
|
} else {
|
||||||
|
println!("Size: {:?}", res.len());
|
||||||
|
println!("Going to delete file");
|
||||||
|
|
||||||
|
match lr.delete(&file_path).await {
|
||||||
|
Ok(res) => {
|
||||||
|
println!("Result: {res:?}");
|
||||||
|
println!("Deleted");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => match err {
|
Err(err) => match err {
|
||||||
labyrinth::Error::Info(err_str) => {
|
labyrinth::Error::Info(err_str) => {
|
||||||
|
|||||||
+272
-257
@@ -193,257 +193,270 @@ mod tests {
|
|||||||
|
|
||||||
pub async fn song_queue_req(
|
pub async fn song_queue_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
// Create multipart form
|
// Create multipart form
|
||||||
let mut form = MultipartForm::default();
|
match run_post(
|
||||||
let _ = form.add_file("flac", "tests/I/track01.flac");
|
Some(ReqBody::Multipart((
|
||||||
|
"flac".to_string(),
|
||||||
// Create request
|
"tests/I/track01.flac".to_string(),
|
||||||
let content_type = form.content_type();
|
))),
|
||||||
let body = MultipartBody::from(form);
|
crate::callers::queue::endpoints::QUEUESONG,
|
||||||
let req = axum::http::Request::builder()
|
axum::http::Method::POST,
|
||||||
.method(axum::http::Method::POST)
|
true,
|
||||||
.uri(crate::callers::queue::endpoints::QUEUESONG)
|
)
|
||||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
.await
|
||||||
.header(
|
{
|
||||||
axum::http::header::AUTHORIZATION,
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
super::bearer_auth().await,
|
Ok(response) => Ok(response),
|
||||||
)
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
.body(axum::body::Body::from_stream(body))
|
},
|
||||||
.unwrap();
|
Err(err) => Err(err),
|
||||||
app.clone().oneshot(req).await
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn song_queue_link_req(
|
pub async fn song_queue_link_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
user_id: &uuid::Uuid,
|
user_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload =
|
let payload =
|
||||||
super::payload_data::link_user_to_queued_song(song_queue_id, user_id).await;
|
super::payload_data::link_user_to_queued_song(song_queue_id, user_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::PATCH)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::queue::endpoints::QUEUESONGLINKUSERID)
|
crate::callers::queue::endpoints::QUEUESONGLINKUSERID,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::PATCH,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
app.clone().oneshot(req).await
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_queue_req(
|
pub async fn fetch_queue_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let fetch_req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::GET)
|
None,
|
||||||
.uri(crate::callers::queue::endpoints::NEXTQUEUESONG)
|
crate::callers::queue::endpoints::NEXTQUEUESONG,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::GET,
|
||||||
.header(
|
false,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::empty())
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
app.clone().oneshot(fetch_req).await
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_metadata_queue_req(
|
pub async fn fetch_metadata_queue_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let uri = format!(
|
let uri = format!(
|
||||||
"{}?id={}",
|
"{}?id={}",
|
||||||
crate::callers::queue::endpoints::QUEUEMETADATA,
|
crate::callers::queue::endpoints::QUEUEMETADATA,
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(None, &uri, axum::http::Method::GET, false).await {
|
||||||
.method(axum::http::Method::GET)
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.uri(uri)
|
Ok(response) => Ok(response),
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
.header(
|
},
|
||||||
axum::http::header::AUTHORIZATION,
|
Err(err) => Err(err),
|
||||||
super::bearer_auth().await,
|
}
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_queue_data_req(
|
pub async fn fetch_queue_data_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let raw_uri = String::from(crate::callers::queue::endpoints::QUEUESONGDATA);
|
let raw_uri = String::from(crate::callers::queue::endpoints::QUEUESONGDATA);
|
||||||
let end_index = raw_uri.len() - 4;
|
let end_index = raw_uri.len() - 4;
|
||||||
let mut uri: String = (&raw_uri[..end_index]).to_string();
|
let mut uri: String = (&raw_uri[..end_index]).to_string();
|
||||||
uri += &id.to_string();
|
uri += &id.to_string();
|
||||||
let req = axum::http::Request::builder()
|
|
||||||
.method(axum::http::Method::GET)
|
|
||||||
.uri(uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::CONTENT_TYPE,
|
|
||||||
simeta::detection::song::constants::mime::FLAC,
|
|
||||||
)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
match run_post(None, &uri, axum::http::Method::GET, false).await {
|
||||||
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn upload_coverart_queue_req(
|
pub async fn upload_coverart_queue_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let mut form = MultipartForm::default();
|
match run_post(
|
||||||
let _ = form.add_file(
|
Some(ReqBody::Multipart((
|
||||||
simeta::detection::coverart::constants::JPEG_TYPE,
|
simeta::detection::coverart::constants::JPEG_TYPE.to_string(),
|
||||||
"tests/I/Coverart-1.jpg",
|
"tests/I/Coverart-1.jpg".to_string(),
|
||||||
);
|
))),
|
||||||
|
crate::callers::queue::endpoints::QUEUECOVERART,
|
||||||
// Create request
|
axum::http::Method::POST,
|
||||||
let content_type = form.content_type();
|
true,
|
||||||
let body = MultipartBody::from(form);
|
)
|
||||||
|
.await
|
||||||
let req = axum::http::Request::builder()
|
{
|
||||||
.method(axum::http::Method::POST)
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.uri(crate::callers::queue::endpoints::QUEUECOVERART)
|
Ok(response) => Ok(response),
|
||||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
.header(
|
},
|
||||||
axum::http::header::AUTHORIZATION,
|
Err(err) => Err(err),
|
||||||
super::bearer_auth().await,
|
}
|
||||||
)
|
|
||||||
.body(axum::body::Body::from_stream(body))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn queue_metadata_req(
|
pub async fn queue_metadata_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = super::payload_data::queue_metadata(&song_queue_id).await;
|
let payload = super::payload_data::queue_metadata(&song_queue_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::POST)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::queue::endpoints::QUEUEMETADATA)
|
crate::callers::queue::endpoints::QUEUEMETADATA,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::POST,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
app.clone().oneshot(req).await
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn coverart_queue_song_queue_link_req(
|
pub async fn coverart_queue_song_queue_link_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
coverart_id: &uuid::Uuid,
|
coverart_id: &uuid::Uuid,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = super::payload_data::link_queued_coverart_to_queued_song(
|
let payload = super::payload_data::link_queued_coverart_to_queued_song(
|
||||||
song_queue_id,
|
song_queue_id,
|
||||||
coverart_id,
|
coverart_id,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
let req = axum::http::Request::builder()
|
|
||||||
.method(axum::http::Method::PATCH)
|
|
||||||
.uri(crate::callers::queue::endpoints::QUEUECOVERARTLINK)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
match run_post(
|
||||||
|
Some(ReqBody::Json(payload)),
|
||||||
|
crate::callers::queue::endpoints::QUEUECOVERARTLINK,
|
||||||
|
axum::http::Method::PATCH,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_coverart_req(
|
pub async fn create_coverart_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_id: &uuid::Uuid,
|
song_id: &uuid::Uuid,
|
||||||
coverart_id: &uuid::Uuid,
|
coverart_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = super::payload_data::create_coverart(song_id, coverart_id).await;
|
let payload = super::payload_data::create_coverart(song_id, coverart_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::POST)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::endpoints::CREATECOVERART)
|
crate::callers::endpoints::CREATECOVERART,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::POST,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
app.clone().oneshot(req).await
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_song_req(
|
pub async fn create_song_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
user_id: &uuid::Uuid,
|
user_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload = super::payload_data::create_song(song_queue_id, user_id).await;
|
let payload = super::payload_data::create_song(song_queue_id, user_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::POST)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::endpoints::CREATESONG)
|
crate::callers::endpoints::CREATESONG,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::POST,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
app.clone().oneshot(req).await
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_song_queue_status_req(
|
pub async fn update_song_queue_status_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let payload =
|
let payload =
|
||||||
super::payload_data::update_song_queue_status_to_ready(song_queue_id).await;
|
super::payload_data::update_song_queue_status_to_ready(song_queue_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
match run_post(
|
||||||
.method(axum::http::Method::PATCH)
|
Some(ReqBody::Json(payload)),
|
||||||
.uri(crate::callers::queue::endpoints::QUEUESONG)
|
crate::callers::queue::endpoints::QUEUESONG,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::PATCH,
|
||||||
.header(
|
true,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
{
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
.unwrap();
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
app.clone().oneshot(req).await
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_queued_coverart(
|
pub async fn get_queued_coverart(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
let uri = format!(
|
let uri = format!(
|
||||||
"{}?id={}",
|
"{}?id={}",
|
||||||
crate::callers::queue::endpoints::QUEUECOVERART,
|
crate::callers::queue::endpoints::QUEUECOVERART,
|
||||||
coverart_queue_id
|
coverart_queue_id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
match run_post(None, &uri, axum::http::Method::GET, false).await {
|
||||||
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
|
Ok(response) => Ok(response),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
Err(err)
|
||||||
|
// Err(std::convert::Infallible::from(err))
|
||||||
|
// Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
let req = axum::http::Request::builder()
|
let req = axum::http::Request::builder()
|
||||||
.method(axum::http::Method::GET)
|
.method(axum::http::Method::GET)
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
@@ -456,6 +469,70 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
app.clone().oneshot(req).await
|
app.clone().oneshot(req).await
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ReqBody {
|
||||||
|
Json(serde_json::Value),
|
||||||
|
Multipart((String, String)),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run_post(
|
||||||
|
// payload: Option<&serde_json::Value>,
|
||||||
|
payload: Option<ReqBody>,
|
||||||
|
uri: &str,
|
||||||
|
method: axum::http::Method,
|
||||||
|
has_body: bool,
|
||||||
|
) -> Result<axum::http::Request<axum::body::Body>, axum::http::Error> {
|
||||||
|
let mut content_type = "application/json; charset=utf-8".to_string();
|
||||||
|
let body = if has_body {
|
||||||
|
assert_eq!(
|
||||||
|
true,
|
||||||
|
payload.is_some(),
|
||||||
|
"Has request body and payload has data"
|
||||||
|
);
|
||||||
|
// axum::body::Body::from(payload.unwrap().to_string())
|
||||||
|
match payload {
|
||||||
|
Some(p) => match p {
|
||||||
|
ReqBody::Json(val) => axum::body::Body::from(val.to_string()),
|
||||||
|
ReqBody::Multipart((t, p)) => {
|
||||||
|
let mut form = MultipartForm::default();
|
||||||
|
let _ = form.add_file(t, p);
|
||||||
|
|
||||||
|
// Create request
|
||||||
|
// let content_type = form.content_type();
|
||||||
|
content_type = form.content_type();
|
||||||
|
println!("Content: {content_type:?}");
|
||||||
|
let body = MultipartBody::from(form);
|
||||||
|
println!("Streaming");
|
||||||
|
axum::body::Body::from_stream(body)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
eprintln!("This should not empty");
|
||||||
|
axum::body::Body::empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
axum::body::Body::empty()
|
||||||
|
};
|
||||||
|
match axum::http::Request::builder()
|
||||||
|
.method(method)
|
||||||
|
.uri(uri)
|
||||||
|
.header(
|
||||||
|
axum::http::header::CONTENT_TYPE,
|
||||||
|
content_type,
|
||||||
|
// "application/json; charset=utf-8",
|
||||||
|
)
|
||||||
|
.header(
|
||||||
|
axum::http::header::AUTHORIZATION,
|
||||||
|
super::bearer_auth().await,
|
||||||
|
)
|
||||||
|
.body(body)
|
||||||
|
{
|
||||||
|
Ok(t) => Ok(t),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,7 +540,7 @@ mod tests {
|
|||||||
// Flow for queueing song
|
// Flow for queueing song
|
||||||
pub async fn queue_song_flow(
|
pub async fn queue_song_flow(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<(axum::response::Response, uuid::Uuid), std::convert::Infallible> {
|
) -> Result<(axum::response::Response, uuid::Uuid), axum::http::Error> {
|
||||||
match super::request::song_queue_req(&app).await {
|
match super::request::song_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = super::util::get_resp_data::<
|
let resp = super::util::get_resp_data::<
|
||||||
@@ -506,6 +583,10 @@ mod tests {
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
@@ -519,7 +600,7 @@ mod tests {
|
|||||||
pub async fn queue_coverart_flow(
|
pub async fn queue_coverart_flow(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
match super::request::upload_coverart_queue_req(&app).await {
|
match super::request::upload_coverart_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = super::util::get_resp_data::<
|
let resp = super::util::get_resp_data::<
|
||||||
@@ -555,15 +636,23 @@ mod tests {
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns coverart response and song_queue_id
|
// Returns coverart response and song_queue_id
|
||||||
pub async fn queue_song_and_coverart_flow(
|
pub async fn queue_song_and_coverart_flow(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<(axum::response::Response, uuid::Uuid), std::convert::Infallible> {
|
) -> Result<(axum::response::Response, uuid::Uuid), axum::http::Error> {
|
||||||
match queue_song_flow(&app).await {
|
match queue_song_flow(&app).await {
|
||||||
Ok((song_response, user_id)) => {
|
Ok((song_response, user_id)) => {
|
||||||
let resp = super::util::get_resp_data::<
|
let resp = super::util::get_resp_data::<
|
||||||
@@ -719,8 +808,10 @@ mod tests {
|
|||||||
let app = init::app(pool).await;
|
let app = init::app(pool).await;
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
|
println!("Trying");
|
||||||
match request::song_queue_req(&app).await {
|
match request::song_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
|
println!("response: {response:?}");
|
||||||
let resp = util::get_resp_data::<
|
let resp = util::get_resp_data::<
|
||||||
crate::callers::queue::song::response::song_queue::Response,
|
crate::callers::queue::song::response::song_queue::Response,
|
||||||
>(response)
|
>(response)
|
||||||
@@ -729,6 +820,7 @@ mod tests {
|
|||||||
assert_eq!(false, resp.data[0].is_nil(), "Should not be empty");
|
assert_eq!(false, resp.data[0].is_nil(), "Should not be empty");
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
eprintln!("Failure!");
|
||||||
assert!(false, "Error: {:?}", err);
|
assert!(false, "Error: {:?}", err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -931,13 +1023,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
let songpath = song.song_path().unwrap();
|
let songpath = song.song_path().unwrap();
|
||||||
|
|
||||||
let mut form = MultipartForm::default();
|
|
||||||
let _ = form.add_file("flac", &songpath);
|
|
||||||
|
|
||||||
// Create request
|
|
||||||
let content_type = form.content_type();
|
|
||||||
let body = MultipartBody::from(form);
|
|
||||||
|
|
||||||
let raw_uri =
|
let raw_uri =
|
||||||
String::from(crate::callers::queue::endpoints::QUEUESONGUPDATE);
|
String::from(crate::callers::queue::endpoints::QUEUESONGUPDATE);
|
||||||
let end_index = raw_uri.len() - 5;
|
let end_index = raw_uri.len() - 5;
|
||||||
@@ -951,16 +1036,7 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
request::run_post(Some(request::ReqBody::Multipart(("flac".to_string(), songpath))), &uri, axum::http::Method::PATCH, true).await.unwrap()
|
||||||
.method(axum::http::Method::PATCH)
|
|
||||||
.uri(uri)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::from_stream(body))
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -1648,6 +1724,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -1833,19 +1912,7 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
request::run_post(Some(request::ReqBody::Json(payload)), crate::callers::queue::endpoints::QUEUECOVERARTDATAWIPE, axum::http::Method::PATCH, true).await.unwrap()
|
||||||
.method(axum::http::Method::PATCH)
|
|
||||||
.uri(crate::callers::queue::endpoints::QUEUECOVERARTDATAWIPE)
|
|
||||||
.header(
|
|
||||||
axum::http::header::CONTENT_TYPE,
|
|
||||||
"application/json",
|
|
||||||
)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::from(payload.to_string()))
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -1913,16 +1980,7 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false).await.unwrap()
|
||||||
.method(axum::http::Method::GET)
|
|
||||||
.uri(uri)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -1970,16 +2028,7 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false).await.unwrap()
|
||||||
.method(axum::http::Method::GET)
|
|
||||||
.uri(uri)
|
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -2059,15 +2108,7 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false).await.unwrap()
|
||||||
.method(axum::http::Method::GET)
|
|
||||||
.uri(&uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -2119,15 +2160,7 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false).await.unwrap()
|
||||||
.method(axum::http::Method::GET)
|
|
||||||
.uri(&uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -2181,15 +2214,7 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::GET, false).await.unwrap()
|
||||||
.method(axum::http::Method::GET)
|
|
||||||
.uri(&uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -2308,15 +2333,7 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(None, &uri, axum::http::Method::DELETE, false).await.unwrap()
|
||||||
.method(axum::http::Method::DELETE)
|
|
||||||
.uri(&uri)
|
|
||||||
.header(
|
|
||||||
axum::http::header::AUTHORIZATION,
|
|
||||||
super::bearer_auth().await,
|
|
||||||
)
|
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -2380,16 +2397,14 @@ mod tests {
|
|||||||
match app
|
match app
|
||||||
.clone()
|
.clone()
|
||||||
.oneshot(
|
.oneshot(
|
||||||
axum::http::Request::builder()
|
super::request::run_post(
|
||||||
.method(axum::http::Method::GET)
|
None,
|
||||||
.uri(crate::callers::endpoints::GETALLSONGS)
|
crate::callers::endpoints::GETALLSONGS,
|
||||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
axum::http::Method::GET,
|
||||||
.header(
|
false,
|
||||||
axum::http::header::AUTHORIZATION,
|
)
|
||||||
super::bearer_auth().await,
|
.await
|
||||||
)
|
.unwrap(),
|
||||||
.body(axum::body::Body::empty())
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user