Update to the latest version of Rocket, to use rocket_contrib::Template::custom
This commit is contained in:
@@ -19,7 +19,7 @@ pub mod request;
|
||||
pub mod sign;
|
||||
pub mod webfinger;
|
||||
|
||||
pub type ActivityPub = Content<Json>;
|
||||
pub type ActivityPub = Content<Json<serde_json::Value>>;
|
||||
|
||||
pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams";
|
||||
pub const PUBLIC_VISIBILTY: &'static str = "https://www.w3.org/ns/activitystreams#Public";
|
||||
|
||||
+11
@@ -1,7 +1,10 @@
|
||||
use gettextrs::*;
|
||||
use rocket::{Data, Request, Rocket, fairing::{Fairing, Info, Kind}};
|
||||
use serde_json;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use tera::{Tera, Error as TeraError};
|
||||
|
||||
const ACCEPT_LANG: &'static str = "Accept-Language";
|
||||
|
||||
@@ -42,3 +45,11 @@ impl Fairing for I18n {
|
||||
setlocale(LocaleCategory::LcAll, format!("{}.UTF-8", lang.replace("-", "_")));
|
||||
}
|
||||
}
|
||||
|
||||
fn tera_gettext(ctx: HashMap<String, serde_json::Value>) -> Result<serde_json::Value, TeraError> {
|
||||
Ok(serde_json::Value::String(String::from("")))
|
||||
}
|
||||
|
||||
pub fn tera(t: &mut Tera) {
|
||||
t.register_global_function("gettext", Box::new(tera_gettext))
|
||||
}
|
||||
|
||||
+6
-3
@@ -1,7 +1,8 @@
|
||||
#![feature(plugin, custom_derive, iterator_find_map)]
|
||||
#![feature(plugin, custom_derive, decl_macro, iterator_find_map)]
|
||||
#![plugin(rocket_codegen)]
|
||||
|
||||
extern crate activitypub;
|
||||
extern crate ammonia;
|
||||
extern crate array_tool;
|
||||
extern crate base64;
|
||||
extern crate bcrypt;
|
||||
@@ -29,8 +30,8 @@ extern crate serde;
|
||||
extern crate serde_derive;
|
||||
#[macro_use]
|
||||
extern crate serde_json;
|
||||
extern crate tera;
|
||||
extern crate url;
|
||||
extern crate ammonia;
|
||||
|
||||
use diesel::{pg::PgConnection, r2d2::{ConnectionManager, Pool}};
|
||||
use dotenv::dotenv;
|
||||
@@ -128,7 +129,9 @@ fn main() {
|
||||
routes::well_known::webfinger
|
||||
])
|
||||
.manage(init_pool())
|
||||
.attach(Template::fairing())
|
||||
.attach(Template::custom(|engines| {
|
||||
i18n::tera(&mut engines.tera);
|
||||
}))
|
||||
.attach(i18n::I18n::new("plume"))
|
||||
.launch();
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ fn create(conn: DbConn, data: Form<NewBlogForm>, user: User) -> Redirect {
|
||||
is_owner: true
|
||||
});
|
||||
|
||||
Redirect::to(format!("/~/{}/", slug).as_str())
|
||||
Redirect::to(format!("/~/{}/", slug))
|
||||
}
|
||||
|
||||
#[get("/~/<name>/outbox")]
|
||||
|
||||
@@ -55,5 +55,5 @@ fn create(blog: String, slug: String, query: CommentQuery, data: Form<NewComment
|
||||
|
||||
broadcast(&*conn, &user, comment.create_activity(&*conn), user.get_followers(&*conn));
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/#comment-{}", blog, slug, comment.id).as_ref())
|
||||
Redirect::to(format!("/~/{}/{}/#comment-{}", blog, slug, comment.id))
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ fn shared_inbox(conn: DbConn, data: String) -> String {
|
||||
}
|
||||
|
||||
#[get("/nodeinfo")]
|
||||
fn nodeinfo(conn: DbConn) -> Json {
|
||||
fn nodeinfo(conn: DbConn) -> Json<serde_json::Value> {
|
||||
Json(json!({
|
||||
"version": "2.0",
|
||||
"software": {
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
broadcast(&*conn, &user, delete_act, user.get_followers(&*conn));
|
||||
}
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug).as_ref())
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug))
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/<slug>/like", rank = 2)]
|
||||
|
||||
+1
-1
@@ -120,5 +120,5 @@ fn create(blog_name: String, data: Form<NewPostForm>, user: User, conn: DbConn)
|
||||
let act = post.create_activity(&*conn);
|
||||
broadcast(&*conn, &user, act, user.get_followers(&*conn));
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/", blog_name, slug).as_str())
|
||||
Redirect::to(format!("/~/{}/{}/", blog_name, slug))
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
broadcast(&*conn, &user, delete_act, user.get_followers(&*conn));
|
||||
}
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug).as_ref())
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug))
|
||||
}
|
||||
|
||||
#[get("/~/<blog>/<slug>/reshare", rank=1)]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use rocket::{
|
||||
http::{Cookie, Cookies},
|
||||
http::{Cookie, Cookies, uri::Uri},
|
||||
response::{Redirect, status::NotFound},
|
||||
request::{Form,FlashMessage}
|
||||
};
|
||||
@@ -49,10 +49,10 @@ fn create(conn: DbConn, data: Form<LoginForm>, flash: Option<FlashMessage>, mut
|
||||
Ok(usr) => {
|
||||
if usr.auth(form.password.to_string()) {
|
||||
cookies.add_private(Cookie::new(AUTH_COOKIE, usr.id.to_string()));
|
||||
Ok(Redirect::to(&flash
|
||||
.and_then(|f| if f.name()=="callback" { Some(f.msg().to_owned()) } else { None })
|
||||
Ok(Redirect::to(Uri::new(flash
|
||||
.and_then(|f| if f.name() == "callback" { Some(f.msg().to_owned()) } else { None })
|
||||
.unwrap_or("/".to_owned()))
|
||||
)
|
||||
))
|
||||
} else {
|
||||
Err(NotFound(String::from("Invalid username or password")))
|
||||
}
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ use utils;
|
||||
#[get("/me")]
|
||||
fn me(user: Option<User>) -> Result<Redirect,Flash<Redirect>> {
|
||||
match user {
|
||||
Some(user) => Ok(Redirect::to(format!("/@/{}/", user.username).as_ref())),
|
||||
Some(user) => Ok(Redirect::to(format!("/@/{}/", user.username))),
|
||||
None => Err(utils::requires_login("", "/me"))
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ fn follow(name: String, conn: DbConn, user: User) -> Redirect {
|
||||
act.follow_props.set_object_object(user.into_activity(&*conn)).unwrap();
|
||||
act.object_props.set_id_string(format!("{}/follow/{}", user.ap_url, target.ap_url)).unwrap();
|
||||
broadcast(&*conn, &user, act, vec![target]);
|
||||
Redirect::to(format!("/@/{}/", name).as_ref())
|
||||
Redirect::to(format!("/@/{}/", name))
|
||||
}
|
||||
|
||||
#[get("/@/<name>/follow", rank = 2)]
|
||||
@@ -208,7 +208,7 @@ fn create(conn: DbConn, data: Form<NewUserForm>) -> Result<Redirect, String> {
|
||||
User::hash_pass(form.password.to_string()),
|
||||
inst.id
|
||||
)).update_boxes(&*conn);
|
||||
Ok(Redirect::to(format!("/@/{}/", data.get().username).as_str()))
|
||||
Ok(Redirect::to(format!("/@/{}/", data.get().username)))
|
||||
} else {
|
||||
Err(String::from("Passwords don't match"))
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,5 +1,8 @@
|
||||
use heck::CamelCase;
|
||||
use rocket::response::{Redirect, Flash};
|
||||
use rocket::{
|
||||
http::uri::Uri,
|
||||
response::{Redirect, Flash}
|
||||
};
|
||||
|
||||
/// Remove non alphanumeric characters and CamelCase a string
|
||||
pub fn make_actor_id(name: String) -> String {
|
||||
@@ -12,5 +15,5 @@ pub fn make_actor_id(name: String) -> String {
|
||||
}
|
||||
|
||||
pub fn requires_login(message: &str, url: &str) -> Flash<Redirect> {
|
||||
Flash::new(Redirect::to(&format!("/login?m={}", message)), "callback", url)
|
||||
Flash::new(Redirect::to(Uri::new(format!("/login?m={}", message))), "callback", url)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user