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()
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UploadParams {
|
||||
session_id: String,
|
||||
file_id: String,
|
||||
token: String,
|
||||
}
|
||||
|
||||
pub async fn handle_receive_upload(
|
||||
Query(params): Query<UploadParams>,
|
||||
State(service): State<JocalService>,
|
||||
|
@ -316,13 +324,10 @@ pub async fn handle_receive_upload(
|
|||
StatusCode::OK.into_response()
|
||||
}
|
||||
|
||||
// Query parameters struct
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UploadParams {
|
||||
pub struct CancelParams {
|
||||
session_id: String,
|
||||
file_id: String,
|
||||
token: String,
|
||||
}
|
||||
|
||||
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()
|
||||
async fn do_send_bytes(
|
||||
sessions: Sessions,
|
||||
client: Client,
|
||||
session_id: &str,
|
||||
content_id: &str,
|
||||
token: &String,
|
||||
token: &str,
|
||||
body: Bytes,
|
||||
) -> Result<()> {
|
||||
let sessions = sessions.read().await;
|
||||
let session = sessions.get(session_id).unwrap();
|
||||
let session = sessions
|
||||
.read()
|
||||
.await
|
||||
.get(session_id)
|
||||
.cloned()
|
||||
.ok_or(LocalSendError::SessionNotFound)?;
|
||||
|
||||
if session.status != SessionStatus::Active {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -395,11 +397,11 @@ async fn do_send_bytes(
|
|||
let response = request.send().await?;
|
||||
|
||||
if response.status() != 200 {
|
||||
log::trace!("non-200 remote response: {response:?}");
|
||||
return Err(LocalSendError::UploadFailed);
|
||||
log::warn!("non-200 remote response: {response:?}");
|
||||
Err(LocalSendError::UploadFailed)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// free function that can be called inside a future in tokio::task::spawn()
|
||||
|
|
Loading…
Reference in a new issue