forked from greatest-ape/aquatic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work on http_private, including parsing announce requests
- Loading branch information
1 parent
87223f7
commit dc94367
Showing
7 changed files
with
69 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
**/criterion/*/new | ||
|
||
.DS_Store | ||
.env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
use axum::{ | ||
extract::{Path, RawQuery}, | ||
extract::{ConnectInfo, Path, RawQuery}, | ||
headers::UserAgent, | ||
http::StatusCode, | ||
Extension, TypedHeader, | ||
}; | ||
use sqlx::mysql::MySqlPool; | ||
use std::net::SocketAddr; | ||
|
||
use aquatic_http_protocol::request::AnnounceRequest; | ||
|
||
use super::db; | ||
|
||
pub async fn announce( | ||
Extension(pool): Extension<MySqlPool>, | ||
ConnectInfo(peer_addr): ConnectInfo<SocketAddr>, | ||
opt_user_agent: Option<TypedHeader<UserAgent>>, | ||
Path(user_token): Path<String>, | ||
RawQuery(query): RawQuery, | ||
) -> Result<String, (StatusCode, String)> { | ||
match db::announce(&pool).await { | ||
Ok(r) => Ok(format!("{:?}", r)), | ||
Err(err) => Err((StatusCode::INTERNAL_SERVER_ERROR, err.to_string())), | ||
} | ||
let request = AnnounceRequest::from_query_string(&query.unwrap_or_else(|| "".into())) | ||
.map_err(anyhow_error)?; | ||
|
||
let opt_user_agent = opt_user_agent.map(|header| header.as_str().to_owned()); | ||
|
||
let db_announce_request = | ||
db::DbAnnounceRequest::new(peer_addr, opt_user_agent, user_token, request); | ||
|
||
let db_announce_result = db::get_announce_response(&pool, db_announce_request) | ||
.await | ||
.map_err(anyhow_error)?; | ||
|
||
Ok(format!("{:?}", db_announce_result)) | ||
} | ||
|
||
fn anyhow_error(err: anyhow::Error) -> (StatusCode, String) { | ||
(StatusCode::INTERNAL_SERVER_ERROR, err.to_string()) | ||
} |