use api v2 for add comment
This commit is contained in:
@@ -15,7 +15,6 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
#[derive(FromForm)]
|
#[derive(FromForm)]
|
||||||
pub struct CommentInput {
|
pub struct CommentInput {
|
||||||
pid: i32,
|
|
||||||
#[field(validate = len(1..12289))]
|
#[field(validate = len(1..12289))]
|
||||||
text: String,
|
text: String,
|
||||||
use_title: Option<i8>,
|
use_title: Option<i8>,
|
||||||
@@ -112,14 +111,20 @@ pub async fn get_comment(pid: i32, user: CurrentUser, db: Db, rconn: RdsConn) ->
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/docomment", data = "<ci>")]
|
#[post("/docomment")]
|
||||||
|
pub async fn old_add_comment() -> ApiError {
|
||||||
|
OldApi.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/post/<pid>/comment", data = "<ci>")]
|
||||||
pub async fn add_comment(
|
pub async fn add_comment(
|
||||||
|
pid: i32,
|
||||||
ci: Form<CommentInput>,
|
ci: Form<CommentInput>,
|
||||||
user: CurrentUser,
|
user: CurrentUser,
|
||||||
db: Db,
|
db: Db,
|
||||||
rconn: RdsConn,
|
rconn: RdsConn,
|
||||||
) -> JsonApi {
|
) -> JsonApi {
|
||||||
let mut p = Post::get(&db, &rconn, ci.pid).await?;
|
let mut p = Post::get(&db, &rconn, pid).await?;
|
||||||
let c = Comment::create(
|
let c = Comment::create(
|
||||||
&db,
|
&db,
|
||||||
NewComment {
|
NewComment {
|
||||||
@@ -132,7 +137,7 @@ pub async fn add_comment(
|
|||||||
})
|
})
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
is_tmp: user.id.is_none(),
|
is_tmp: user.id.is_none(),
|
||||||
post_id: ci.pid,
|
post_id: pid,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ pub enum PolicyError {
|
|||||||
TitleUsed,
|
TitleUsed,
|
||||||
YouAreTmp,
|
YouAreTmp,
|
||||||
NoReason,
|
NoReason,
|
||||||
|
OldApi,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -141,6 +142,7 @@ impl<'r> Responder<'r, 'static> for ApiError {
|
|||||||
PolicyError::TitleUsed => "头衔已被使用",
|
PolicyError::TitleUsed => "头衔已被使用",
|
||||||
PolicyError::YouAreTmp => "临时用户只可发布内容和进入单个洞",
|
PolicyError::YouAreTmp => "临时用户只可发布内容和进入单个洞",
|
||||||
PolicyError::NoReason => "未填写理由",
|
PolicyError::NoReason => "未填写理由",
|
||||||
|
PolicyError::OldApi => "请使用最新版前端地址并检查更新"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.respond_to(req),
|
.respond_to(req),
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ async fn main() -> Result<(), rocket::Error> {
|
|||||||
"/_api/v1",
|
"/_api/v1",
|
||||||
routes![
|
routes![
|
||||||
api::comment::get_comment,
|
api::comment::get_comment,
|
||||||
api::comment::add_comment,
|
api::comment::old_add_comment,
|
||||||
api::post::get_list,
|
api::post::get_list,
|
||||||
api::post::get_one,
|
api::post::get_one,
|
||||||
api::post::publish_post,
|
api::post::publish_post,
|
||||||
@@ -84,6 +84,7 @@ async fn main() -> Result<(), rocket::Error> {
|
|||||||
cors::options_handler,
|
cors::options_handler,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
.mount("/_api/v2", routes![api::comment::add_comment])
|
||||||
.mount(
|
.mount(
|
||||||
"/_login",
|
"/_login",
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user