From 999ca30448a6667b8857bbc9b554349a7a81a933 Mon Sep 17 00:00:00 2001 From: hole-thu Date: Sun, 31 Jul 2022 14:53:26 +0800 Subject: [PATCH] use api v2 for add comment --- src/api/comment.rs | 13 +++++++++---- src/api/mod.rs | 2 ++ src/main.rs | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/api/comment.rs b/src/api/comment.rs index 8cf72c4..321886b 100644 --- a/src/api/comment.rs +++ b/src/api/comment.rs @@ -15,7 +15,6 @@ use std::collections::HashMap; #[derive(FromForm)] pub struct CommentInput { - pid: i32, #[field(validate = len(1..12289))] text: String, use_title: Option, @@ -112,14 +111,20 @@ pub async fn get_comment(pid: i32, user: CurrentUser, db: Db, rconn: RdsConn) -> })) } -#[post("/docomment", data = "")] +#[post("/docomment")] +pub async fn old_add_comment() -> ApiError { + OldApi.into() +} + +#[post("/post//comment", data = "")] pub async fn add_comment( + pid: i32, ci: Form, user: CurrentUser, db: Db, rconn: RdsConn, ) -> JsonApi { - let mut p = Post::get(&db, &rconn, ci.pid).await?; + let mut p = Post::get(&db, &rconn, pid).await?; let c = Comment::create( &db, NewComment { @@ -132,7 +137,7 @@ pub async fn add_comment( }) .unwrap_or_default(), is_tmp: user.id.is_none(), - post_id: ci.pid, + post_id: pid, }, ) .await?; diff --git a/src/api/mod.rs b/src/api/mod.rs index 82fc249..20c3d48 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -116,6 +116,7 @@ pub enum PolicyError { TitleUsed, YouAreTmp, NoReason, + OldApi, } #[derive(Debug)] @@ -141,6 +142,7 @@ impl<'r> Responder<'r, 'static> for ApiError { PolicyError::TitleUsed => "头衔已被使用", PolicyError::YouAreTmp => "临时用户只可发布内容和进入单个洞", PolicyError::NoReason => "未填写理由", + PolicyError::OldApi => "请使用最新版前端地址并检查更新" } }) .respond_to(req), diff --git a/src/main.rs b/src/main.rs index 3797081..517dc21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,7 +64,7 @@ async fn main() -> Result<(), rocket::Error> { "/_api/v1", routes![ api::comment::get_comment, - api::comment::add_comment, + api::comment::old_add_comment, api::post::get_list, api::post::get_one, api::post::publish_post, @@ -84,6 +84,7 @@ async fn main() -> Result<(), rocket::Error> { cors::options_handler, ], ) + .mount("/_api/v2", routes![api::comment::add_comment]) .mount( "/_login", [