more contention removal
This commit is contained in:
parent
16ef487581
commit
1aa3f7aec4
1 changed files with 21 additions and 19 deletions
|
@ -251,6 +251,14 @@ pub async fn handle_prepare_upload(
|
||||||
.into_response()
|
.into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct UploadParams {
|
||||||
|
session_id: String,
|
||||||
|
file_id: String,
|
||||||
|
token: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn handle_receive_upload(
|
pub async fn handle_receive_upload(
|
||||||
Query(params): Query<UploadParams>,
|
Query(params): Query<UploadParams>,
|
||||||
State(service): State<JocalService>,
|
State(service): State<JocalService>,
|
||||||
|
@ -316,13 +324,10 @@ pub async fn handle_receive_upload(
|
||||||
StatusCode::OK.into_response()
|
StatusCode::OK.into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query parameters struct
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct UploadParams {
|
pub struct CancelParams {
|
||||||
session_id: String,
|
session_id: String,
|
||||||
file_id: String,
|
|
||||||
token: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_cancel(
|
pub async fn handle_cancel(
|
||||||
|
@ -358,30 +363,27 @@ pub async fn handle_cancel(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel parameters struct
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CancelParams {
|
|
||||||
session_id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
// free function that can be called inside a future in tokio::task::spawn()
|
// free function that can be called inside a future in tokio::task::spawn()
|
||||||
async fn do_send_bytes(
|
async fn do_send_bytes(
|
||||||
sessions: Sessions,
|
sessions: Sessions,
|
||||||
client: Client,
|
client: Client,
|
||||||
session_id: &str,
|
session_id: &str,
|
||||||
content_id: &str,
|
content_id: &str,
|
||||||
token: &String,
|
token: &str,
|
||||||
body: Bytes,
|
body: Bytes,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let sessions = sessions.read().await;
|
let session = sessions
|
||||||
let session = sessions.get(session_id).unwrap();
|
.read()
|
||||||
|
.await
|
||||||
|
.get(session_id)
|
||||||
|
.cloned()
|
||||||
|
.ok_or(LocalSendError::SessionNotFound)?;
|
||||||
|
|
||||||
if session.status != SessionStatus::Active {
|
if session.status != SessionStatus::Active {
|
||||||
return Err(LocalSendError::SessionInactive);
|
return Err(LocalSendError::SessionInactive);
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.file_tokens.get(content_id) != Some(token) {
|
if session.file_tokens.get(content_id).map(|t| t.as_str()) != Some(token) {
|
||||||
return Err(LocalSendError::InvalidToken);
|
return Err(LocalSendError::InvalidToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,12 +397,12 @@ async fn do_send_bytes(
|
||||||
let response = request.send().await?;
|
let response = request.send().await?;
|
||||||
|
|
||||||
if response.status() != 200 {
|
if response.status() != 200 {
|
||||||
log::trace!("non-200 remote response: {response:?}");
|
log::warn!("non-200 remote response: {response:?}");
|
||||||
return Err(LocalSendError::UploadFailed);
|
Err(LocalSendError::UploadFailed)
|
||||||
}
|
} else {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// free function that can be called inside a future in tokio::task::spawn()
|
// free function that can be called inside a future in tokio::task::spawn()
|
||||||
async fn do_prepare_upload(
|
async fn do_prepare_upload(
|
||||||
|
|
Loading…
Reference in a new issue