mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-23 10:30:41 +00:00
Add ActivityPub endpoint for actors
This commit is contained in:
parent
9eb1b987b2
commit
7b3a884ec6
6 changed files with 29 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -473,6 +473,7 @@ dependencies = [
|
|||
"rocket 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rocket_codegen 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rocket_contrib 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -8,6 +8,7 @@ dotenv = "*"
|
|||
heck = "0.3.0"
|
||||
rocket = "*"
|
||||
rocket_codegen = "*"
|
||||
serde_json = "1.0"
|
||||
|
||||
[dependencies.diesel]
|
||||
features = ["postgres", "r2d2"]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use models::instance::Instance;
|
||||
use diesel::PgConnection;
|
||||
use serde_json::Value;
|
||||
|
||||
pub trait Actor {
|
||||
fn get_box_prefix() -> &'static str;
|
||||
|
@ -8,6 +9,10 @@ pub trait Actor {
|
|||
|
||||
fn get_instance(&self, conn: &PgConnection) -> Instance;
|
||||
|
||||
fn as_activity_pub (&self) -> Value {
|
||||
json!({})
|
||||
}
|
||||
|
||||
fn compute_outbox(&self, conn: &PgConnection) -> String {
|
||||
self.compute_box(conn, "outbox")
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ extern crate rocket;
|
|||
extern crate rocket_contrib;
|
||||
extern crate bcrypt;
|
||||
extern crate heck;
|
||||
#[macro_use]
|
||||
extern crate serde_json;
|
||||
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::r2d2::{ConnectionManager, Pool};
|
||||
|
@ -56,6 +58,7 @@ fn main() {
|
|||
|
||||
routes::user::me,
|
||||
routes::user::details,
|
||||
routes::user::activity,
|
||||
routes::user::new,
|
||||
routes::user::create,
|
||||
|
||||
|
@ -64,6 +67,7 @@ fn main() {
|
|||
routes::session::delete,
|
||||
|
||||
routes::blogs::details,
|
||||
routes::blogs::activity,
|
||||
routes::blogs::new,
|
||||
routes::blogs::create,
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rocket::request::Form;
|
||||
use rocket::response::Redirect;
|
||||
use rocket_contrib::Template;
|
||||
use rocket_contrib::{Json, Template};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use utils;
|
||||
|
@ -9,12 +9,19 @@ use models::blogs::*;
|
|||
use models::blog_authors::*;
|
||||
use models::instance::Instance;
|
||||
use models::user::User;
|
||||
use activity_pub::Actor;
|
||||
|
||||
#[get("/~/<name>")]
|
||||
#[get("/~/<name>", rank = 2)]
|
||||
fn details(name: String) -> String {
|
||||
format!("Welcome on ~{}", name)
|
||||
}
|
||||
|
||||
#[get("/~/<name>", format = "application/activity+json", rank = 1)]
|
||||
fn activity(name: String, conn: DbConn) -> Json {
|
||||
let blog = Blog::find_by_actor_id(&*conn, name).unwrap();
|
||||
Json(blog.as_activity_pub())
|
||||
}
|
||||
|
||||
#[get("/blogs/new")]
|
||||
fn new(_user: User) -> Template {
|
||||
Template::render("blogs/new", HashMap::<String, i32>::new())
|
||||
|
|
|
@ -1,22 +1,29 @@
|
|||
use rocket::request::Form;
|
||||
use rocket::response::Redirect;
|
||||
use rocket_contrib::Template;
|
||||
use rocket_contrib::{Json, Template};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use db_conn::DbConn;
|
||||
use models::user::*;
|
||||
use models::instance::Instance;
|
||||
use activity_pub::Actor;
|
||||
|
||||
#[get("/me")]
|
||||
fn me(user: User) -> String {
|
||||
format!("Logged in as {}", user.username.to_string())
|
||||
}
|
||||
|
||||
#[get("/@/<name>")]
|
||||
#[get("/@/<name>", rank = 2)]
|
||||
fn details(name: String) -> String {
|
||||
format!("Hello, @{}", name)
|
||||
}
|
||||
|
||||
#[get("/@/<name>", format = "application/activity+json", rank = 1)]
|
||||
fn activity(name: String, conn: DbConn) -> Json {
|
||||
let user = User::find_by_name(&*conn, name).unwrap();
|
||||
Json(user.as_activity_pub())
|
||||
}
|
||||
|
||||
#[get("/users/new")]
|
||||
fn new() -> Template {
|
||||
Template::render("users/new", HashMap::<String, i32>::new())
|
||||
|
|
Loading…
Reference in a new issue