Plume/src/routes/instance.rs

66 lines
1.8 KiB
Rust
Raw Normal View History

2018-06-17 18:06:47 +02:00
use gettextrs::gettext;
2018-06-10 21:33:42 +02:00
use rocket_contrib::{Json, Template};
use serde_json;
2018-05-13 19:39:18 +02:00
use activity_pub::inbox::Inbox;
use db_conn::DbConn;
2018-05-19 09:39:59 +02:00
use models::{
2018-06-10 21:33:42 +02:00
comments::Comment,
2018-05-19 09:39:59 +02:00
posts::Post,
users::User,
instance::*
};
2018-04-29 19:50:46 +02:00
#[get("/")]
2018-05-10 22:31:52 +02:00
fn index(conn: DbConn, user: Option<User>) -> Template {
2018-04-29 19:50:46 +02:00
match Instance::get_local(&*conn) {
Some(inst) => {
let recents = Post::get_recents(&*conn, 6);
2018-05-09 21:09:52 +02:00
Template::render("instance/index", json!({
2018-05-10 22:31:52 +02:00
"instance": inst,
"account": user,
"recents": recents.into_iter().map(|p| p.to_json(&*conn)).collect::<Vec<serde_json::Value>>()
2018-05-09 21:09:52 +02:00
}))
2018-04-29 19:50:46 +02:00
}
None => {
2018-05-09 21:09:52 +02:00
Template::render("errors/500", json!({
2018-06-17 18:06:47 +02:00
"error_message": gettext("You need to configure your instance before using it.".to_string())
2018-05-09 21:09:52 +02:00
}))
2018-04-29 19:50:46 +02:00
}
}
}
2018-05-13 19:39:18 +02:00
#[post("/inbox", data = "<data>")]
fn shared_inbox(conn: DbConn, data: String) -> String {
let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap();
let instance = Instance::get_local(&*conn).unwrap();
instance.received(&*conn, act);
String::from("")
}
2018-06-10 21:33:42 +02:00
#[get("/nodeinfo")]
fn nodeinfo(conn: DbConn) -> Json<serde_json::Value> {
2018-06-10 21:33:42 +02:00
Json(json!({
"version": "2.0",
"software": {
"name": "Plume",
"version": "0.1.0"
},
"protocols": ["activitypub"],
"services": {
"inbound": [],
"outbound": []
},
"openRegistrations": true,
"usage": {
"users": {
"total": User::count_local(&*conn)
},
"localPosts": Post::count_local(&*conn),
"localComments": Comment::count_local(&*conn)
},
"metadata": {}
}))
}