Run 'cargo fmt' to format code (#489)
This commit is contained in:
committed by
Baptiste Gelez
parent
732f514da7
commit
b945d1f602
+167
-132
@@ -39,16 +39,13 @@ extern crate validator_derive;
|
||||
extern crate webfinger;
|
||||
|
||||
use diesel::r2d2::ConnectionManager;
|
||||
use rocket::{
|
||||
Config, State,
|
||||
config::Limits
|
||||
};
|
||||
use rocket_csrf::CsrfFairingBuilder;
|
||||
use plume_models::{
|
||||
DATABASE_URL, Connection, Error,
|
||||
db_conn::{DbPool, PragmaForeignKey},
|
||||
search::{Searcher as UnmanagedSearcher, SearcherError},
|
||||
Connection, Error, DATABASE_URL,
|
||||
};
|
||||
use rocket::{config::Limits, Config, State};
|
||||
use rocket_csrf::CsrfFairingBuilder;
|
||||
use scheduled_thread_pool::ScheduledThreadPool;
|
||||
use std::env;
|
||||
use std::process::exit;
|
||||
@@ -78,7 +75,8 @@ fn init_pool() -> Option<DbPool> {
|
||||
let manager = ConnectionManager::<Connection>::new(DATABASE_URL.as_str());
|
||||
DbPool::builder()
|
||||
.connection_customizer(Box::new(PragmaForeignKey))
|
||||
.build(manager).ok()
|
||||
.build(manager)
|
||||
.ok()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -89,37 +87,58 @@ fn main() {
|
||||
let searcher = match UnmanagedSearcher::open(&"search_index") {
|
||||
Err(Error::Search(e)) => match e {
|
||||
SearcherError::WriteLockAcquisitionError => panic!(
|
||||
r#"Your search index is locked. Plume can't start. To fix this issue
|
||||
r#"Your search index is locked. Plume can't start. To fix this issue
|
||||
make sure no other Plume instance is started, and run:
|
||||
|
||||
plm search unlock
|
||||
|
||||
Then try to restart Plume.
|
||||
"#),
|
||||
e => Err(e).unwrap()
|
||||
"#
|
||||
),
|
||||
e => Err(e).unwrap(),
|
||||
},
|
||||
Err(_) => panic!("Unexpected error while opening search index"),
|
||||
Ok(s) => Arc::new(s)
|
||||
Ok(s) => Arc::new(s),
|
||||
};
|
||||
|
||||
let commiter = searcher.clone();
|
||||
workpool.execute_with_fixed_delay(Duration::from_secs(5), Duration::from_secs(60*30), move || commiter.commit());
|
||||
workpool.execute_with_fixed_delay(
|
||||
Duration::from_secs(5),
|
||||
Duration::from_secs(60 * 30),
|
||||
move || commiter.commit(),
|
||||
);
|
||||
|
||||
let search_unlocker = searcher.clone();
|
||||
ctrlc::set_handler(move || {
|
||||
search_unlocker.drop_writer();
|
||||
exit(0);
|
||||
}).expect("Error setting Ctrl-c handler");
|
||||
})
|
||||
.expect("Error setting Ctrl-c handler");
|
||||
|
||||
let mut config = Config::active().unwrap();
|
||||
config.set_address(env::var("ROCKET_ADDRESS").unwrap_or_else(|_| "localhost".to_owned())).unwrap();
|
||||
config.set_port(env::var("ROCKET_PORT").ok().map(|s| s.parse::<u16>().unwrap()).unwrap_or(7878));
|
||||
config
|
||||
.set_address(env::var("ROCKET_ADDRESS").unwrap_or_else(|_| "localhost".to_owned()))
|
||||
.unwrap();
|
||||
config.set_port(
|
||||
env::var("ROCKET_PORT")
|
||||
.ok()
|
||||
.map(|s| s.parse::<u16>().unwrap())
|
||||
.unwrap_or(7878),
|
||||
);
|
||||
let _ = env::var("ROCKET_SECRET_KEY").map(|k| config.set_secret_key(k).unwrap());
|
||||
let form_size = &env::var("FORM_SIZE").unwrap_or_else(|_| "32".to_owned()).parse::<u64>().unwrap();
|
||||
let activity_size = &env::var("ACTIVITY_SIZE").unwrap_or_else(|_| "1024".to_owned()).parse::<u64>().unwrap();
|
||||
config.set_limits(Limits::new()
|
||||
.limit("forms", form_size * 1024)
|
||||
.limit("json", activity_size * 1024));
|
||||
let form_size = &env::var("FORM_SIZE")
|
||||
.unwrap_or_else(|_| "32".to_owned())
|
||||
.parse::<u64>()
|
||||
.unwrap();
|
||||
let activity_size = &env::var("ACTIVITY_SIZE")
|
||||
.unwrap_or_else(|_| "1024".to_owned())
|
||||
.parse::<u64>()
|
||||
.unwrap();
|
||||
config.set_limits(
|
||||
Limits::new()
|
||||
.limit("forms", form_size * 1024)
|
||||
.limit("json", activity_size * 1024),
|
||||
);
|
||||
|
||||
let mail = mail::init();
|
||||
if mail.is_none() && config.environment.is_prod() {
|
||||
@@ -128,110 +147,100 @@ Then try to restart Plume.
|
||||
}
|
||||
|
||||
rocket::custom(config)
|
||||
.mount("/", routes![
|
||||
routes::blogs::details,
|
||||
routes::blogs::activity_details,
|
||||
routes::blogs::outbox,
|
||||
routes::blogs::new,
|
||||
routes::blogs::new_auth,
|
||||
routes::blogs::create,
|
||||
routes::blogs::delete,
|
||||
routes::blogs::atom_feed,
|
||||
|
||||
routes::comments::create,
|
||||
routes::comments::delete,
|
||||
routes::comments::activity_pub,
|
||||
|
||||
routes::instance::index,
|
||||
routes::instance::local,
|
||||
routes::instance::feed,
|
||||
routes::instance::federated,
|
||||
routes::instance::admin,
|
||||
routes::instance::admin_instances,
|
||||
routes::instance::admin_users,
|
||||
routes::instance::ban,
|
||||
routes::instance::toggle_block,
|
||||
routes::instance::update_settings,
|
||||
routes::instance::shared_inbox,
|
||||
routes::instance::nodeinfo,
|
||||
routes::instance::about,
|
||||
routes::instance::web_manifest,
|
||||
|
||||
routes::likes::create,
|
||||
routes::likes::create_auth,
|
||||
|
||||
routes::medias::list,
|
||||
routes::medias::new,
|
||||
routes::medias::upload,
|
||||
routes::medias::details,
|
||||
routes::medias::delete,
|
||||
routes::medias::set_avatar,
|
||||
|
||||
routes::notifications::notifications,
|
||||
routes::notifications::notifications_auth,
|
||||
|
||||
routes::posts::details,
|
||||
routes::posts::activity_details,
|
||||
routes::posts::edit,
|
||||
routes::posts::update,
|
||||
routes::posts::new,
|
||||
routes::posts::new_auth,
|
||||
routes::posts::create,
|
||||
routes::posts::delete,
|
||||
|
||||
routes::reshares::create,
|
||||
routes::reshares::create_auth,
|
||||
|
||||
routes::search::search,
|
||||
|
||||
routes::session::new,
|
||||
routes::session::create,
|
||||
routes::session::delete,
|
||||
routes::session::password_reset_request_form,
|
||||
routes::session::password_reset_request,
|
||||
routes::session::password_reset_form,
|
||||
routes::session::password_reset,
|
||||
|
||||
routes::plume_static_files,
|
||||
routes::static_files,
|
||||
|
||||
routes::tags::tag,
|
||||
|
||||
routes::user::me,
|
||||
routes::user::details,
|
||||
routes::user::dashboard,
|
||||
routes::user::dashboard_auth,
|
||||
routes::user::followers,
|
||||
routes::user::followed,
|
||||
routes::user::edit,
|
||||
routes::user::edit_auth,
|
||||
routes::user::update,
|
||||
routes::user::delete,
|
||||
routes::user::follow,
|
||||
routes::user::follow_auth,
|
||||
routes::user::activity_details,
|
||||
routes::user::outbox,
|
||||
routes::user::inbox,
|
||||
routes::user::ap_followers,
|
||||
routes::user::new,
|
||||
routes::user::create,
|
||||
routes::user::atom_feed,
|
||||
|
||||
routes::well_known::host_meta,
|
||||
routes::well_known::nodeinfo,
|
||||
routes::well_known::webfinger,
|
||||
|
||||
routes::errors::csrf_violation
|
||||
])
|
||||
.mount("/api/v1", routes![
|
||||
api::oauth,
|
||||
|
||||
api::apps::create,
|
||||
|
||||
api::posts::get,
|
||||
api::posts::list,
|
||||
api::posts::create,
|
||||
])
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
routes::blogs::details,
|
||||
routes::blogs::activity_details,
|
||||
routes::blogs::outbox,
|
||||
routes::blogs::new,
|
||||
routes::blogs::new_auth,
|
||||
routes::blogs::create,
|
||||
routes::blogs::delete,
|
||||
routes::blogs::atom_feed,
|
||||
routes::comments::create,
|
||||
routes::comments::delete,
|
||||
routes::comments::activity_pub,
|
||||
routes::instance::index,
|
||||
routes::instance::local,
|
||||
routes::instance::feed,
|
||||
routes::instance::federated,
|
||||
routes::instance::admin,
|
||||
routes::instance::admin_instances,
|
||||
routes::instance::admin_users,
|
||||
routes::instance::ban,
|
||||
routes::instance::toggle_block,
|
||||
routes::instance::update_settings,
|
||||
routes::instance::shared_inbox,
|
||||
routes::instance::nodeinfo,
|
||||
routes::instance::about,
|
||||
routes::instance::web_manifest,
|
||||
routes::likes::create,
|
||||
routes::likes::create_auth,
|
||||
routes::medias::list,
|
||||
routes::medias::new,
|
||||
routes::medias::upload,
|
||||
routes::medias::details,
|
||||
routes::medias::delete,
|
||||
routes::medias::set_avatar,
|
||||
routes::notifications::notifications,
|
||||
routes::notifications::notifications_auth,
|
||||
routes::posts::details,
|
||||
routes::posts::activity_details,
|
||||
routes::posts::edit,
|
||||
routes::posts::update,
|
||||
routes::posts::new,
|
||||
routes::posts::new_auth,
|
||||
routes::posts::create,
|
||||
routes::posts::delete,
|
||||
routes::reshares::create,
|
||||
routes::reshares::create_auth,
|
||||
routes::search::search,
|
||||
routes::session::new,
|
||||
routes::session::create,
|
||||
routes::session::delete,
|
||||
routes::session::password_reset_request_form,
|
||||
routes::session::password_reset_request,
|
||||
routes::session::password_reset_form,
|
||||
routes::session::password_reset,
|
||||
routes::plume_static_files,
|
||||
routes::static_files,
|
||||
routes::tags::tag,
|
||||
routes::user::me,
|
||||
routes::user::details,
|
||||
routes::user::dashboard,
|
||||
routes::user::dashboard_auth,
|
||||
routes::user::followers,
|
||||
routes::user::followed,
|
||||
routes::user::edit,
|
||||
routes::user::edit_auth,
|
||||
routes::user::update,
|
||||
routes::user::delete,
|
||||
routes::user::follow,
|
||||
routes::user::follow_auth,
|
||||
routes::user::activity_details,
|
||||
routes::user::outbox,
|
||||
routes::user::inbox,
|
||||
routes::user::ap_followers,
|
||||
routes::user::new,
|
||||
routes::user::create,
|
||||
routes::user::atom_feed,
|
||||
routes::well_known::host_meta,
|
||||
routes::well_known::nodeinfo,
|
||||
routes::well_known::webfinger,
|
||||
routes::errors::csrf_violation
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
"/api/v1",
|
||||
routes![
|
||||
api::oauth,
|
||||
api::apps::create,
|
||||
api::posts::get,
|
||||
api::posts::list,
|
||||
api::posts::create,
|
||||
],
|
||||
)
|
||||
.register(catchers![
|
||||
routes::errors::not_found,
|
||||
routes::errors::unprocessable_entity,
|
||||
@@ -243,15 +252,41 @@ Then try to restart Plume.
|
||||
.manage(workpool)
|
||||
.manage(searcher)
|
||||
.manage(include_i18n!())
|
||||
.attach(CsrfFairingBuilder::new()
|
||||
.set_default_target("/csrf-violation?target=<uri>".to_owned(), rocket::http::Method::Post)
|
||||
.attach(
|
||||
CsrfFairingBuilder::new()
|
||||
.set_default_target(
|
||||
"/csrf-violation?target=<uri>".to_owned(),
|
||||
rocket::http::Method::Post,
|
||||
)
|
||||
.add_exceptions(vec![
|
||||
("/inbox".to_owned(), "/inbox".to_owned(), rocket::http::Method::Post),
|
||||
("/@/<name>/inbox".to_owned(), "/@/<name>/inbox".to_owned(), rocket::http::Method::Post),
|
||||
("/login".to_owned(), "/login".to_owned(), rocket::http::Method::Post),
|
||||
("/users/new".to_owned(), "/users/new".to_owned(), rocket::http::Method::Post),
|
||||
("/api/<path..>".to_owned(), "/api/<path..>".to_owned(), rocket::http::Method::Post)
|
||||
(
|
||||
"/inbox".to_owned(),
|
||||
"/inbox".to_owned(),
|
||||
rocket::http::Method::Post,
|
||||
),
|
||||
(
|
||||
"/@/<name>/inbox".to_owned(),
|
||||
"/@/<name>/inbox".to_owned(),
|
||||
rocket::http::Method::Post,
|
||||
),
|
||||
(
|
||||
"/login".to_owned(),
|
||||
"/login".to_owned(),
|
||||
rocket::http::Method::Post,
|
||||
),
|
||||
(
|
||||
"/users/new".to_owned(),
|
||||
"/users/new".to_owned(),
|
||||
rocket::http::Method::Post,
|
||||
),
|
||||
(
|
||||
"/api/<path..>".to_owned(),
|
||||
"/api/<path..>".to_owned(),
|
||||
rocket::http::Method::Post,
|
||||
),
|
||||
])
|
||||
.finalize().expect("main: csrf fairing creation error"))
|
||||
.finalize()
|
||||
.expect("main: csrf fairing creation error"),
|
||||
)
|
||||
.launch();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user