diff --git a/CHANGELOG.md b/CHANGELOG.md index e762ece..65e2565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,13 +12,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added OAuth authorization page. - Support `authorization_code` OAuth grant type. - Documented `http_cors_allowlist` configuration parameter. -- Added `/api/v1/{status_id}/thread` API endpoint (replaces `/api/v1/{status_id}/context`). +- Added `/api/v1/statuses/{status_id}/thread` API endpoint (replaces `/api/v1/statuses/{status_id}/context`). ### Changed - Allow `instance_uri` configuration value to contain URI scheme. - Changed `Content-Security-Policy` header value in nginx config examples. -- Changed `/api/v1/{status_id}/context` response format to match Mastodon API. +- Changed `/api/v1/statuses/{status_id}/context` response format to match Mastodon API. +- Changed status code of `/api/v1/statuses` response to 200 to match Mastodon API. ## [1.13.1] - 2023-02-09 diff --git a/docs/openapi.yaml b/docs/openapi.yaml index f97dfe7..c0e6187 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -886,7 +886,7 @@ paths: required: - status responses: - 201: + 200: description: Post created content: application/json: diff --git a/src/http.rs b/src/http.rs index c9ca660..68261a5 100644 --- a/src/http.rs +++ b/src/http.rs @@ -4,12 +4,16 @@ use actix_web::{ error::{Error, JsonPayloadError}, http::StatusCode, middleware::{ErrorHandlerResponse, ErrorHandlers}, + web::{Form, Json}, + Either, HttpRequest, }; use serde_json::json; use crate::errors::HttpError; +pub type FormOrJson = Either, Json>; + /// Error handler for 401 Unauthorized pub fn create_auth_error_handler() -> ErrorHandlers { // Creates and returns actix middleware @@ -30,6 +34,7 @@ pub fn create_auth_error_handler() -> ErrorHandlers }) } +/// Convert JSON payload deserialization errors into validation errors pub fn json_error_handler( error: JsonPayloadError, _: &HttpRequest, diff --git a/src/mastodon_api/oauth/views.rs b/src/mastodon_api/oauth/views.rs index 8d37d4d..0a0f760 100644 --- a/src/mastodon_api/oauth/views.rs +++ b/src/mastodon_api/oauth/views.rs @@ -3,7 +3,6 @@ use actix_web::{ http::header as http_header, post, web, - Either, HttpResponse, Scope as ActixScope, }; @@ -19,6 +18,7 @@ use crate::ethereum::{ eip4361::verify_eip4361_signature, utils::validate_ethereum_address, }; +use crate::http::FormOrJson; use crate::models::{ oauth::queries::{ create_oauth_authorization, @@ -115,15 +115,9 @@ const ACCESS_TOKEN_EXPIRES_IN: i64 = 86400 * 7; async fn token_view( config: web::Data, db_pool: web::Data, - request_data: Either< - web::Json, - web::Form, - >, + request_data: FormOrJson, ) -> Result { - let request_data = match request_data { - Either::Left(json) => json.into_inner(), - Either::Right(form) => form.into_inner(), - }; + let request_data = request_data.into_inner(); let db_client = &**get_database_client(&db_pool).await?; let user = match request_data.grant_type.as_str() { "authorization_code" => { diff --git a/src/mastodon_api/statuses/views.rs b/src/mastodon_api/statuses/views.rs index aa14b62..7446f8e 100644 --- a/src/mastodon_api/statuses/views.rs +++ b/src/mastodon_api/statuses/views.rs @@ -21,6 +21,7 @@ use crate::activitypub::builders::{ use crate::database::{get_database_client, DatabaseError, DbPool}; use crate::errors::{HttpError, ValidationError}; use crate::ethereum::nft::create_mint_signature; +use crate::http::FormOrJson; use crate::ipfs::{ store as ipfs_store, posts::PostMetadata, @@ -70,7 +71,7 @@ async fn create_status( auth: BearerAuth, config: web::Data, db_pool: web::Data, - status_data: web::Json, + status_data: FormOrJson, ) -> Result { let db_client = &mut **get_database_client(&db_pool).await?; let current_user = get_current_user(db_client, auth.token()).await?; @@ -190,7 +191,7 @@ async fn create_status( .await?.enqueue(db_client).await?; let status = Status::from_post(post, &instance.url()); - Ok(HttpResponse::Created().json(status)) + Ok(HttpResponse::Ok().json(status)) } #[post("/preview")]