use super::*;
use crate::send_email;
use crate::settings::Settings;
+use diesel::PgConnection;
#[derive(Serialize, Deserialize)]
pub struct CreateComment {
}
impl Perform<CommentResponse> for Oper<CreateComment> {
- fn perform(&self) -> Result<CommentResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<CommentResponse, Error> {
let data: &CreateComment = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<CommentResponse> for Oper<EditComment> {
- fn perform(&self) -> Result<CommentResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<CommentResponse, Error> {
let data: &EditComment = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<CommentResponse> for Oper<SaveComment> {
- fn perform(&self) -> Result<CommentResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<CommentResponse, Error> {
let data: &SaveComment = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<CommentResponse> for Oper<CreateCommentLike> {
- fn perform(&self) -> Result<CommentResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<CommentResponse, Error> {
let data: &CreateCommentLike = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
use super::*;
+use diesel::PgConnection;
use std::str::FromStr;
#[derive(Serialize, Deserialize)]
}
impl Perform<GetCommunityResponse> for Oper<GetCommunity> {
- fn perform(&self) -> Result<GetCommunityResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetCommunityResponse, Error> {
let data: &GetCommunity = &self.data;
- let conn = establish_connection();
let user_id: Option<i32> = match &data.auth {
Some(auth) => match Claims::decode(&auth) {
}
impl Perform<CommunityResponse> for Oper<CreateCommunity> {
- fn perform(&self) -> Result<CommunityResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<CommunityResponse, Error> {
let data: &CreateCommunity = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<CommunityResponse> for Oper<EditCommunity> {
- fn perform(&self) -> Result<CommunityResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<CommunityResponse, Error> {
let data: &EditCommunity = &self.data;
if has_slurs(&data.name) || has_slurs(&data.title) {
return Err(APIError::err(&self.op, "no_slurs").into());
}
- let conn = establish_connection();
-
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()),
}
impl Perform<ListCommunitiesResponse> for Oper<ListCommunities> {
- fn perform(&self) -> Result<ListCommunitiesResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<ListCommunitiesResponse, Error> {
let data: &ListCommunities = &self.data;
- let conn = establish_connection();
let user_claims: Option<Claims> = match &data.auth {
Some(auth) => match Claims::decode(&auth) {
}
impl Perform<CommunityResponse> for Oper<FollowCommunity> {
- fn perform(&self) -> Result<CommunityResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<CommunityResponse, Error> {
let data: &FollowCommunity = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<GetFollowedCommunitiesResponse> for Oper<GetFollowedCommunities> {
- fn perform(&self) -> Result<GetFollowedCommunitiesResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetFollowedCommunitiesResponse, Error> {
let data: &GetFollowedCommunities = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> {
- fn perform(&self) -> Result<BanFromCommunityResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<BanFromCommunityResponse, Error> {
let data: &BanFromCommunity = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<AddModToCommunityResponse> for Oper<AddModToCommunity> {
- fn perform(&self) -> Result<AddModToCommunityResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<AddModToCommunityResponse, Error> {
let data: &AddModToCommunity = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<GetCommunityResponse> for Oper<TransferCommunity> {
- fn perform(&self) -> Result<GetCommunityResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetCommunityResponse, Error> {
let data: &TransferCommunity = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
use crate::db::user_view::*;
use crate::db::*;
use crate::{extract_usernames, has_slurs, naive_from_unix, naive_now, remove_slurs};
+use diesel::PgConnection;
use failure::Error;
use serde::{Deserialize, Serialize};
}
pub trait Perform<T> {
- fn perform(&self) -> Result<T, Error>
+ fn perform(&self, conn: &PgConnection) -> Result<T, Error>
where
T: Sized;
}
use super::*;
+use diesel::PgConnection;
use std::str::FromStr;
#[derive(Serialize, Deserialize)]
}
impl Perform<PostResponse> for Oper<CreatePost> {
- fn perform(&self) -> Result<PostResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<PostResponse, Error> {
let data: &CreatePost = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<GetPostResponse> for Oper<GetPost> {
- fn perform(&self) -> Result<GetPostResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetPostResponse, Error> {
let data: &GetPost = &self.data;
- let conn = establish_connection();
let user_id: Option<i32> = match &data.auth {
Some(auth) => match Claims::decode(&auth) {
}
impl Perform<GetPostsResponse> for Oper<GetPosts> {
- fn perform(&self) -> Result<GetPostsResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetPostsResponse, Error> {
let data: &GetPosts = &self.data;
- let conn = establish_connection();
let user_claims: Option<Claims> = match &data.auth {
Some(auth) => match Claims::decode(&auth) {
}
impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
- fn perform(&self) -> Result<CreatePostLikeResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<CreatePostLikeResponse, Error> {
let data: &CreatePostLike = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<PostResponse> for Oper<EditPost> {
- fn perform(&self) -> Result<PostResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<PostResponse, Error> {
let data: &EditPost = &self.data;
if has_slurs(&data.name) || (data.body.is_some() && has_slurs(&data.body.to_owned().unwrap())) {
return Err(APIError::err(&self.op, "no_slurs").into());
}
- let conn = establish_connection();
-
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()),
}
impl Perform<PostResponse> for Oper<SavePost> {
- fn perform(&self) -> Result<PostResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<PostResponse, Error> {
let data: &SavePost = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
use super::*;
+use diesel::PgConnection;
use std::str::FromStr;
#[derive(Serialize, Deserialize)]
}
impl Perform<ListCategoriesResponse> for Oper<ListCategories> {
- fn perform(&self) -> Result<ListCategoriesResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<ListCategoriesResponse, Error> {
let _data: &ListCategories = &self.data;
- let conn = establish_connection();
let categories: Vec<Category> = Category::list_all(&conn)?;
}
impl Perform<GetModlogResponse> for Oper<GetModlog> {
- fn perform(&self) -> Result<GetModlogResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetModlogResponse, Error> {
let data: &GetModlog = &self.data;
- let conn = establish_connection();
let removed_posts = ModRemovePostView::list(
&conn,
}
impl Perform<SiteResponse> for Oper<CreateSite> {
- fn perform(&self) -> Result<SiteResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<SiteResponse, Error> {
let data: &CreateSite = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<SiteResponse> for Oper<EditSite> {
- fn perform(&self) -> Result<SiteResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<SiteResponse, Error> {
let data: &EditSite = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<GetSiteResponse> for Oper<GetSite> {
- fn perform(&self) -> Result<GetSiteResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetSiteResponse, Error> {
let _data: &GetSite = &self.data;
- let conn = establish_connection();
// It can return a null site in order to redirect
let site_view = match Site::read(&conn, 1) {
}
impl Perform<SearchResponse> for Oper<Search> {
- fn perform(&self) -> Result<SearchResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<SearchResponse, Error> {
let data: &Search = &self.data;
- let conn = establish_connection();
let sort = SortType::from_str(&data.sort)?;
let type_ = SearchType::from_str(&data.type_)?;
}
impl Perform<GetSiteResponse> for Oper<TransferSite> {
- fn perform(&self) -> Result<GetSiteResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetSiteResponse, Error> {
let data: &TransferSite = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
use crate::settings::Settings;
use crate::{generate_random_string, send_email};
use bcrypt::verify;
+use diesel::PgConnection;
use std::str::FromStr;
#[derive(Serialize, Deserialize, Debug)]
}
impl Perform<LoginResponse> for Oper<Login> {
- fn perform(&self) -> Result<LoginResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
let data: &Login = &self.data;
- let conn = establish_connection();
// Fetch that username / email
let user: User_ = match User_::find_by_email_or_username(&conn, &data.username_or_email) {
}
impl Perform<LoginResponse> for Oper<Register> {
- fn perform(&self) -> Result<LoginResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
let data: &Register = &self.data;
- let conn = establish_connection();
// Make sure site has open registration
if let Ok(site) = SiteView::read(&conn) {
}
impl Perform<LoginResponse> for Oper<SaveUserSettings> {
- fn perform(&self) -> Result<LoginResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
let data: &SaveUserSettings = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<GetUserDetailsResponse> for Oper<GetUserDetails> {
- fn perform(&self) -> Result<GetUserDetailsResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetUserDetailsResponse, Error> {
let data: &GetUserDetails = &self.data;
- let conn = establish_connection();
let user_claims: Option<Claims> = match &data.auth {
Some(auth) => match Claims::decode(&auth) {
}
impl Perform<AddAdminResponse> for Oper<AddAdmin> {
- fn perform(&self) -> Result<AddAdminResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<AddAdminResponse, Error> {
let data: &AddAdmin = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<BanUserResponse> for Oper<BanUser> {
- fn perform(&self) -> Result<BanUserResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<BanUserResponse, Error> {
let data: &BanUser = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<GetRepliesResponse> for Oper<GetReplies> {
- fn perform(&self) -> Result<GetRepliesResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetRepliesResponse, Error> {
let data: &GetReplies = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<GetUserMentionsResponse> for Oper<GetUserMentions> {
- fn perform(&self) -> Result<GetUserMentionsResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetUserMentionsResponse, Error> {
let data: &GetUserMentions = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<UserMentionResponse> for Oper<EditUserMention> {
- fn perform(&self) -> Result<UserMentionResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<UserMentionResponse, Error> {
let data: &EditUserMention = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<GetRepliesResponse> for Oper<MarkAllAsRead> {
- fn perform(&self) -> Result<GetRepliesResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<GetRepliesResponse, Error> {
let data: &MarkAllAsRead = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<LoginResponse> for Oper<DeleteAccount> {
- fn perform(&self) -> Result<LoginResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
let data: &DeleteAccount = &self.data;
- let conn = establish_connection();
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
}
impl Perform<PasswordResetResponse> for Oper<PasswordReset> {
- fn perform(&self) -> Result<PasswordResetResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<PasswordResetResponse, Error> {
let data: &PasswordReset = &self.data;
- let conn = establish_connection();
// Fetch that email
let user: User_ = match User_::find_by_email(&conn, &data.email) {
}
impl Perform<LoginResponse> for Oper<PasswordChange> {
- fn perform(&self) -> Result<LoginResponse, Error> {
+ fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
let data: &PasswordChange = &self.data;
- let conn = establish_connection();
// Fetch the user_id from the token
let user_id = PasswordResetRequest::read_from_token(&conn, &data.token)?.user_id;
use crate::apub::make_apub_endpoint;
use crate::db::community::Community;
use crate::db::community_view::CommunityFollowerView;
-use crate::db::establish_connection;
+use crate::db::establish_unpooled_connection;
use crate::to_datetime_utc;
use activitypub::{actor::Group, collection::UnorderedCollection, context};
use actix_web::body::Body;
collection.object_props.set_context_object(context()).ok();
collection.object_props.set_id_string(base_url).ok();
- let connection = establish_connection();
+ let connection = establish_unpooled_connection();
//As we are an object, we validated that the community id was valid
let community_followers = CommunityFollowerView::for_community(&connection, self.id).unwrap();
}
pub async fn get_apub_community(info: Path<CommunityQuery>) -> HttpResponse<Body> {
- let connection = establish_connection();
+ let connection = establish_unpooled_connection();
if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) {
HttpResponse::Ok()
}
pub async fn get_apub_community_followers(info: Path<CommunityQuery>) -> HttpResponse<Body> {
- let connection = establish_connection();
+ let connection = establish_unpooled_connection();
if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) {
HttpResponse::Ok()
use crate::apub::make_apub_endpoint;
-use crate::db::establish_connection;
+use crate::db::establish_unpooled_connection;
use crate::db::user::User_;
use crate::to_datetime_utc;
use activitypub::{actor::Person, context};
}
pub async fn get_apub_user(info: Path<UserQuery>) -> HttpResponse<Body> {
- let connection = establish_connection();
+ let connection = establish_unpooled_connection();
if let Ok(user) = User_::find_by_email_or_username(&connection, &info.user_name) {
HttpResponse::Ok()
use super::*;
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let categories = Category::list_all(&conn).unwrap();
let expected_first_category = Category {
use super::*;
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let new_user = UserForm {
name: "terry".into(),
use super::*;
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let new_user = UserForm {
name: "timmy".into(),
use super::*;
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let new_user = UserForm {
name: "bobbee".into(),
extern crate lazy_static;
use crate::settings::Settings;
use diesel::dsl::*;
-use diesel::r2d2::*;
use diesel::result::Error;
use diesel::*;
use serde::{Deserialize, Serialize};
}
}
-lazy_static! {
- static ref PG_POOL: Pool<ConnectionManager<PgConnection>> = {
- let db_url = Settings::get().get_database_url();
- let manager = ConnectionManager::<PgConnection>::new(&db_url);
- Pool::builder()
- .max_size(Settings::get().database.pool_size)
- .build(manager)
- .unwrap_or_else(|_| panic!("Error connecting to {}", db_url))
- };
-}
-
-pub fn establish_connection() -> PooledConnection<ConnectionManager<PgConnection>> {
- PG_POOL.get().unwrap()
+pub fn establish_unpooled_connection() -> PgConnection {
+ let db_url = Settings::get().get_database_url();
+ PgConnection::establish(&db_url).expect(&format!("Error connecting to {}", db_url))
}
#[derive(EnumString, ToString, Debug, Serialize, Deserialize)]
// use Crud;
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let new_mod = UserForm {
name: "the mod".into(),
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let new_user = UserForm {
name: "thommy prw".into(),
use super::*;
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let new_user = UserForm {
name: "jim".into(),
use super::*;
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let user_name = "tegan".to_string();
let community_name = "test_community_3".to_string();
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let new_user = UserForm {
name: "thommy".into(),
use super::*;
#[test]
fn test_crud() {
- let conn = establish_connection();
+ let conn = establish_unpooled_connection();
let new_user = UserForm {
name: "terrylake".into(),
extern crate diesel_migrations;
use actix_web::*;
-use lemmy_server::db::establish_connection;
+use diesel::r2d2::{ConnectionManager, Pool};
+use diesel::PgConnection;
use lemmy_server::routes::{federation, feeds, index, nodeinfo, webfinger, websocket};
use lemmy_server::settings::Settings;
use std::io;
#[actix_rt::main]
async fn main() -> io::Result<()> {
env_logger::init();
+ let settings = Settings::get();
+
+ // Set up the r2d2 connection pool
+ let manager = ConnectionManager::<PgConnection>::new(&settings.get_database_url());
+ let pool = Pool::builder()
+ .max_size(settings.database.pool_size)
+ .build(manager)
+ .unwrap_or_else(|_| panic!("Error connecting to {}", settings.get_database_url()));
// Run the migrations from code
- let conn = establish_connection();
+ let conn = pool.get().unwrap();
embedded_migrations::run(&conn).unwrap();
- let settings = Settings::get();
-
println!(
"Starting http server at {}:{}",
settings.bind, settings.port
// Create Http server with websocket support
HttpServer::new(move || {
App::new()
+ .wrap(middleware::Logger::default())
+ .data(pool.clone())
+ // The routes
.configure(federation::config)
.configure(feeds::config)
.configure(index::config)
.configure(nodeinfo::config)
.configure(webfinger::config)
.configure(websocket::config)
+ // .configure(websocket.config(pool))
+ // .configure(websocket.
+ // static files
.service(actix_files::Files::new(
"/static",
settings.front_end_dir.to_owned(),
use crate::db::site_view::SiteView;
use crate::db::user::{Claims, User_};
use crate::db::user_mention_view::{UserMentionQueryBuilder, UserMentionView};
-use crate::db::{establish_connection, ListingType, SortType};
+use crate::db::{ListingType, SortType};
use crate::Settings;
-use actix_web::body::Body;
use actix_web::{web, HttpResponse, Result};
use chrono::{DateTime, Utc};
+use diesel::r2d2::{ConnectionManager, Pool};
+use diesel::PgConnection;
use failure::Error;
use rss::{CategoryBuilder, ChannelBuilder, GuidBuilder, Item, ItemBuilder};
use serde::Deserialize;
.route("/feeds/all.xml", web::get().to(feeds::get_all_feed));
}
-async fn get_all_feed(info: web::Query<Params>) -> HttpResponse<Body> {
- let sort_type = match get_sort_type(info) {
- Ok(sort_type) => sort_type,
- Err(_) => return HttpResponse::BadRequest().finish(),
- };
-
- let feed_result = get_feed_all_data(&sort_type);
-
- match feed_result {
- Ok(rss) => HttpResponse::Ok()
+async fn get_all_feed(
+ info: web::Query<Params>,
+ db: web::Data<Pool<ConnectionManager<PgConnection>>>,
+) -> Result<HttpResponse, actix_web::Error> {
+ let res = web::block(move || {
+ let conn = db.get()?;
+
+ let sort_type = get_sort_type(info)?;
+ get_feed_all_data(&conn, &sort_type)
+ })
+ .await
+ .map(|rss| {
+ HttpResponse::Ok()
.content_type("application/rss+xml")
- .body(rss),
- Err(_) => HttpResponse::NotFound().finish(),
- }
+ .body(rss)
+ })
+ .map_err(|_| HttpResponse::InternalServerError())?;
+ Ok(res)
}
async fn get_feed(
path: web::Path<(String, String)>,
info: web::Query<Params>,
-) -> HttpResponse<Body> {
- let sort_type = match get_sort_type(info) {
- Ok(sort_type) => sort_type,
- Err(_) => return HttpResponse::BadRequest().finish(),
- };
-
- let request_type = match path.0.as_ref() {
- "u" => RequestType::User,
- "c" => RequestType::Community,
- "front" => RequestType::Front,
- "inbox" => RequestType::Inbox,
- _ => return HttpResponse::NotFound().finish(),
- };
-
- let param = path.1.to_owned();
-
- let feed_result = match request_type {
- RequestType::User => get_feed_user(&sort_type, param),
- RequestType::Community => get_feed_community(&sort_type, param),
- RequestType::Front => get_feed_front(&sort_type, param),
- RequestType::Inbox => get_feed_inbox(param),
- };
-
- match feed_result {
- Ok(rss) => HttpResponse::Ok()
+ db: web::Data<Pool<ConnectionManager<PgConnection>>>,
+) -> Result<HttpResponse, actix_web::Error> {
+ let res = web::block(move || {
+ let conn = db.get()?;
+
+ let sort_type = get_sort_type(info)?;
+
+ let request_type = match path.0.as_ref() {
+ "u" => RequestType::User,
+ "c" => RequestType::Community,
+ "front" => RequestType::Front,
+ "inbox" => RequestType::Inbox,
+ _ => return Err(format_err!("wrong_type")),
+ };
+
+ let param = path.1.to_owned();
+
+ match request_type {
+ RequestType::User => get_feed_user(&conn, &sort_type, param),
+ RequestType::Community => get_feed_community(&conn, &sort_type, param),
+ RequestType::Front => get_feed_front(&conn, &sort_type, param),
+ RequestType::Inbox => get_feed_inbox(&conn, param),
+ }
+ })
+ .await
+ .map(|rss| {
+ HttpResponse::Ok()
.content_type("application/rss+xml")
- .body(rss),
- Err(_) => HttpResponse::NotFound().finish(),
- }
+ .body(rss)
+ })
+ .map_err(|_| HttpResponse::InternalServerError())?;
+ Ok(res)
}
fn get_sort_type(info: web::Query<Params>) -> Result<SortType, ParseError> {
SortType::from_str(&sort_query)
}
-fn get_feed_all_data(sort_type: &SortType) -> Result<String, Error> {
- let conn = establish_connection();
-
+fn get_feed_all_data(conn: &PgConnection, sort_type: &SortType) -> Result<String, failure::Error> {
let site_view = SiteView::read(&conn)?;
let posts = PostQueryBuilder::create(&conn)
Ok(channel_builder.build().unwrap().to_string())
}
-fn get_feed_user(sort_type: &SortType, user_name: String) -> Result<String, Error> {
- let conn = establish_connection();
-
+fn get_feed_user(
+ conn: &PgConnection,
+ sort_type: &SortType,
+ user_name: String,
+) -> Result<String, Error> {
let site_view = SiteView::read(&conn)?;
let user = User_::find_by_username(&conn, &user_name)?;
let user_url = user.get_profile_url();
Ok(channel_builder.build().unwrap().to_string())
}
-fn get_feed_community(sort_type: &SortType, community_name: String) -> Result<String, Error> {
- let conn = establish_connection();
-
+fn get_feed_community(
+ conn: &PgConnection,
+ sort_type: &SortType,
+ community_name: String,
+) -> Result<String, Error> {
let site_view = SiteView::read(&conn)?;
let community = Community::read_from_name(&conn, community_name)?;
let community_url = community.get_url();
Ok(channel_builder.build().unwrap().to_string())
}
-fn get_feed_front(sort_type: &SortType, jwt: String) -> Result<String, Error> {
- let conn = establish_connection();
-
+fn get_feed_front(conn: &PgConnection, sort_type: &SortType, jwt: String) -> Result<String, Error> {
let site_view = SiteView::read(&conn)?;
let user_id = Claims::decode(&jwt)?.claims.id;
Ok(channel_builder.build().unwrap().to_string())
}
-fn get_feed_inbox(jwt: String) -> Result<String, Error> {
- let conn = establish_connection();
-
+fn get_feed_inbox(conn: &PgConnection, jwt: String) -> Result<String, Error> {
let site_view = SiteView::read(&conn)?;
let user_id = Claims::decode(&jwt)?.claims.id;
-use crate::db::establish_connection;
use crate::db::site_view::SiteView;
use crate::version;
use crate::Settings;
use actix_web::body::Body;
use actix_web::web;
use actix_web::HttpResponse;
+use diesel::r2d2::{ConnectionManager, Pool};
+use diesel::PgConnection;
use serde_json::json;
pub fn config(cfg: &mut web::ServiceConfig) {
.body(json.to_string())
}
-async fn node_info() -> HttpResponse<Body> {
- let conn = establish_connection();
- let site_view = match SiteView::read(&conn) {
- Ok(site_view) => site_view,
- Err(_e) => return HttpResponse::InternalServerError().finish(),
- };
- let protocols = if Settings::get().federation_enabled {
- vec!["activitypub"]
- } else {
- vec![]
- };
- let json = json!({
- "version": "2.0",
- "software": {
- "name": "lemmy",
- "version": version::VERSION,
- },
- "protocols": protocols,
- "usage": {
- "users": {
- "total": site_view.number_of_users
+async fn node_info(
+ db: web::Data<Pool<ConnectionManager<PgConnection>>>,
+) -> Result<HttpResponse, actix_web::Error> {
+ let res = web::block(move || {
+ let conn = db.get()?;
+ let site_view = match SiteView::read(&conn) {
+ Ok(site_view) => site_view,
+ Err(_) => return Err(format_err!("not_found")),
+ };
+ let protocols = if Settings::get().federation_enabled {
+ vec!["activitypub"]
+ } else {
+ vec![]
+ };
+ Ok(json!({
+ "version": "2.0",
+ "software": {
+ "name": "lemmy",
+ "version": version::VERSION,
},
- "localPosts": site_view.number_of_posts,
- "localComments": site_view.number_of_comments,
- "openRegistrations": site_view.open_registration,
+ "protocols": protocols,
+ "usage": {
+ "users": {
+ "total": site_view.number_of_users
+ },
+ "localPosts": site_view.number_of_posts,
+ "localComments": site_view.number_of_comments,
+ "openRegistrations": site_view.open_registration,
}
- });
- HttpResponse::Ok()
- .content_type("application/json")
- .body(json.to_string())
+ }))
+ })
+ .await
+ .map(|json| HttpResponse::Ok().json(json))
+ .map_err(|_| HttpResponse::InternalServerError())?;
+ Ok(res)
}
use crate::db::community::Community;
-use crate::db::establish_connection;
use crate::Settings;
-use actix_web::body::Body;
use actix_web::web;
use actix_web::web::Query;
use actix_web::HttpResponse;
+use diesel::r2d2::{ConnectionManager, Pool};
+use diesel::PgConnection;
use regex::Regex;
use serde::Deserialize;
use serde_json::json;
///
/// You can also view the webfinger response that Mastodon sends:
/// https://radical.town/.well-known/webfinger?resource=acct:felix@radical.town
-async fn get_webfinger_response(info: Query<Params>) -> HttpResponse<Body> {
- let regex_parsed = WEBFINGER_COMMUNITY_REGEX
- .captures(&info.resource)
- .map(|c| c.get(1));
- // TODO: replace this with .flatten() once we are running rust 1.40
- let regex_parsed_flattened = match regex_parsed {
- Some(s) => s,
- None => None,
- };
- let community_name = match regex_parsed_flattened {
- Some(c) => c.as_str(),
- None => return HttpResponse::NotFound().finish(),
- };
+async fn get_webfinger_response(
+ info: Query<Params>,
+ db: web::Data<Pool<ConnectionManager<PgConnection>>>,
+) -> Result<HttpResponse, actix_web::Error> {
+ let res = web::block(move || {
+ let conn = db.get()?;
- // Make sure the requested community exists.
- let conn = establish_connection();
- let community = match Community::read_from_name(&conn, community_name.to_string()) {
- Ok(o) => o,
- Err(_) => return HttpResponse::NotFound().finish(),
- };
+ let regex_parsed = WEBFINGER_COMMUNITY_REGEX
+ .captures(&info.resource)
+ .map(|c| c.get(1));
+ // TODO: replace this with .flatten() once we are running rust 1.40
+ let regex_parsed_flattened = match regex_parsed {
+ Some(s) => s,
+ None => None,
+ };
+ let community_name = match regex_parsed_flattened {
+ Some(c) => c.as_str(),
+ None => return Err(format_err!("not_found")),
+ };
- let community_url = community.get_url();
+ // Make sure the requested community exists.
+ let community = match Community::read_from_name(&conn, community_name.to_string()) {
+ Ok(o) => o,
+ Err(_) => return Err(format_err!("not_found")),
+ };
- let json = json!({
+ let community_url = community.get_url();
+
+ Ok(json!({
"subject": info.resource,
"aliases": [
community_url,
],
"links": [
- {
- "rel": "http://webfinger.net/rel/profile-page",
- "type": "text/html",
- "href": community_url
- },
- {
- "rel": "self",
- "type": "application/activity+json",
- // Yes this is correct, this link doesn't include the `.json` extension
- "href": community_url
- }
- // TODO: this also needs to return the subscribe link once that's implemented
- //{
- // "rel": "http://ostatus.org/schema/1.0/subscribe",
- // "template": "https://my_instance.com/authorize_interaction?uri={uri}"
- //}
+ {
+ "rel": "http://webfinger.net/rel/profile-page",
+ "type": "text/html",
+ "href": community_url
+ },
+ {
+ "rel": "self",
+ "type": "application/activity+json",
+ // Yes this is correct, this link doesn't include the `.json` extension
+ "href": community_url
+ }
+ // TODO: this also needs to return the subscribe link once that's implemented
+ //{
+ // "rel": "http://ostatus.org/schema/1.0/subscribe",
+ // "template": "https://my_instance.com/authorize_interaction?uri={uri}"
+ //}
]
- });
- HttpResponse::Ok()
- .content_type("application/activity+json")
- .body(json.to_string())
+ }))
+ })
+ .await
+ .map(|json| HttpResponse::Ok().json(json))
+ .map_err(|_| HttpResponse::InternalServerError())?;
+ Ok(res)
}
use crate::websocket::server::*;
+use crate::Settings;
use actix::prelude::*;
use actix_web::web;
use actix_web::*;
use actix_web_actors::ws;
+use diesel::r2d2::{ConnectionManager, Pool};
+use diesel::PgConnection;
use std::time::{Duration, Instant};
pub fn config(cfg: &mut web::ServiceConfig) {
+ // TODO couldn't figure out how to get this method to recieve the other pool
+ let settings = Settings::get();
+ let manager = ConnectionManager::<PgConnection>::new(&settings.get_database_url());
+ let pool = Pool::builder()
+ .max_size(settings.database.pool_size)
+ .build(manager)
+ .unwrap_or_else(|_| panic!("Error connecting to {}", settings.get_database_url()));
+
// Start chat server actor in separate thread
- let server = ChatServer::default().start();
+ let server = ChatServer::startup(pool).start();
cfg
.data(server)
.service(web::resource("/api/v1/ws").to(chat_route));
stream: web::Payload,
chat_server: web::Data<Addr<ChatServer>>,
) -> Result<HttpResponse, Error> {
+ // TODO not sure if the blocking should be here or not
ws::start(
WSSession {
- cs_addr: chat_server.get_ref().to_owned(),
+ // db: db.get_ref().clone(),
+ cs_addr: chat_server.get_ref().clone(),
id: 0,
hb: Instant::now(),
ip: req
/// Client must send ping at least once per 10 seconds (CLIENT_TIMEOUT),
/// otherwise we drop connection.
hb: Instant,
+ // db: Pool<ConnectionManager<PgConnection>>,
}
impl Actor for WSSession {
}
ws::Message::Text(text) => {
let m = text.trim().to_owned();
- println!("WEBSOCKET MESSAGE: {:?} from id: {}", &m, self.id);
+ // println!("WEBSOCKET MESSAGE: {:?} from id: {}", &m, self.id);
self
.cs_addr
//! room through `ChatServer`.
use actix::prelude::*;
+use diesel::r2d2::{ConnectionManager, Pool};
+use diesel::PgConnection;
use failure::Error;
use rand::{rngs::ThreadRng, Rng};
use serde::{Deserialize, Serialize};
pub ip: String,
}
+// TODO this is unused rn
/// Send message to specific room
#[derive(Message)]
#[rtype(result = "()")]
rate_limits: HashMap<String, RateLimitBucket>,
rooms: HashMap<i32, HashSet<usize>>, // A map from room / post name to set of connectionIDs
rng: ThreadRng,
+ db: Pool<ConnectionManager<PgConnection>>,
}
-impl Default for ChatServer {
- fn default() -> ChatServer {
+// impl Default for ChatServer {
+// fn default(nah: String) -> ChatServer {
+// // default room
+// let rooms = HashMap::new();
+
+// ChatServer {
+// sessions: HashMap::new(),
+// rate_limits: HashMap::new(),
+// rooms,
+// rng: rand::thread_rng(),
+// nah: nah,
+// }
+// }
+// }
+
+impl ChatServer {
+ pub fn startup(db: Pool<ConnectionManager<PgConnection>>) -> ChatServer {
// default room
let rooms = HashMap::new();
rate_limits: HashMap::new(),
rooms,
rng: rand::thread_rng(),
+ db,
}
}
-}
-impl ChatServer {
/// Send message to all users in the room
fn send_room_message(&self, room: i32, message: &str, skip_id: usize) {
if let Some(sessions) = self.rooms.get(&room) {
) -> Result<(), Error> {
use crate::db::post_view::*;
use crate::db::*;
- let conn = establish_connection();
+
+ let conn = self.db.get()?;
let posts = PostQueryBuilder::create(&conn)
.listing_type(ListingType::Community)
message: "Unknown op type".to_string(),
})?;
+ let conn = chat.db.get()?;
+
let user_operation: UserOperation = UserOperation::from_str(&op)?;
match user_operation {
UserOperation::Login => {
let login: Login = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, login).perform()?;
+ let res = Oper::new(user_operation, login).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::Register => {
let register: Register = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, register).perform();
+ let res = Oper::new(user_operation, register).perform(&conn);
if res.is_ok() {
chat.check_rate_limit_register(msg.id)?;
}
}
UserOperation::GetUserDetails => {
let get_user_details: GetUserDetails = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, get_user_details).perform()?;
+ let res = Oper::new(user_operation, get_user_details).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::SaveUserSettings => {
let save_user_settings: SaveUserSettings = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, save_user_settings).perform()?;
+ let res = Oper::new(user_operation, save_user_settings).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::AddAdmin => {
let add_admin: AddAdmin = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, add_admin).perform()?;
+ let res = Oper::new(user_operation, add_admin).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::BanUser => {
let ban_user: BanUser = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, ban_user).perform()?;
+ let res = Oper::new(user_operation, ban_user).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::GetReplies => {
let get_replies: GetReplies = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, get_replies).perform()?;
+ let res = Oper::new(user_operation, get_replies).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::GetUserMentions => {
let get_user_mentions: GetUserMentions = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, get_user_mentions).perform()?;
+ let res = Oper::new(user_operation, get_user_mentions).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::EditUserMention => {
let edit_user_mention: EditUserMention = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, edit_user_mention).perform()?;
+ let res = Oper::new(user_operation, edit_user_mention).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::MarkAllAsRead => {
let mark_all_as_read: MarkAllAsRead = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, mark_all_as_read).perform()?;
+ let res = Oper::new(user_operation, mark_all_as_read).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::GetCommunity => {
let get_community: GetCommunity = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, get_community).perform()?;
+ let res = Oper::new(user_operation, get_community).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::ListCommunities => {
let list_communities: ListCommunities = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, list_communities).perform()?;
+ let res = Oper::new(user_operation, list_communities).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::CreateCommunity => {
chat.check_rate_limit_register(msg.id)?;
let create_community: CreateCommunity = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, create_community).perform()?;
+ let res = Oper::new(user_operation, create_community).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::EditCommunity => {
let edit_community: EditCommunity = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, edit_community).perform()?;
+ let res = Oper::new(user_operation, edit_community).perform(&conn)?;
let mut community_sent: CommunityResponse = res.clone();
community_sent.community.user_id = None;
community_sent.community.subscribed = None;
}
UserOperation::FollowCommunity => {
let follow_community: FollowCommunity = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, follow_community).perform()?;
+ let res = Oper::new(user_operation, follow_community).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::GetFollowedCommunities => {
let followed_communities: GetFollowedCommunities = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, followed_communities).perform()?;
+ let res = Oper::new(user_operation, followed_communities).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::BanFromCommunity => {
let ban_from_community: BanFromCommunity = serde_json::from_str(data)?;
let community_id = ban_from_community.community_id;
- let res = Oper::new(user_operation, ban_from_community).perform()?;
+ let res = Oper::new(user_operation, ban_from_community).perform(&conn)?;
let res_str = serde_json::to_string(&res)?;
chat.send_community_message(community_id, &res_str, msg.id)?;
Ok(res_str)
UserOperation::AddModToCommunity => {
let mod_add_to_community: AddModToCommunity = serde_json::from_str(data)?;
let community_id = mod_add_to_community.community_id;
- let res = Oper::new(user_operation, mod_add_to_community).perform()?;
+ let res = Oper::new(user_operation, mod_add_to_community).perform(&conn)?;
let res_str = serde_json::to_string(&res)?;
chat.send_community_message(community_id, &res_str, msg.id)?;
Ok(res_str)
}
UserOperation::ListCategories => {
let list_categories: ListCategories = ListCategories;
- let res = Oper::new(user_operation, list_categories).perform()?;
+ let res = Oper::new(user_operation, list_categories).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::CreatePost => {
chat.check_rate_limit_post(msg.id)?;
let create_post: CreatePost = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, create_post).perform()?;
+ let res = Oper::new(user_operation, create_post).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::GetPost => {
let get_post: GetPost = serde_json::from_str(data)?;
chat.join_room(get_post.id, msg.id);
- let res = Oper::new(user_operation, get_post).perform()?;
+ let res = Oper::new(user_operation, get_post).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::GetPosts => {
let get_posts: GetPosts = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, get_posts).perform()?;
+ let res = Oper::new(user_operation, get_posts).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::CreatePostLike => {
chat.check_rate_limit_message(msg.id)?;
let create_post_like: CreatePostLike = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, create_post_like).perform()?;
+ let res = Oper::new(user_operation, create_post_like).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::EditPost => {
let edit_post: EditPost = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, edit_post).perform()?;
+ let res = Oper::new(user_operation, edit_post).perform(&conn)?;
let mut post_sent = res.clone();
post_sent.post.my_vote = None;
let post_sent_str = serde_json::to_string(&post_sent)?;
}
UserOperation::SavePost => {
let save_post: SavePost = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, save_post).perform()?;
+ let res = Oper::new(user_operation, save_post).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::CreateComment => {
chat.check_rate_limit_message(msg.id)?;
let create_comment: CreateComment = serde_json::from_str(data)?;
let post_id = create_comment.post_id;
- let res = Oper::new(user_operation, create_comment).perform()?;
+ let res = Oper::new(user_operation, create_comment).perform(&conn)?;
let mut comment_sent = res.clone();
comment_sent.comment.my_vote = None;
comment_sent.comment.user_id = None;
UserOperation::EditComment => {
let edit_comment: EditComment = serde_json::from_str(data)?;
let post_id = edit_comment.post_id;
- let res = Oper::new(user_operation, edit_comment).perform()?;
+ let res = Oper::new(user_operation, edit_comment).perform(&conn)?;
let mut comment_sent = res.clone();
comment_sent.comment.my_vote = None;
comment_sent.comment.user_id = None;
}
UserOperation::SaveComment => {
let save_comment: SaveComment = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, save_comment).perform()?;
+ let res = Oper::new(user_operation, save_comment).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::CreateCommentLike => {
chat.check_rate_limit_message(msg.id)?;
let create_comment_like: CreateCommentLike = serde_json::from_str(data)?;
let post_id = create_comment_like.post_id;
- let res = Oper::new(user_operation, create_comment_like).perform()?;
+ let res = Oper::new(user_operation, create_comment_like).perform(&conn)?;
let mut comment_sent = res.clone();
comment_sent.comment.my_vote = None;
comment_sent.comment.user_id = None;
}
UserOperation::GetModlog => {
let get_modlog: GetModlog = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, get_modlog).perform()?;
+ let res = Oper::new(user_operation, get_modlog).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::CreateSite => {
let create_site: CreateSite = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, create_site).perform()?;
+ let res = Oper::new(user_operation, create_site).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::EditSite => {
let edit_site: EditSite = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, edit_site).perform()?;
+ let res = Oper::new(user_operation, edit_site).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::GetSite => {
let online: usize = chat.sessions.len();
let get_site: GetSite = serde_json::from_str(data)?;
- let mut res = Oper::new(user_operation, get_site).perform()?;
+ let mut res = Oper::new(user_operation, get_site).perform(&conn)?;
res.online = online;
Ok(serde_json::to_string(&res)?)
}
UserOperation::Search => {
let search: Search = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, search).perform()?;
+ let res = Oper::new(user_operation, search).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::TransferCommunity => {
let transfer_community: TransferCommunity = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, transfer_community).perform()?;
+ let res = Oper::new(user_operation, transfer_community).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::TransferSite => {
let transfer_site: TransferSite = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, transfer_site).perform()?;
+ let res = Oper::new(user_operation, transfer_site).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::DeleteAccount => {
let delete_account: DeleteAccount = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, delete_account).perform()?;
+ let res = Oper::new(user_operation, delete_account).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::PasswordReset => {
let password_reset: PasswordReset = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, password_reset).perform()?;
+ let res = Oper::new(user_operation, password_reset).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
UserOperation::PasswordChange => {
let password_change: PasswordChange = serde_json::from_str(data)?;
- let res = Oper::new(user_operation, password_change).perform()?;
+ let res = Oper::new(user_operation, password_change).perform(&conn)?;
Ok(serde_json::to_string(&res)?)
}
}