2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::category::*;
|
2019-06-03 17:47:12 +00:00
|
|
|
use crate::db::comment::*;
|
|
|
|
use crate::db::comment_view::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::community::*;
|
2019-06-03 17:47:12 +00:00
|
|
|
use crate::db::community_view::*;
|
|
|
|
use crate::db::moderator::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::moderator_views::*;
|
2019-11-02 06:43:21 +00:00
|
|
|
use crate::db::password_reset_request::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::post::*;
|
|
|
|
use crate::db::post_view::*;
|
2020-01-22 21:35:29 +00:00
|
|
|
use crate::db::private_message::*;
|
|
|
|
use crate::db::private_message_view::*;
|
2019-12-11 20:21:47 +00:00
|
|
|
use crate::db::site::*;
|
|
|
|
use crate::db::site_view::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::user::*;
|
2019-10-20 00:46:29 +00:00
|
|
|
use crate::db::user_mention::*;
|
|
|
|
use crate::db::user_mention_view::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
use crate::db::user_view::*;
|
|
|
|
use crate::db::*;
|
2020-02-03 03:51:54 +00:00
|
|
|
use crate::{
|
2020-04-19 22:08:25 +00:00
|
|
|
extract_usernames, fetch_iframely_and_pictshare_data, generate_random_string, naive_from_unix,
|
|
|
|
naive_now, remove_slurs, send_email, slur_check, slurs_vec_to_str,
|
2020-02-03 03:51:54 +00:00
|
|
|
};
|
2020-04-19 22:08:25 +00:00
|
|
|
|
2020-04-21 14:25:29 +00:00
|
|
|
use crate::apub::{
|
2020-04-26 17:20:42 +00:00
|
|
|
activities::{send_post_create, send_post_update},
|
2020-04-21 14:25:29 +00:00
|
|
|
fetcher::search_by_apub_id,
|
|
|
|
signatures::generate_actor_keypair,
|
2020-04-26 17:20:42 +00:00
|
|
|
{make_apub_endpoint, ActorType, EndpointType},
|
2020-04-21 14:25:29 +00:00
|
|
|
};
|
2020-04-19 22:08:25 +00:00
|
|
|
use crate::settings::Settings;
|
|
|
|
use crate::websocket::UserOperation;
|
|
|
|
use crate::websocket::{
|
|
|
|
server::{
|
|
|
|
JoinCommunityRoom, JoinPostRoom, JoinUserRoom, SendAllMessage, SendComment,
|
|
|
|
SendCommunityRoomMessage, SendPost, SendUserRoomMessage,
|
|
|
|
},
|
|
|
|
WebsocketInfo,
|
|
|
|
};
|
|
|
|
use diesel::r2d2::{ConnectionManager, Pool};
|
2020-01-12 15:31:51 +00:00
|
|
|
use diesel::PgConnection;
|
2019-09-07 15:35:05 +00:00
|
|
|
use failure::Error;
|
2020-04-21 14:25:29 +00:00
|
|
|
use log::{debug, error, info};
|
2019-09-07 15:35:05 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-04-19 22:08:25 +00:00
|
|
|
use std::str::FromStr;
|
2019-05-05 05:20:38 +00:00
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
pub mod comment;
|
2019-05-05 05:20:38 +00:00
|
|
|
pub mod community;
|
|
|
|
pub mod post;
|
|
|
|
pub mod site;
|
2019-09-07 15:35:05 +00:00
|
|
|
pub mod user;
|
2019-05-05 05:20:38 +00:00
|
|
|
|
|
|
|
#[derive(Fail, Debug)]
|
2020-01-16 14:39:08 +00:00
|
|
|
#[fail(display = "{{\"error\":\"{}\"}}", message)]
|
2019-05-05 05:20:38 +00:00
|
|
|
pub struct APIError {
|
2019-05-05 16:20:30 +00:00
|
|
|
pub message: String,
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl APIError {
|
2020-01-16 14:39:08 +00:00
|
|
|
pub fn err(msg: &str) -> Self {
|
2019-05-05 05:20:38 +00:00
|
|
|
APIError {
|
|
|
|
message: msg.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Oper<T> {
|
2019-09-07 15:35:05 +00:00
|
|
|
data: T,
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 14:04:36 +00:00
|
|
|
impl<Data> Oper<Data> {
|
|
|
|
pub fn new(data: Data) -> Oper<Data> {
|
2020-01-16 14:39:08 +00:00
|
|
|
Oper { data }
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 03:59:07 +00:00
|
|
|
pub trait Perform {
|
2020-04-21 20:40:03 +00:00
|
|
|
type Response: serde::ser::Serialize + Send;
|
2020-04-20 03:59:07 +00:00
|
|
|
|
2020-04-19 22:08:25 +00:00
|
|
|
fn perform(
|
|
|
|
&self,
|
|
|
|
pool: Pool<ConnectionManager<PgConnection>>,
|
|
|
|
websocket_info: Option<WebsocketInfo>,
|
2020-04-20 03:59:07 +00:00
|
|
|
) -> Result<Self::Response, Error>;
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|