Return error if post is already saved to IPFS
This commit is contained in:
parent
d668ee78d6
commit
057cac1ac7
3 changed files with 22 additions and 3 deletions
|
@ -17,8 +17,14 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Status'
|
||||
403:
|
||||
description: Post does not belong to user or is not public
|
||||
404:
|
||||
description: Post not found
|
||||
418:
|
||||
description: IPFS integration is not enabled
|
||||
422:
|
||||
description: Post already saved to IPFS
|
||||
/api/v1/{status_id}/signature:
|
||||
get:
|
||||
summary: Sign post data with instance key
|
||||
|
@ -42,8 +48,14 @@ paths:
|
|||
s:
|
||||
type: string
|
||||
example: '6a5cb313907cd3...'
|
||||
403:
|
||||
description: Post does not belong to user or is not public
|
||||
404:
|
||||
description: Post not found
|
||||
418:
|
||||
description: Ethereum integration is not enabled
|
||||
422:
|
||||
description: Post is not saved to IPFS
|
||||
|
||||
components:
|
||||
parameters:
|
||||
|
|
|
@ -58,6 +58,9 @@ pub enum HttpError {
|
|||
#[error("operation not supported")]
|
||||
NotSupported,
|
||||
|
||||
#[error("{0}")]
|
||||
OperationError(&'static str),
|
||||
|
||||
#[error("internal error")]
|
||||
InternalError,
|
||||
}
|
||||
|
@ -94,6 +97,7 @@ impl ResponseError for HttpError {
|
|||
HttpError::PermissionError => StatusCode::FORBIDDEN,
|
||||
HttpError::NotFoundError(_) => StatusCode::NOT_FOUND,
|
||||
HttpError::NotSupported => StatusCode::IM_A_TEAPOT,
|
||||
HttpError::OperationError(_) => StatusCode::UNPROCESSABLE_ENTITY,
|
||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -319,9 +319,12 @@ async fn make_permanent(
|
|||
let db_client = &**get_database_client(&db_pool).await?;
|
||||
let current_user = get_current_user(db_client, auth.token()).await?;
|
||||
let mut post = get_post_by_id(db_client, &status_id).await?;
|
||||
if post.ipfs_cid.is_some() {
|
||||
return Err(HttpError::OperationError("post already saved to IPFS"));
|
||||
};
|
||||
if post.author.id != current_user.id || !post.is_public() {
|
||||
// Users can only archive their own public posts
|
||||
return Err(HttpError::NotFoundError("post"));
|
||||
return Err(HttpError::PermissionError);
|
||||
};
|
||||
let ipfs_api_url = config.ipfs_api_url.as_ref()
|
||||
.ok_or(HttpError::NotSupported)?;
|
||||
|
@ -378,11 +381,11 @@ async fn get_signature(
|
|||
let post = get_post_by_id(db_client, &status_id).await?;
|
||||
if post.author.id != current_user.id || !post.is_public() {
|
||||
// Users can only tokenize their own public posts
|
||||
return Err(HttpError::NotFoundError("post"));
|
||||
return Err(HttpError::PermissionError);
|
||||
};
|
||||
let ipfs_cid = post.ipfs_cid
|
||||
// Post metadata is not immutable
|
||||
.ok_or(HttpError::ValidationError("post is not immutable".into()))?;
|
||||
.ok_or(HttpError::OperationError("post is not immutable"))?;
|
||||
let token_uri = get_ipfs_url(&ipfs_cid);
|
||||
let signature = create_mint_signature(
|
||||
contract_config,
|
||||
|
|
Loading…
Reference in a new issue