diff options
Diffstat (limited to 'server/src/api/post.rs')
-rw-r--r-- | server/src/api/post.rs | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 84ef89f1..32eb5470 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -1,6 +1,6 @@ use super::*; -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct CreatePost { name: String, url: Option<String>, @@ -31,7 +31,7 @@ pub struct GetPostResponse { pub online: usize, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct GetPosts { type_: String, sort: String, @@ -41,9 +41,9 @@ pub struct GetPosts { auth: Option<String>, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct GetPostsResponse { - posts: Vec<PostView>, + pub posts: Vec<PostView>, } #[derive(Serialize, Deserialize)] @@ -112,7 +112,8 @@ impl Perform for Oper<CreatePost> { } // Check for a site ban - if UserView::read(&conn, user_id)?.banned { + let user = User_::read(&conn, user_id)?; + if user.banned { return Err(APIError::err("site_ban").into()); } @@ -136,6 +137,9 @@ impl Perform for Oper<CreatePost> { embed_description: iframely_description, embed_html: iframely_html, thumbnail_url: pictshare_thumbnail, + ap_id: "changeme".into(), + local: true, + published: None, }; let inserted_post = match Post::create(&conn, &post_form) { @@ -151,6 +155,13 @@ impl Perform for Oper<CreatePost> { } }; + let updated_post = match Post::update_ap_id(&conn, inserted_post.id) { + Ok(post) => post, + Err(_e) => return Err(APIError::err("couldnt_create_post").into()), + }; + + post_create(&updated_post, &user, &conn)?; + // They like their own post by default let like_form = PostLikeForm { post_id: inserted_post.id, @@ -446,7 +457,8 @@ impl Perform for Oper<EditPost> { } // Check for a site ban - if UserView::read(&conn, user_id)?.banned { + let user = User_::read(&conn, user_id)?; + if user.banned { return Err(APIError::err("site_ban").into()); } @@ -454,6 +466,8 @@ impl Perform for Oper<EditPost> { let (iframely_title, iframely_description, iframely_html, pictshare_thumbnail) = fetch_iframely_and_pictshare_data(data.url.to_owned()); + let read_post = Post::read(&conn, data.edit_id)?; + let post_form = PostForm { name: data.name.to_owned(), url: data.url.to_owned(), @@ -470,9 +484,12 @@ impl Perform for Oper<EditPost> { embed_description: iframely_description, embed_html: iframely_html, thumbnail_url: pictshare_thumbnail, + ap_id: read_post.ap_id, + local: read_post.local, + published: None, }; - let _updated_post = match Post::update(&conn, data.edit_id, &post_form) { + let updated_post = match Post::update(&conn, data.edit_id, &post_form) { Ok(post) => post, Err(e) => { let err_type = if e.to_string() == "value too long for type character varying(200)" { @@ -514,6 +531,8 @@ impl Perform for Oper<EditPost> { ModStickyPost::create(&conn, &form)?; } + post_update(&updated_post, &user, &conn)?; + let post_view = PostView::read(&conn, data.edit_id, Some(user_id))?; let res = PostResponse { post: post_view }; |