Avoid deconstruction when using path extractor

Preparing for migration to actix 4.
This commit is contained in:
silverpill 2022-04-09 17:04:43 +00:00
parent 5b96464761
commit ed68b728be
6 changed files with 43 additions and 38 deletions

View file

@ -77,7 +77,7 @@ async fn actor_view(
config: web::Data<Config>,
db_pool: web::Data<Pool>,
request: HttpRequest,
web::Path(username): web::Path<String>,
username: web::Path<String>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let user = get_user_by_name(db_client, &username).await?;
@ -130,7 +130,7 @@ struct CollectionQueryParams {
async fn outbox(
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(username): web::Path<String>,
username: web::Path<String>,
query_params: web::Query<CollectionQueryParams>,
) -> Result<HttpResponse, HttpError> {
let instance = config.instance();
@ -185,7 +185,7 @@ async fn outbox(
#[get("/followers")]
async fn followers_collection(
config: web::Data<Config>,
web::Path(username): web::Path<String>,
username: web::Path<String>,
query_params: web::Query<CollectionQueryParams>,
) -> Result<HttpResponse, HttpError> {
if query_params.page.is_some() {
@ -203,7 +203,7 @@ async fn followers_collection(
#[get("/following")]
async fn following_collection(
config: web::Data<Config>,
web::Path(username): web::Path<String>,
username: web::Path<String>,
query_params: web::Query<CollectionQueryParams>,
) -> Result<HttpResponse, HttpError> {
if query_params.page.is_some() {
@ -221,7 +221,7 @@ async fn following_collection(
#[get("/subscribers")]
async fn subscribers_collection(
config: web::Data<Config>,
web::Path(username): web::Path<String>,
username: web::Path<String>,
query_params: web::Query<CollectionQueryParams>,
) -> Result<HttpResponse, HttpError> {
if query_params.page.is_some() {
@ -280,10 +280,11 @@ pub async fn object_view(
config: web::Data<Config>,
db_pool: web::Data<Pool>,
request: HttpRequest,
web::Path(internal_object_id): web::Path<Uuid>,
internal_object_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
// Try to find local post by ID, return 404 if not found
let internal_object_id = internal_object_id.into_inner();
let thread = get_thread(db_client, &internal_object_id, None).await?;
let mut post = thread.iter()
.find(|post| post.id == internal_object_id && post.author.is_local())

View file

@ -142,7 +142,7 @@ pub async fn create_account(
async fn get_account(
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(account_id): web::Path<Uuid>,
account_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let profile = get_profile_by_id(db_client, &account_id).await?;
@ -169,11 +169,11 @@ async fn update_credentials(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
data: web::Json<AccountUpdateData>,
account_data: web::Json<AccountUpdateData>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let mut current_user = get_current_user(db_client, auth.token()).await?;
let mut profile_data = data.into_inner()
let mut profile_data = account_data.into_inner()
.into_profile_data(
&current_user.profile.avatar_file_name,
&current_user.profile.banner_file_name,
@ -253,8 +253,8 @@ async fn follow_account(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(account_id): web::Path<Uuid>,
data: web::Json<FollowData>,
account_id: web::Path<Uuid>,
follow_data: web::Json<FollowData>,
) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -281,12 +281,12 @@ async fn follow_account(
Err(other_error) => return Err(other_error.into()),
};
};
if data.reblogs {
if follow_data.reblogs {
show_reposts(db_client, &current_user.id, &target.id).await?;
} else {
hide_reposts(db_client, &current_user.id, &target.id).await?;
};
if data.replies {
if follow_data.replies {
show_replies(db_client, &current_user.id, &target.id).await?;
} else {
hide_replies(db_client, &current_user.id, &target.id).await?;
@ -304,7 +304,7 @@ async fn unfollow_account(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(account_id): web::Path<Uuid>,
account_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -354,7 +354,7 @@ async fn get_account_statuses(
auth: Option<BearerAuth>,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(account_id): web::Path<Uuid>,
account_id: web::Path<Uuid>,
query_params: web::Query<StatusListQueryParams>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
@ -395,7 +395,7 @@ async fn get_account_followers(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(account_id): web::Path<Uuid>,
account_id: web::Path<Uuid>,
query_params: web::Query<FollowListQueryParams>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
@ -423,7 +423,7 @@ async fn get_account_following(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(account_id): web::Path<Uuid>,
account_id: web::Path<Uuid>,
query_params: web::Query<FollowListQueryParams>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;

View file

@ -32,7 +32,7 @@ async fn get_marker_view(
async fn update_marker_view(
auth: BearerAuth,
db_pool: web::Data<Pool>,
data: web::Json<MarkerCreateData>,
marker_data: web::Json<MarkerCreateData>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -40,7 +40,7 @@ async fn update_marker_view(
db_client,
&current_user.id,
Timeline::Notifications,
data.into_inner().notifications,
marker_data.into_inner().notifications,
).await?;
let markers = Markers { notifications: Some(db_marker.into()) };
Ok(HttpResponse::Ok().json(markers))

View file

@ -14,12 +14,12 @@ async fn create_attachment_view(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
data: web::Json<AttachmentCreateData>,
attachment_data: web::Json<AttachmentCreateData>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
let (file_name, media_type) = save_b64_file(
&data.file,
&attachment_data.file,
&config.media_dir(),
).map_err(|err| match err {
FileError::Base64DecodingError(err) => HttpError::ValidationError(err.to_string()),

View file

@ -56,12 +56,12 @@ async fn create_status(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
data: web::Json<StatusData>,
status_data: web::Json<StatusData>,
) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
let instance = config.instance();
let mut post_data = PostCreateData::try_from(data.into_inner())?;
let mut post_data = PostCreateData::try_from(status_data.into_inner())?;
post_data.clean(config.post_character_limit)?;
// Mentions
let mention_map = find_mentioned_profiles(
@ -134,7 +134,7 @@ async fn get_status(
auth: Option<BearerAuth>,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let maybe_current_user = match auth {
@ -158,7 +158,7 @@ async fn delete_status(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -187,7 +187,7 @@ async fn get_context(
auth: Option<BearerAuth>,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let maybe_current_user = match auth {
@ -219,7 +219,7 @@ async fn favourite(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -264,7 +264,7 @@ async fn unfavourite(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -304,7 +304,7 @@ async fn reblog(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -313,7 +313,7 @@ async fn reblog(
return Err(HttpError::NotFoundError("post"));
};
let repost_data = PostCreateData {
repost_of_id: Some(status_id),
repost_of_id: Some(status_id.into_inner()),
..Default::default()
};
let mut repost = create_post(db_client, &current_user.id, repost_data).await?;
@ -342,11 +342,15 @@ async fn unreblog(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
let reposts = find_reposts_by_user(db_client, &current_user.id, &[status_id]).await?;
let reposts = find_reposts_by_user(
db_client,
&current_user.id,
&[*status_id],
).await?;
let repost_id = reposts.first().ok_or(HttpError::NotFoundError("post"))?;
// Ignore returned data because reposts don't have attached files
delete_post(db_client, repost_id).await?;
@ -374,7 +378,7 @@ async fn make_permanent(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -430,7 +434,7 @@ async fn get_signature(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -460,8 +464,8 @@ async fn token_minted(
auth: BearerAuth,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(status_id): web::Path<Uuid>,
data: web::Json<TransactionData>,
status_id: web::Path<Uuid>,
transaction_data: web::Json<TransactionData>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
@ -472,7 +476,7 @@ async fn token_minted(
if post.author.id != current_user.id || !post.is_public() {
return Err(HttpError::PermissionError);
};
post.token_tx_id = Some(data.into_inner().transaction_id);
post.token_tx_id = Some(transaction_data.into_inner().transaction_id);
update_post(db_client, &post).await?;
get_reposted_posts(db_client, vec![&mut post]).await?;
get_actions_for_posts(db_client, &current_user.id, vec![&mut post]).await?;

View file

@ -47,7 +47,7 @@ async fn hashtag_timeline(
auth: Option<BearerAuth>,
config: web::Data<Config>,
db_pool: web::Data<Pool>,
web::Path(hashtag): web::Path<String>,
hashtag: web::Path<String>,
query_params: web::Query<TimelineQueryParams>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;