From c282246bf2157e8c14df83c67d1b8aa4a0953096 Mon Sep 17 00:00:00 2001 From: Bat Date: Fri, 4 May 2018 12:09:08 +0100 Subject: [PATCH] Add an enpoint for viewing articles AP representation --- src/main.rs | 1 + src/routes/posts.rs | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 232eb499..c0217808 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,6 +83,7 @@ fn main() { routes::blogs::create, routes::posts::details, + routes::posts::activity_details, routes::posts::new, routes::posts::new_auth, routes::posts::create diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 5dcb8482..571f1b41 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -4,7 +4,9 @@ use rocket::response::Redirect; use rocket_contrib::Template; use std::collections::HashMap; +use activity_pub::{context, activity_pub, ActivityPub}; use activity_pub::activity::Create; +use activity_pub::object::Object; use activity_pub::outbox::broadcast; use db_conn::DbConn; use models::blogs::*; @@ -13,16 +15,21 @@ use models::posts::*; use models::users::User; use utils; -#[get("/~//", rank = 3)] +#[get("/~//", rank = 4)] fn details(blog: String, slug: String, conn: DbConn) -> String { let blog = Blog::find_by_actor_id(&*conn, blog).unwrap(); let post = Post::find_by_slug(&*conn, slug).unwrap(); format!("{} in {}", post.title, blog.title) } -#[get("/~/<_blog>/new", rank = 1)] -fn new(_blog: String, _user: User) -> Template { - Template::render("posts/new", HashMap::::new()) +#[get("/~/<_blog>/", rank = 3, format = "application/activity+json")] +fn activity_details(_blog: String, slug: String, conn: DbConn) -> ActivityPub { + // TODO: posts in different blogs may have the same slug + let post = Post::find_by_slug(&*conn, slug).unwrap(); + + let mut act = post.serialize(&*conn); + act["@context"] = context(); + activity_pub(act) } #[get("/~/<_blog>/new", rank = 2)] @@ -30,6 +37,11 @@ fn new_auth(_blog: String) -> Redirect { utils::requires_login() } +#[get("/~/<_blog>/new", rank = 1)] +fn new(_blog: String, _user: User) -> Template { + Template::render("posts/new", HashMap::::new()) +} + #[derive(FromForm)] struct NewPostForm { pub title: String,