Reorganize uses
This commit is contained in:
parent
f0b08b2d6d
commit
0c9a1bfc3a
86
src/activity_pub/actor.rs
Normal file
86
src/activity_pub/actor.rs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
use diesel::PgConnection;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use models::instance::Instance;
|
||||||
|
|
||||||
|
pub enum ActorType {
|
||||||
|
Person,
|
||||||
|
Blog
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToString for ActorType {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
String::from(match self {
|
||||||
|
ActorType::Person => "Person",
|
||||||
|
ActorType::Blog => "Blog"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Actor {
|
||||||
|
fn get_box_prefix() -> &'static str;
|
||||||
|
|
||||||
|
fn get_actor_id(&self) -> String;
|
||||||
|
|
||||||
|
fn get_instance(&self, conn: &PgConnection) -> Instance;
|
||||||
|
|
||||||
|
fn get_actor_type() -> ActorType;
|
||||||
|
|
||||||
|
fn as_activity_pub (&self, conn: &PgConnection) -> Value {
|
||||||
|
json!({
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"movedTo": "as:movedTo",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"ostatus":"http://ostatus.org#",
|
||||||
|
"atomUri":"ostatus:atomUri",
|
||||||
|
"inReplyToAtomUri":"ostatus:inReplyToAtomUri",
|
||||||
|
"conversation":"ostatus:conversation",
|
||||||
|
"toot":"http://joinmastodon.org/ns#",
|
||||||
|
"Emoji":"toot:Emoji",
|
||||||
|
"focalPoint": {
|
||||||
|
"@container":"@list",
|
||||||
|
"@id":"toot:focalPoint"
|
||||||
|
},
|
||||||
|
"featured":"toot:featured"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": self.compute_id(conn),
|
||||||
|
"type": Self::get_actor_type().to_string(),
|
||||||
|
"inbox": self.compute_inbox(conn),
|
||||||
|
"outbox": self.compute_outbox(conn),
|
||||||
|
"preferredUsername": self.get_actor_id(),
|
||||||
|
"name": "",
|
||||||
|
"summary": "",
|
||||||
|
"url": self.compute_id(conn),
|
||||||
|
"endpoints": {
|
||||||
|
"sharedInbox": "https://plu.me/inbox"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compute_outbox(&self, conn: &PgConnection) -> String {
|
||||||
|
self.compute_box(conn, "outbox")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compute_inbox(&self, conn: &PgConnection) -> String {
|
||||||
|
self.compute_box(conn, "inbox")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compute_box(&self, conn: &PgConnection, box_name: &str) -> String {
|
||||||
|
format!("{id}/{name}", id = self.compute_id(conn), name = box_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compute_id(&self, conn: &PgConnection) -> String {
|
||||||
|
format!(
|
||||||
|
"https://{instance}/{prefix}/{user}",
|
||||||
|
instance = self.get_instance(conn).public_domain,
|
||||||
|
prefix = Self::get_box_prefix(),
|
||||||
|
user = self.get_actor_id()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -1,87 +1,2 @@
|
|||||||
use models::instance::Instance;
|
pub mod actor;
|
||||||
use diesel::PgConnection;
|
|
||||||
use serde_json::Value;
|
|
||||||
|
|
||||||
pub mod webfinger;
|
pub mod webfinger;
|
||||||
|
|
||||||
pub enum ActorType {
|
|
||||||
Person,
|
|
||||||
Blog
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToString for ActorType {
|
|
||||||
fn to_string(&self) -> String {
|
|
||||||
String::from(match self {
|
|
||||||
ActorType::Person => "Person",
|
|
||||||
ActorType::Blog => "Blog"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Actor {
|
|
||||||
fn get_box_prefix() -> &'static str;
|
|
||||||
|
|
||||||
fn get_actor_id(&self) -> String;
|
|
||||||
|
|
||||||
fn get_instance(&self, conn: &PgConnection) -> Instance;
|
|
||||||
|
|
||||||
fn get_actor_type() -> ActorType;
|
|
||||||
|
|
||||||
fn as_activity_pub (&self, conn: &PgConnection) -> Value {
|
|
||||||
json!({
|
|
||||||
"@context": [
|
|
||||||
"https://www.w3.org/ns/activitystreams",
|
|
||||||
"https://w3id.org/security/v1",
|
|
||||||
{
|
|
||||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
|
||||||
"sensitive": "as:sensitive",
|
|
||||||
"movedTo": "as:movedTo",
|
|
||||||
"Hashtag": "as:Hashtag",
|
|
||||||
"ostatus":"http://ostatus.org#",
|
|
||||||
"atomUri":"ostatus:atomUri",
|
|
||||||
"inReplyToAtomUri":"ostatus:inReplyToAtomUri",
|
|
||||||
"conversation":"ostatus:conversation",
|
|
||||||
"toot":"http://joinmastodon.org/ns#",
|
|
||||||
"Emoji":"toot:Emoji",
|
|
||||||
"focalPoint": {
|
|
||||||
"@container":"@list",
|
|
||||||
"@id":"toot:focalPoint"
|
|
||||||
},
|
|
||||||
"featured":"toot:featured"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"id": self.compute_id(conn),
|
|
||||||
"type": Self::get_actor_type().to_string(),
|
|
||||||
"inbox": self.compute_inbox(conn),
|
|
||||||
"outbox": self.compute_outbox(conn),
|
|
||||||
"preferredUsername": self.get_actor_id(),
|
|
||||||
"name": "",
|
|
||||||
"summary": "",
|
|
||||||
"url": self.compute_id(conn),
|
|
||||||
"endpoints": {
|
|
||||||
"sharedInbox": "https://plu.me/inbox"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compute_outbox(&self, conn: &PgConnection) -> String {
|
|
||||||
self.compute_box(conn, "outbox")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compute_inbox(&self, conn: &PgConnection) -> String {
|
|
||||||
self.compute_box(conn, "inbox")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compute_box(&self, conn: &PgConnection, box_name: &str) -> String {
|
|
||||||
format!("{id}/{name}", id = self.compute_id(conn), name = box_name)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compute_id(&self, conn: &PgConnection) -> String {
|
|
||||||
format!(
|
|
||||||
"https://{instance}/{prefix}/{user}",
|
|
||||||
instance = self.get_instance(conn).public_domain,
|
|
||||||
prefix = Self::get_box_prefix(),
|
|
||||||
user = self.get_actor_id()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use serde_json;
|
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
pub trait Webfinger {
|
pub trait Webfinger {
|
||||||
fn webfinger_subject(&self, conn: &PgConnection) -> String;
|
fn webfinger_subject(&self, conn: &PgConnection) -> String;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use std::ops::Deref;
|
|
||||||
use rocket::http::Status;
|
|
||||||
use rocket::request::{self, FromRequest};
|
|
||||||
use rocket::{Request, State, Outcome};
|
|
||||||
use diesel::pg::PgConnection;
|
use diesel::pg::PgConnection;
|
||||||
use diesel::r2d2::{ConnectionManager, Pool, PooledConnection};
|
use diesel::r2d2::{ConnectionManager, Pool, PooledConnection};
|
||||||
|
use rocket::{Request, State, Outcome};
|
||||||
|
use rocket::http::Status;
|
||||||
|
use rocket::request::{self, FromRequest};
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
// From rocket documentation
|
// From rocket documentation
|
||||||
|
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
#![feature(plugin, custom_derive)]
|
#![feature(plugin, custom_derive)]
|
||||||
#![plugin(rocket_codegen)]
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate bcrypt;
|
||||||
|
extern crate heck;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
extern crate dotenv;
|
extern crate dotenv;
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
extern crate rocket_contrib;
|
extern crate rocket_contrib;
|
||||||
extern crate bcrypt;
|
|
||||||
extern crate heck;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use diesel::pg::PgConnection;
|
use diesel::pg::PgConnection;
|
||||||
use diesel::r2d2::{ConnectionManager, Pool};
|
use diesel::r2d2::{ConnectionManager, Pool};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use std::env;
|
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
mod activity_pub;
|
mod activity_pub;
|
||||||
mod db_conn;
|
mod db_conn;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use diesel;
|
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
||||||
use diesel::{QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
|
||||||
use schema::blog_authors;
|
use schema::blog_authors;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable)]
|
#[derive(Queryable, Identifiable)]
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
use diesel;
|
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
||||||
use diesel::{QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
|
||||||
use schema::blogs;
|
use activity_pub::actor::{Actor, ActorType};
|
||||||
use activity_pub::{Actor, ActorType};
|
|
||||||
use models::instance::Instance;
|
|
||||||
use activity_pub::webfinger::*;
|
use activity_pub::webfinger::*;
|
||||||
|
use models::instance::Instance;
|
||||||
|
use schema::blogs;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable)]
|
#[derive(Queryable, Identifiable)]
|
||||||
pub struct Blog {
|
pub struct Blog {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use diesel;
|
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
||||||
use diesel::{ QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection };
|
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use schema::{instances, users};
|
|
||||||
use models::users::User;
|
use models::users::User;
|
||||||
|
use schema::{instances, users};
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable)]
|
#[derive(Identifiable, Queryable)]
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use diesel;
|
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||||
use diesel::{PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
|
||||||
use schema::post_authors;
|
use schema::post_authors;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable)]
|
#[derive(Queryable, Identifiable)]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use diesel;
|
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
|
||||||
use diesel::{PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
|
|
||||||
use schema::posts;
|
use schema::posts;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable)]
|
#[derive(Queryable, Identifiable)]
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
use rocket::request;
|
|
||||||
use rocket::request::{FromRequest, Request};
|
|
||||||
use rocket::outcome::IntoOutcome;
|
|
||||||
use diesel;
|
|
||||||
use diesel::{QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
|
||||||
use schema::users;
|
|
||||||
use db_conn::DbConn;
|
|
||||||
use activity_pub::{ActorType, Actor};
|
|
||||||
use models::instance::Instance;
|
|
||||||
use bcrypt;
|
use bcrypt;
|
||||||
|
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
||||||
|
use rocket::request::{self, FromRequest, Request};
|
||||||
|
use rocket::outcome::IntoOutcome;
|
||||||
|
|
||||||
|
use activity_pub::actor::{ActorType, Actor};
|
||||||
use activity_pub::webfinger::Webfinger;
|
use activity_pub::webfinger::Webfinger;
|
||||||
|
use db_conn::DbConn;
|
||||||
|
use models::instance::Instance;
|
||||||
|
use schema::users;
|
||||||
|
|
||||||
pub const AUTH_COOKIE: &'static str = "user_id";
|
pub const AUTH_COOKIE: &'static str = "user_id";
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@ use rocket::response::Redirect;
|
|||||||
use rocket_contrib::{Json, Template};
|
use rocket_contrib::{Json, Template};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use utils;
|
use activity_pub::actor::Actor;
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::blogs::*;
|
|
||||||
use models::blog_authors::*;
|
use models::blog_authors::*;
|
||||||
|
use models::blogs::*;
|
||||||
use models::instance::Instance;
|
use models::instance::Instance;
|
||||||
use models::users::User;
|
use models::users::User;
|
||||||
use activity_pub::Actor;
|
use utils;
|
||||||
|
|
||||||
#[get("/~/<name>", rank = 2)]
|
#[get("/~/<name>", rank = 2)]
|
||||||
fn details(name: String) -> String {
|
fn details(name: String) -> String {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use rocket_contrib::Template;
|
|
||||||
use rocket::response::Redirect;
|
|
||||||
use rocket::request::Form;
|
use rocket::request::Form;
|
||||||
|
use rocket::response::Redirect;
|
||||||
|
use rocket_contrib::Template;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
pub mod blogs;
|
pub mod blogs;
|
||||||
pub mod instance;
|
pub mod instance;
|
||||||
pub mod session;
|
|
||||||
pub mod posts;
|
pub mod posts;
|
||||||
|
pub mod session;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
pub mod well_known;
|
pub mod well_known;
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
use rocket::response::Redirect;
|
use heck::KebabCase;
|
||||||
use rocket::request::Form;
|
use rocket::request::Form;
|
||||||
|
use rocket::response::Redirect;
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use heck::KebabCase;
|
|
||||||
|
|
||||||
use utils;
|
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::blogs::*;
|
use models::blogs::*;
|
||||||
use models::posts::*;
|
|
||||||
use models::post_authors::*;
|
use models::post_authors::*;
|
||||||
|
use models::posts::*;
|
||||||
use models::users::User;
|
use models::users::User;
|
||||||
|
use utils;
|
||||||
|
|
||||||
#[get("/~/<blog>/<slug>", rank = 3)]
|
#[get("/~/<blog>/<slug>", rank = 3)]
|
||||||
fn details(blog: String, slug: String, conn: DbConn) -> String {
|
fn details(blog: String, slug: String, conn: DbConn) -> String {
|
||||||
@ -18,13 +18,13 @@ fn details(blog: String, slug: String, conn: DbConn) -> String {
|
|||||||
format!("{} in {}", post.title, blog.title)
|
format!("{} in {}", post.title, blog.title)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/~/<blog>/new", rank = 1)]
|
#[get("/~/<_blog>/new", rank = 1)]
|
||||||
fn new(blog: String, user: User) -> Template {
|
fn new(_blog: String, _user: User) -> Template {
|
||||||
Template::render("posts/new", HashMap::<String, String>::new())
|
Template::render("posts/new", HashMap::<String, String>::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/~/<blog>/new", rank = 2)]
|
#[get("/~/<_blog>/new", rank = 2)]
|
||||||
fn new_auth(blog: String) -> Redirect {
|
fn new_auth(_blog: String) -> Redirect {
|
||||||
utils::requires_login()
|
utils::requires_login()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
use std::collections::HashMap;
|
use rocket::http::{Cookie, Cookies};
|
||||||
use rocket_contrib::Template;
|
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
use rocket::request::Form;
|
|
||||||
use models::users::User;
|
|
||||||
use rocket::response::status::NotFound;
|
use rocket::response::status::NotFound;
|
||||||
use rocket::http::Cookies;
|
use rocket::request::Form;
|
||||||
|
use rocket_contrib::Template;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use rocket::http::Cookie;
|
use models::users::{User, AUTH_COOKIE};
|
||||||
use models::users::AUTH_COOKIE;
|
|
||||||
|
|
||||||
#[get("/login")]
|
#[get("/login")]
|
||||||
fn new() -> Template {
|
fn new() -> Template {
|
||||||
|
@ -3,10 +3,10 @@ use rocket::response::Redirect;
|
|||||||
use rocket_contrib::{Json, Template};
|
use rocket_contrib::{Json, Template};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use activity_pub::actor::Actor;
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::users::*;
|
|
||||||
use models::instance::Instance;
|
use models::instance::Instance;
|
||||||
use activity_pub::Actor;
|
use models::users::*;
|
||||||
|
|
||||||
#[get("/me")]
|
#[get("/me")]
|
||||||
fn me(user: User) -> String {
|
fn me(user: User) -> String {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use models::instance::Instance;
|
|
||||||
use db_conn::DbConn;
|
|
||||||
use models::users::User;
|
|
||||||
use models::blogs::Blog;
|
|
||||||
use rocket_contrib::Json;
|
|
||||||
use activity_pub::webfinger::Webfinger;
|
use activity_pub::webfinger::Webfinger;
|
||||||
|
use db_conn::DbConn;
|
||||||
|
use models::blogs::Blog;
|
||||||
|
use models::instance::Instance;
|
||||||
|
use models::users::User;
|
||||||
|
|
||||||
#[get("/.well-known/host-meta", format = "application/xml")]
|
#[get("/.well-known/host-meta", format = "application/xml")]
|
||||||
fn host_meta(conn: DbConn) -> String {
|
fn host_meta(conn: DbConn) -> String {
|
||||||
|
Loading…
Reference in New Issue
Block a user