mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-12 15:34:00 +00:00
Merge branch 'structs_separate' into main
This commit is contained in:
commit
17df0ee6b3
57 changed files with 940 additions and 845 deletions
10
docker/dev/Dockerfile
vendored
10
docker/dev/Dockerfile
vendored
|
@ -20,12 +20,18 @@ RUN USER=root cargo new server
|
||||||
# Install cargo-build-deps
|
# Install cargo-build-deps
|
||||||
RUN cargo install --git https://github.com/romac/cargo-build-deps.git
|
RUN cargo install --git https://github.com/romac/cargo-build-deps.git
|
||||||
WORKDIR /app/server
|
WORKDIR /app/server
|
||||||
RUN mkdir -p lemmy_db/src/ lemmy_utils/src/
|
RUN mkdir -p lemmy_db/src/ \
|
||||||
|
lemmy_utils/src/ \
|
||||||
|
lemmy_api_structs/src/ \
|
||||||
|
lemmy_rate_limit/src/ \
|
||||||
|
lemmy
|
||||||
|
|
||||||
# Copy the cargo tomls
|
# Copy the cargo tomls
|
||||||
COPY server/Cargo.toml server/Cargo.lock ./
|
COPY server/Cargo.toml server/Cargo.lock ./
|
||||||
COPY server/lemmy_db/Cargo.toml ./lemmy_db/
|
COPY server/lemmy_db/Cargo.toml ./lemmy_db/
|
||||||
COPY server/lemmy_utils/Cargo.toml ./lemmy_utils/
|
COPY server/lemmy_utils/Cargo.toml ./lemmy_utils/
|
||||||
|
COPY server/lemmy_api_structs/Cargo.toml ./lemmy_api_structs/
|
||||||
|
COPY server/lemmy_rate_limit/Cargo.toml ./lemmy_rate_limit/
|
||||||
|
|
||||||
# Cache the deps
|
# Cache the deps
|
||||||
RUN cargo build-deps
|
RUN cargo build-deps
|
||||||
|
@ -34,6 +40,8 @@ RUN cargo build-deps
|
||||||
COPY server/src ./src/
|
COPY server/src ./src/
|
||||||
COPY server/lemmy_db/src ./lemmy_db/src/
|
COPY server/lemmy_db/src ./lemmy_db/src/
|
||||||
COPY server/lemmy_utils/src/ ./lemmy_utils/src/
|
COPY server/lemmy_utils/src/ ./lemmy_utils/src/
|
||||||
|
COPY server/lemmy_api_structs/src/ ./lemmy_api_structs/src/
|
||||||
|
COPY server/lemmy_rate_limit/src/ ./lemmy_rate_limit/src/
|
||||||
COPY server/migrations ./migrations/
|
COPY server/migrations ./migrations/
|
||||||
|
|
||||||
# Build for debug
|
# Build for debug
|
||||||
|
|
2
docker/prod/Dockerfile
vendored
2
docker/prod/Dockerfile
vendored
|
@ -13,6 +13,8 @@ WORKDIR /app/server
|
||||||
COPY server/Cargo.toml server/Cargo.lock ./
|
COPY server/Cargo.toml server/Cargo.lock ./
|
||||||
COPY server/lemmy_db ./lemmy_db
|
COPY server/lemmy_db ./lemmy_db
|
||||||
COPY server/lemmy_utils ./lemmy_utils
|
COPY server/lemmy_utils ./lemmy_utils
|
||||||
|
COPY server/lemmy_api_structs ./lemmy_api_structs
|
||||||
|
COPY server/lemmy_rate_limit ./lemmy_rate_limit
|
||||||
RUN mkdir -p ./src/bin \
|
RUN mkdir -p ./src/bin \
|
||||||
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
|
|
27
server/Cargo.lock
generated
vendored
27
server/Cargo.lock
generated
vendored
|
@ -1794,6 +1794,15 @@ version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lemmy_api_structs"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"lemmy_db",
|
||||||
|
"serde 1.0.114",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_db"
|
name = "lemmy_db"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -1812,6 +1821,20 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lemmy_rate_limit"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"actix-web",
|
||||||
|
"futures",
|
||||||
|
"lemmy_api_structs",
|
||||||
|
"lemmy_utils",
|
||||||
|
"log",
|
||||||
|
"strum",
|
||||||
|
"strum_macros",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_server"
|
name = "lemmy_server"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
@ -1841,7 +1864,9 @@ dependencies = [
|
||||||
"itertools",
|
"itertools",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"lemmy_api_structs",
|
||||||
"lemmy_db",
|
"lemmy_db",
|
||||||
|
"lemmy_rate_limit",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"log",
|
"log",
|
||||||
"openssl",
|
"openssl",
|
||||||
|
@ -1864,6 +1889,8 @@ dependencies = [
|
||||||
name = "lemmy_utils"
|
name = "lemmy_utils"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"actix-web",
|
||||||
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
"comrak",
|
"comrak",
|
||||||
"config",
|
"config",
|
||||||
|
|
6
server/Cargo.toml
vendored
6
server/Cargo.toml
vendored
|
@ -9,12 +9,16 @@ lto = true
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"lemmy_db"
|
"lemmy_db",
|
||||||
|
"lemmy_api_structs",
|
||||||
|
"lemmy_rate_limit",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_utils = { path = "./lemmy_utils" }
|
lemmy_utils = { path = "./lemmy_utils" }
|
||||||
lemmy_db = { path = "./lemmy_db" }
|
lemmy_db = { path = "./lemmy_db" }
|
||||||
|
lemmy_api_structs = { path = "./lemmy_api_structs" }
|
||||||
|
lemmy_rate_limit = { path = "./lemmy_rate_limit" }
|
||||||
diesel = "1.4.4"
|
diesel = "1.4.4"
|
||||||
diesel_migrations = "1.4.0"
|
diesel_migrations = "1.4.0"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
|
|
14
server/lemmy_api_structs/Cargo.toml
vendored
Normal file
14
server/lemmy_api_structs/Cargo.toml
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
[package]
|
||||||
|
name = "lemmy_api_structs"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Felix Ableitner <me@nutomic.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "lemmy_api_structs"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
lemmy_db = { path = "../lemmy_db" }
|
||||||
|
serde = { version = "1.0.105", features = ["derive"] }
|
||||||
|
thiserror = "1.0.20"
|
77
server/lemmy_api_structs/src/comment.rs
Normal file
77
server/lemmy_api_structs/src/comment.rs
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
use lemmy_db::comment_view::CommentView;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct CreateComment {
|
||||||
|
pub content: String,
|
||||||
|
pub parent_id: Option<i32>,
|
||||||
|
pub post_id: i32,
|
||||||
|
pub form_id: Option<String>,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct EditComment {
|
||||||
|
pub content: String,
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub form_id: Option<String>,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct DeleteComment {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct RemoveComment {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub removed: bool,
|
||||||
|
pub reason: Option<String>,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct MarkCommentAsRead {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub read: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct SaveComment {
|
||||||
|
pub comment_id: i32,
|
||||||
|
pub save: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct CommentResponse {
|
||||||
|
pub comment: CommentView,
|
||||||
|
pub recipient_ids: Vec<i32>,
|
||||||
|
pub form_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct CreateCommentLike {
|
||||||
|
pub comment_id: i32,
|
||||||
|
pub score: i16,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetComments {
|
||||||
|
pub type_: String,
|
||||||
|
pub sort: String,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
pub community_id: Option<i32>,
|
||||||
|
pub auth: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetCommentsResponse {
|
||||||
|
pub comments: Vec<CommentView>,
|
||||||
|
}
|
131
server/lemmy_api_structs/src/community.rs
Normal file
131
server/lemmy_api_structs/src/community.rs
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
use lemmy_db::{
|
||||||
|
community_view::{CommunityFollowerView, CommunityModeratorView, CommunityView},
|
||||||
|
user_view::UserView,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetCommunity {
|
||||||
|
pub id: Option<i32>,
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub auth: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetCommunityResponse {
|
||||||
|
pub community: CommunityView,
|
||||||
|
pub moderators: Vec<CommunityModeratorView>,
|
||||||
|
pub online: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct CreateCommunity {
|
||||||
|
pub name: String,
|
||||||
|
pub title: String,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub icon: Option<String>,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub category_id: i32,
|
||||||
|
pub nsfw: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct CommunityResponse {
|
||||||
|
pub community: CommunityView,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ListCommunities {
|
||||||
|
pub sort: String,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
pub auth: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ListCommunitiesResponse {
|
||||||
|
pub communities: Vec<CommunityView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct BanFromCommunity {
|
||||||
|
pub community_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub ban: bool,
|
||||||
|
pub remove_data: Option<bool>,
|
||||||
|
pub reason: Option<String>,
|
||||||
|
pub expires: Option<i64>,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct BanFromCommunityResponse {
|
||||||
|
pub user: UserView,
|
||||||
|
pub banned: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct AddModToCommunity {
|
||||||
|
pub community_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub added: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct AddModToCommunityResponse {
|
||||||
|
pub moderators: Vec<CommunityModeratorView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct EditCommunity {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub title: String,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub icon: Option<String>,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub category_id: i32,
|
||||||
|
pub nsfw: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct DeleteCommunity {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct RemoveCommunity {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub removed: bool,
|
||||||
|
pub reason: Option<String>,
|
||||||
|
pub expires: Option<i64>,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct FollowCommunity {
|
||||||
|
pub community_id: i32,
|
||||||
|
pub follow: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetFollowedCommunities {
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetFollowedCommunitiesResponse {
|
||||||
|
pub communities: Vec<CommunityFollowerView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct TransferCommunity {
|
||||||
|
pub community_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
24
server/lemmy_api_structs/src/lib.rs
Normal file
24
server/lemmy_api_structs/src/lib.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
pub extern crate serde;
|
||||||
|
pub extern crate thiserror;
|
||||||
|
|
||||||
|
pub mod comment;
|
||||||
|
pub mod community;
|
||||||
|
pub mod post;
|
||||||
|
pub mod site;
|
||||||
|
pub mod user;
|
||||||
|
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
#[error("{{\"error\":\"{message}\"}}")]
|
||||||
|
pub struct APIError {
|
||||||
|
pub message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl APIError {
|
||||||
|
pub fn err(msg: &str) -> Self {
|
||||||
|
APIError {
|
||||||
|
message: msg.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
105
server/lemmy_api_structs/src/post.rs
Normal file
105
server/lemmy_api_structs/src/post.rs
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
use lemmy_db::{
|
||||||
|
comment_view::CommentView,
|
||||||
|
community_view::{CommunityModeratorView, CommunityView},
|
||||||
|
post_view::PostView,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct CreatePost {
|
||||||
|
pub name: String,
|
||||||
|
pub url: Option<String>,
|
||||||
|
pub body: Option<String>,
|
||||||
|
pub nsfw: bool,
|
||||||
|
pub community_id: i32,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PostResponse {
|
||||||
|
pub post: PostView,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetPost {
|
||||||
|
pub id: i32,
|
||||||
|
pub auth: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetPostResponse {
|
||||||
|
pub post: PostView,
|
||||||
|
pub comments: Vec<CommentView>,
|
||||||
|
pub community: CommunityView,
|
||||||
|
pub moderators: Vec<CommunityModeratorView>,
|
||||||
|
pub online: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct GetPosts {
|
||||||
|
pub type_: String,
|
||||||
|
pub sort: String,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
pub community_id: Option<i32>,
|
||||||
|
pub community_name: Option<String>,
|
||||||
|
pub auth: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct GetPostsResponse {
|
||||||
|
pub posts: Vec<PostView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct CreatePostLike {
|
||||||
|
pub post_id: i32,
|
||||||
|
pub score: i16,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct EditPost {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub name: String,
|
||||||
|
pub url: Option<String>,
|
||||||
|
pub body: Option<String>,
|
||||||
|
pub nsfw: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct DeletePost {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct RemovePost {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub removed: bool,
|
||||||
|
pub reason: Option<String>,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct LockPost {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub locked: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct StickyPost {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub stickied: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct SavePost {
|
||||||
|
pub post_id: i32,
|
||||||
|
pub save: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
127
server/lemmy_api_structs/src/site.rs
Normal file
127
server/lemmy_api_structs/src/site.rs
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
use lemmy_db::{
|
||||||
|
category::*,
|
||||||
|
comment_view::*,
|
||||||
|
community_view::*,
|
||||||
|
moderator_views::*,
|
||||||
|
post_view::*,
|
||||||
|
site_view::*,
|
||||||
|
user::*,
|
||||||
|
user_view::*,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct ListCategories {}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct ListCategoriesResponse {
|
||||||
|
pub categories: Vec<Category>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct Search {
|
||||||
|
pub q: String,
|
||||||
|
pub type_: String,
|
||||||
|
pub community_id: Option<i32>,
|
||||||
|
pub sort: String,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
pub auth: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct SearchResponse {
|
||||||
|
pub type_: String,
|
||||||
|
pub comments: Vec<CommentView>,
|
||||||
|
pub posts: Vec<PostView>,
|
||||||
|
pub communities: Vec<CommunityView>,
|
||||||
|
pub users: Vec<UserView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetModlog {
|
||||||
|
pub mod_user_id: Option<i32>,
|
||||||
|
pub community_id: Option<i32>,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetModlogResponse {
|
||||||
|
pub removed_posts: Vec<ModRemovePostView>,
|
||||||
|
pub locked_posts: Vec<ModLockPostView>,
|
||||||
|
pub stickied_posts: Vec<ModStickyPostView>,
|
||||||
|
pub removed_comments: Vec<ModRemoveCommentView>,
|
||||||
|
pub removed_communities: Vec<ModRemoveCommunityView>,
|
||||||
|
pub banned_from_community: Vec<ModBanFromCommunityView>,
|
||||||
|
pub banned: Vec<ModBanView>,
|
||||||
|
pub added_to_community: Vec<ModAddCommunityView>,
|
||||||
|
pub added: Vec<ModAddView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct CreateSite {
|
||||||
|
pub name: String,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub icon: Option<String>,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub enable_downvotes: bool,
|
||||||
|
pub open_registration: bool,
|
||||||
|
pub enable_nsfw: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct EditSite {
|
||||||
|
pub name: String,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub icon: Option<String>,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub enable_downvotes: bool,
|
||||||
|
pub open_registration: bool,
|
||||||
|
pub enable_nsfw: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetSite {
|
||||||
|
pub auth: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct SiteResponse {
|
||||||
|
pub site: SiteView,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetSiteResponse {
|
||||||
|
pub site: Option<SiteView>,
|
||||||
|
pub admins: Vec<UserView>,
|
||||||
|
pub banned: Vec<UserView>,
|
||||||
|
pub online: usize,
|
||||||
|
pub version: String,
|
||||||
|
pub my_user: Option<User_>,
|
||||||
|
pub federated_instances: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct TransferSite {
|
||||||
|
pub user_id: i32,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetSiteConfig {
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetSiteConfigResponse {
|
||||||
|
pub config_hjson: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct SaveSiteConfig {
|
||||||
|
pub config_hjson: String,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
239
server/lemmy_api_structs/src/user.rs
Normal file
239
server/lemmy_api_structs/src/user.rs
Normal file
|
@ -0,0 +1,239 @@
|
||||||
|
use lemmy_db::{
|
||||||
|
comment_view::{CommentView, ReplyView},
|
||||||
|
community_view::{CommunityFollowerView, CommunityModeratorView},
|
||||||
|
post_view::PostView,
|
||||||
|
private_message_view::PrivateMessageView,
|
||||||
|
user_mention_view::UserMentionView,
|
||||||
|
user_view::UserView,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct Login {
|
||||||
|
pub username_or_email: String,
|
||||||
|
pub password: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct Register {
|
||||||
|
pub username: String,
|
||||||
|
pub email: Option<String>,
|
||||||
|
pub password: String,
|
||||||
|
pub password_verify: String,
|
||||||
|
pub admin: bool,
|
||||||
|
pub show_nsfw: bool,
|
||||||
|
pub captcha_uuid: Option<String>,
|
||||||
|
pub captcha_answer: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetCaptcha {}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetCaptchaResponse {
|
||||||
|
pub ok: Option<CaptchaResponse>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct CaptchaResponse {
|
||||||
|
pub png: String, // A Base64 encoded png
|
||||||
|
pub wav: Option<String>, // A Base64 encoded wav audio
|
||||||
|
pub uuid: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct SaveUserSettings {
|
||||||
|
pub show_nsfw: bool,
|
||||||
|
pub theme: String,
|
||||||
|
pub default_sort_type: i16,
|
||||||
|
pub default_listing_type: i16,
|
||||||
|
pub lang: String,
|
||||||
|
pub avatar: Option<String>,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub preferred_username: Option<String>,
|
||||||
|
pub email: Option<String>,
|
||||||
|
pub bio: Option<String>,
|
||||||
|
pub matrix_user_id: Option<String>,
|
||||||
|
pub new_password: Option<String>,
|
||||||
|
pub new_password_verify: Option<String>,
|
||||||
|
pub old_password: Option<String>,
|
||||||
|
pub show_avatars: bool,
|
||||||
|
pub send_notifications_to_email: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct LoginResponse {
|
||||||
|
pub jwt: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetUserDetails {
|
||||||
|
pub user_id: Option<i32>,
|
||||||
|
pub username: Option<String>,
|
||||||
|
pub sort: String,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
pub community_id: Option<i32>,
|
||||||
|
pub saved_only: bool,
|
||||||
|
pub auth: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetUserDetailsResponse {
|
||||||
|
pub user: UserView,
|
||||||
|
pub follows: Vec<CommunityFollowerView>,
|
||||||
|
pub moderates: Vec<CommunityModeratorView>,
|
||||||
|
pub comments: Vec<CommentView>,
|
||||||
|
pub posts: Vec<PostView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetRepliesResponse {
|
||||||
|
pub replies: Vec<ReplyView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetUserMentionsResponse {
|
||||||
|
pub mentions: Vec<UserMentionView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct MarkAllAsRead {
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct AddAdmin {
|
||||||
|
pub user_id: i32,
|
||||||
|
pub added: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct AddAdminResponse {
|
||||||
|
pub admins: Vec<UserView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct BanUser {
|
||||||
|
pub user_id: i32,
|
||||||
|
pub ban: bool,
|
||||||
|
pub remove_data: Option<bool>,
|
||||||
|
pub reason: Option<String>,
|
||||||
|
pub expires: Option<i64>,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct BanUserResponse {
|
||||||
|
pub user: UserView,
|
||||||
|
pub banned: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetReplies {
|
||||||
|
pub sort: String,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
pub unread_only: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetUserMentions {
|
||||||
|
pub sort: String,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
pub unread_only: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct MarkUserMentionAsRead {
|
||||||
|
pub user_mention_id: i32,
|
||||||
|
pub read: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct UserMentionResponse {
|
||||||
|
pub mention: UserMentionView,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct DeleteAccount {
|
||||||
|
pub password: String,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct PasswordReset {
|
||||||
|
pub email: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PasswordResetResponse {}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct PasswordChange {
|
||||||
|
pub token: String,
|
||||||
|
pub password: String,
|
||||||
|
pub password_verify: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct CreatePrivateMessage {
|
||||||
|
pub content: String,
|
||||||
|
pub recipient_id: i32,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct EditPrivateMessage {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub content: String,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct DeletePrivateMessage {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct MarkPrivateMessageAsRead {
|
||||||
|
pub edit_id: i32,
|
||||||
|
pub read: bool,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetPrivateMessages {
|
||||||
|
pub unread_only: bool,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PrivateMessagesResponse {
|
||||||
|
pub messages: Vec<PrivateMessageView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PrivateMessageResponse {
|
||||||
|
pub message: PrivateMessageView,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct UserJoin {
|
||||||
|
pub auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct UserJoinResponse {
|
||||||
|
pub user_id: i32,
|
||||||
|
}
|
19
server/lemmy_rate_limit/Cargo.toml
vendored
Normal file
19
server/lemmy_rate_limit/Cargo.toml
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[package]
|
||||||
|
name = "lemmy_rate_limit"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Felix Ableitner <me@nutomic.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "lemmy_rate_limit"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
lemmy_utils = { path = "../lemmy_utils" }
|
||||||
|
lemmy_api_structs = { path = "../lemmy_api_structs" }
|
||||||
|
tokio = "0.2.21"
|
||||||
|
strum = "0.18.0"
|
||||||
|
strum_macros = "0.18.0"
|
||||||
|
futures = "0.3.5"
|
||||||
|
actix-web = { version = "3.0.0-alpha.3", features = ["rustls"] }
|
||||||
|
log = "0.4.0"
|
|
@ -1,8 +1,17 @@
|
||||||
use super::IPAddr;
|
#[macro_use]
|
||||||
use crate::{get_ip, LemmyError};
|
pub extern crate strum_macros;
|
||||||
|
pub extern crate actix_web;
|
||||||
|
pub extern crate futures;
|
||||||
|
pub extern crate log;
|
||||||
|
pub extern crate tokio;
|
||||||
|
|
||||||
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
|
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
|
||||||
use futures::future::{ok, Ready};
|
use futures::future::{ok, Ready};
|
||||||
use lemmy_utils::settings::{RateLimitConfig, Settings};
|
use lemmy_utils::{
|
||||||
|
get_ip,
|
||||||
|
settings::{RateLimitConfig, Settings},
|
||||||
|
LemmyError,
|
||||||
|
};
|
||||||
use rate_limiter::{RateLimitType, RateLimiter};
|
use rate_limiter::{RateLimitType, RateLimiter};
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
|
@ -1,5 +1,5 @@
|
||||||
use super::IPAddr;
|
use lemmy_api_structs::APIError;
|
||||||
use crate::{api::APIError, LemmyError};
|
use lemmy_utils::{IPAddr, LemmyError};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use std::{collections::HashMap, time::SystemTime};
|
use std::{collections::HashMap, time::SystemTime};
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
@ -27,7 +27,7 @@ pub struct RateLimiter {
|
||||||
impl Default for RateLimiter {
|
impl Default for RateLimiter {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
buckets: HashMap::new(),
|
buckets: HashMap::<RateLimitType, HashMap<IPAddr, RateLimitBucket>>::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
2
server/lemmy_utils/Cargo.toml
vendored
2
server/lemmy_utils/Cargo.toml
vendored
|
@ -24,3 +24,5 @@ comrak = "0.7"
|
||||||
lazy_static = "1.3.0"
|
lazy_static = "1.3.0"
|
||||||
openssl = "0.10"
|
openssl = "0.10"
|
||||||
url = { version = "2.1.1", features = ["serde"] }
|
url = { version = "2.1.1", features = ["serde"] }
|
||||||
|
actix-web = "3.0.0-alpha.3"
|
||||||
|
anyhow = "1.0.32"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub extern crate lazy_static;
|
pub extern crate lazy_static;
|
||||||
|
pub extern crate actix_web;
|
||||||
|
pub extern crate anyhow;
|
||||||
pub extern crate comrak;
|
pub extern crate comrak;
|
||||||
pub extern crate lettre;
|
pub extern crate lettre;
|
||||||
pub extern crate lettre_email;
|
pub extern crate lettre_email;
|
||||||
|
@ -12,6 +14,7 @@ pub extern crate url;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
|
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
|
use actix_web::dev::ConnectionInfo;
|
||||||
use chrono::{DateTime, FixedOffset, Local, NaiveDateTime};
|
use chrono::{DateTime, FixedOffset, Local, NaiveDateTime};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lettre::{
|
use lettre::{
|
||||||
|
@ -31,6 +34,12 @@ use regex::{Regex, RegexBuilder};
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
pub type ConnectionId = usize;
|
||||||
|
pub type PostId = i32;
|
||||||
|
pub type CommunityId = i32;
|
||||||
|
pub type UserId = i32;
|
||||||
|
pub type IPAddr = String;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! location_info {
|
macro_rules! location_info {
|
||||||
() => {
|
() => {
|
||||||
|
@ -43,6 +52,28 @@ macro_rules! location_info {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct LemmyError {
|
||||||
|
inner: anyhow::Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> From<T> for LemmyError
|
||||||
|
where
|
||||||
|
T: Into<anyhow::Error>,
|
||||||
|
{
|
||||||
|
fn from(t: T) -> Self {
|
||||||
|
LemmyError { inner: t.into() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for LemmyError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
self.inner.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl actix_web::error::ResponseError for LemmyError {}
|
||||||
|
|
||||||
pub fn naive_from_unix(time: i64) -> NaiveDateTime {
|
pub fn naive_from_unix(time: i64) -> NaiveDateTime {
|
||||||
NaiveDateTime::from_timestamp(time, 0)
|
NaiveDateTime::from_timestamp(time, 0)
|
||||||
}
|
}
|
||||||
|
@ -346,3 +377,13 @@ pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
|
||||||
))
|
))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_ip(conn_info: &ConnectionInfo) -> String {
|
||||||
|
conn_info
|
||||||
|
.realip_remote_addr()
|
||||||
|
.unwrap_or("127.0.0.1:12345")
|
||||||
|
.split(':')
|
||||||
|
.next()
|
||||||
|
.unwrap_or("127.0.0.1")
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::{
|
||||||
get_user_from_jwt,
|
get_user_from_jwt,
|
||||||
get_user_from_jwt_opt,
|
get_user_from_jwt_opt,
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
APIError,
|
|
||||||
Perform,
|
Perform,
|
||||||
},
|
},
|
||||||
apub::{ApubLikeableType, ApubObjectType},
|
apub::{ApubLikeableType, ApubObjectType},
|
||||||
|
@ -14,12 +13,11 @@ use crate::{
|
||||||
messages::{JoinCommunityRoom, SendComment},
|
messages::{JoinCommunityRoom, SendComment},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
ConnectionId,
|
|
||||||
DbPool,
|
DbPool,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
|
use lemmy_api_structs::{comment::*, APIError};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::*,
|
comment::*,
|
||||||
comment_view::*,
|
comment_view::*,
|
||||||
|
@ -40,88 +38,14 @@ use lemmy_utils::{
|
||||||
scrape_text_for_mentions,
|
scrape_text_for_mentions,
|
||||||
send_email,
|
send_email,
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
|
ConnectionId,
|
||||||
EndpointType,
|
EndpointType,
|
||||||
|
LemmyError,
|
||||||
MentionData,
|
MentionData,
|
||||||
};
|
};
|
||||||
use log::error;
|
use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct CreateComment {
|
|
||||||
content: String,
|
|
||||||
parent_id: Option<i32>,
|
|
||||||
pub post_id: i32,
|
|
||||||
form_id: Option<String>,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct EditComment {
|
|
||||||
content: String,
|
|
||||||
edit_id: i32,
|
|
||||||
form_id: Option<String>,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct DeleteComment {
|
|
||||||
edit_id: i32,
|
|
||||||
deleted: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct RemoveComment {
|
|
||||||
edit_id: i32,
|
|
||||||
removed: bool,
|
|
||||||
reason: Option<String>,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct MarkCommentAsRead {
|
|
||||||
edit_id: i32,
|
|
||||||
read: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct SaveComment {
|
|
||||||
comment_id: i32,
|
|
||||||
save: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct CommentResponse {
|
|
||||||
pub comment: CommentView,
|
|
||||||
pub recipient_ids: Vec<i32>,
|
|
||||||
pub form_id: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct CreateCommentLike {
|
|
||||||
comment_id: i32,
|
|
||||||
score: i16,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetComments {
|
|
||||||
type_: String,
|
|
||||||
sort: String,
|
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
|
||||||
pub community_id: Option<i32>,
|
|
||||||
auth: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetCommentsResponse {
|
|
||||||
comments: Vec<CommentView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for CreateComment {
|
impl Perform for CreateComment {
|
||||||
type Response = CommentResponse;
|
type Response = CommentResponse;
|
||||||
|
|
|
@ -6,7 +6,6 @@ use crate::{
|
||||||
get_user_from_jwt_opt,
|
get_user_from_jwt_opt,
|
||||||
is_admin,
|
is_admin,
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
APIError,
|
|
||||||
Perform,
|
Perform,
|
||||||
},
|
},
|
||||||
apub::ActorType,
|
apub::ActorType,
|
||||||
|
@ -15,12 +14,11 @@ use crate::{
|
||||||
messages::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage},
|
messages::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
ConnectionId,
|
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use lemmy_api_structs::{community::*, APIError};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
comment_view::CommentQueryBuilder,
|
comment_view::CommentQueryBuilder,
|
||||||
|
@ -44,137 +42,12 @@ use lemmy_utils::{
|
||||||
location_info,
|
location_info,
|
||||||
make_apub_endpoint,
|
make_apub_endpoint,
|
||||||
naive_from_unix,
|
naive_from_unix,
|
||||||
|
ConnectionId,
|
||||||
EndpointType,
|
EndpointType,
|
||||||
|
LemmyError,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetCommunity {
|
|
||||||
id: Option<i32>,
|
|
||||||
pub name: Option<String>,
|
|
||||||
auth: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetCommunityResponse {
|
|
||||||
pub community: CommunityView,
|
|
||||||
pub moderators: Vec<CommunityModeratorView>,
|
|
||||||
pub online: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct CreateCommunity {
|
|
||||||
name: String,
|
|
||||||
title: String,
|
|
||||||
description: Option<String>,
|
|
||||||
icon: Option<String>,
|
|
||||||
banner: Option<String>,
|
|
||||||
category_id: i32,
|
|
||||||
nsfw: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct CommunityResponse {
|
|
||||||
pub community: CommunityView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct ListCommunities {
|
|
||||||
pub sort: String,
|
|
||||||
pub page: Option<i64>,
|
|
||||||
pub limit: Option<i64>,
|
|
||||||
pub auth: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct ListCommunitiesResponse {
|
|
||||||
pub communities: Vec<CommunityView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct BanFromCommunity {
|
|
||||||
pub community_id: i32,
|
|
||||||
user_id: i32,
|
|
||||||
ban: bool,
|
|
||||||
remove_data: Option<bool>,
|
|
||||||
reason: Option<String>,
|
|
||||||
expires: Option<i64>,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct BanFromCommunityResponse {
|
|
||||||
user: UserView,
|
|
||||||
banned: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct AddModToCommunity {
|
|
||||||
pub community_id: i32,
|
|
||||||
user_id: i32,
|
|
||||||
added: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct AddModToCommunityResponse {
|
|
||||||
moderators: Vec<CommunityModeratorView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct EditCommunity {
|
|
||||||
pub edit_id: i32,
|
|
||||||
title: String,
|
|
||||||
description: Option<String>,
|
|
||||||
icon: Option<String>,
|
|
||||||
banner: Option<String>,
|
|
||||||
category_id: i32,
|
|
||||||
nsfw: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct DeleteCommunity {
|
|
||||||
pub edit_id: i32,
|
|
||||||
deleted: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct RemoveCommunity {
|
|
||||||
pub edit_id: i32,
|
|
||||||
removed: bool,
|
|
||||||
reason: Option<String>,
|
|
||||||
expires: Option<i64>,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct FollowCommunity {
|
|
||||||
community_id: i32,
|
|
||||||
follow: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetFollowedCommunities {
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetFollowedCommunitiesResponse {
|
|
||||||
communities: Vec<CommunityFollowerView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct TransferCommunity {
|
|
||||||
community_id: i32,
|
|
||||||
user_id: i32,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetCommunity {
|
impl Perform for GetCommunity {
|
||||||
type Response = GetCommunityResponse;
|
type Response = GetCommunityResponse;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{api::claims::Claims, blocking, ConnectionId, DbPool, LemmyContext, LemmyError};
|
use crate::{api::claims::Claims, blocking, DbPool, LemmyContext};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
|
use lemmy_api_structs::APIError;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
community::Community,
|
community::Community,
|
||||||
community_view::CommunityUserBanView,
|
community_view::CommunityUserBanView,
|
||||||
|
@ -7,8 +8,7 @@ use lemmy_db::{
|
||||||
user::User_,
|
user::User_,
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{slur_check, slurs_vec_to_str};
|
use lemmy_utils::{slur_check, slurs_vec_to_str, ConnectionId, LemmyError};
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
pub mod claims;
|
pub mod claims;
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
|
@ -17,20 +17,6 @@ pub mod post;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
#[error("{{\"error\":\"{message}\"}}")]
|
|
||||||
pub struct APIError {
|
|
||||||
pub message: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl APIError {
|
|
||||||
pub fn err(msg: &str) -> Self {
|
|
||||||
APIError {
|
|
||||||
message: msg.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
pub trait Perform {
|
pub trait Perform {
|
||||||
type Response: serde::ser::Serialize + Send;
|
type Response: serde::ser::Serialize + Send;
|
||||||
|
|
|
@ -6,7 +6,6 @@ use crate::{
|
||||||
get_user_from_jwt,
|
get_user_from_jwt,
|
||||||
get_user_from_jwt_opt,
|
get_user_from_jwt_opt,
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
APIError,
|
|
||||||
Perform,
|
Perform,
|
||||||
},
|
},
|
||||||
apub::{ApubLikeableType, ApubObjectType},
|
apub::{ApubLikeableType, ApubObjectType},
|
||||||
|
@ -16,11 +15,10 @@ use crate::{
|
||||||
messages::{GetPostUsersOnline, JoinCommunityRoom, JoinPostRoom, SendPost},
|
messages::{GetPostUsersOnline, JoinCommunityRoom, JoinPostRoom, SendPost},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
ConnectionId,
|
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
|
use lemmy_api_structs::{post::*, APIError};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment_view::*,
|
comment_view::*,
|
||||||
community_view::*,
|
community_view::*,
|
||||||
|
@ -35,110 +33,16 @@ use lemmy_db::{
|
||||||
Saveable,
|
Saveable,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{is_valid_post_title, make_apub_endpoint, EndpointType};
|
use lemmy_utils::{
|
||||||
use serde::{Deserialize, Serialize};
|
is_valid_post_title,
|
||||||
|
make_apub_endpoint,
|
||||||
|
ConnectionId,
|
||||||
|
EndpointType,
|
||||||
|
LemmyError,
|
||||||
|
};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct CreatePost {
|
|
||||||
name: String,
|
|
||||||
url: Option<String>,
|
|
||||||
body: Option<String>,
|
|
||||||
nsfw: bool,
|
|
||||||
pub community_id: i32,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct PostResponse {
|
|
||||||
pub post: PostView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetPost {
|
|
||||||
pub id: i32,
|
|
||||||
auth: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetPostResponse {
|
|
||||||
post: PostView,
|
|
||||||
comments: Vec<CommentView>,
|
|
||||||
community: CommunityView,
|
|
||||||
moderators: Vec<CommunityModeratorView>,
|
|
||||||
pub online: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct GetPosts {
|
|
||||||
type_: String,
|
|
||||||
sort: String,
|
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
|
||||||
pub community_id: Option<i32>,
|
|
||||||
pub community_name: Option<String>,
|
|
||||||
auth: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct GetPostsResponse {
|
|
||||||
pub posts: Vec<PostView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct CreatePostLike {
|
|
||||||
post_id: i32,
|
|
||||||
score: i16,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct EditPost {
|
|
||||||
pub edit_id: i32,
|
|
||||||
name: String,
|
|
||||||
url: Option<String>,
|
|
||||||
body: Option<String>,
|
|
||||||
nsfw: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct DeletePost {
|
|
||||||
pub edit_id: i32,
|
|
||||||
deleted: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct RemovePost {
|
|
||||||
pub edit_id: i32,
|
|
||||||
removed: bool,
|
|
||||||
reason: Option<String>,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct LockPost {
|
|
||||||
pub edit_id: i32,
|
|
||||||
locked: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct StickyPost {
|
|
||||||
pub edit_id: i32,
|
|
||||||
stickied: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct SavePost {
|
|
||||||
post_id: i32,
|
|
||||||
save: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for CreatePost {
|
impl Perform for CreatePost {
|
||||||
type Response = PostResponse;
|
type Response = PostResponse;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use super::user::Register;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::{
|
||||||
check_slurs,
|
check_slurs,
|
||||||
|
@ -6,7 +5,6 @@ use crate::{
|
||||||
get_user_from_jwt,
|
get_user_from_jwt,
|
||||||
get_user_from_jwt_opt,
|
get_user_from_jwt_opt,
|
||||||
is_admin,
|
is_admin,
|
||||||
APIError,
|
|
||||||
Perform,
|
Perform,
|
||||||
},
|
},
|
||||||
apub::fetcher::search_by_apub_id,
|
apub::fetcher::search_by_apub_id,
|
||||||
|
@ -16,12 +14,11 @@ use crate::{
|
||||||
messages::{GetUsersOnline, SendAllMessage},
|
messages::{GetUsersOnline, SendAllMessage},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
ConnectionId,
|
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use lemmy_api_structs::{site::*, user::Register, APIError};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
category::*,
|
category::*,
|
||||||
comment_view::*,
|
comment_view::*,
|
||||||
|
@ -33,133 +30,15 @@ use lemmy_db::{
|
||||||
post_view::*,
|
post_view::*,
|
||||||
site::*,
|
site::*,
|
||||||
site_view::*,
|
site_view::*,
|
||||||
user::*,
|
|
||||||
user_view::*,
|
user_view::*,
|
||||||
Crud,
|
Crud,
|
||||||
SearchType,
|
SearchType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{location_info, settings::Settings};
|
use lemmy_utils::{location_info, settings::Settings, ConnectionId, LemmyError};
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct ListCategories {}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct ListCategoriesResponse {
|
|
||||||
categories: Vec<Category>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct Search {
|
|
||||||
q: String,
|
|
||||||
type_: String,
|
|
||||||
community_id: Option<i32>,
|
|
||||||
sort: String,
|
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
|
||||||
auth: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct SearchResponse {
|
|
||||||
pub type_: String,
|
|
||||||
pub comments: Vec<CommentView>,
|
|
||||||
pub posts: Vec<PostView>,
|
|
||||||
pub communities: Vec<CommunityView>,
|
|
||||||
pub users: Vec<UserView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetModlog {
|
|
||||||
mod_user_id: Option<i32>,
|
|
||||||
community_id: Option<i32>,
|
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetModlogResponse {
|
|
||||||
removed_posts: Vec<ModRemovePostView>,
|
|
||||||
locked_posts: Vec<ModLockPostView>,
|
|
||||||
stickied_posts: Vec<ModStickyPostView>,
|
|
||||||
removed_comments: Vec<ModRemoveCommentView>,
|
|
||||||
removed_communities: Vec<ModRemoveCommunityView>,
|
|
||||||
banned_from_community: Vec<ModBanFromCommunityView>,
|
|
||||||
banned: Vec<ModBanView>,
|
|
||||||
added_to_community: Vec<ModAddCommunityView>,
|
|
||||||
added: Vec<ModAddView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct CreateSite {
|
|
||||||
pub name: String,
|
|
||||||
pub description: Option<String>,
|
|
||||||
pub icon: Option<String>,
|
|
||||||
pub banner: Option<String>,
|
|
||||||
pub enable_downvotes: bool,
|
|
||||||
pub open_registration: bool,
|
|
||||||
pub enable_nsfw: bool,
|
|
||||||
pub auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct EditSite {
|
|
||||||
name: String,
|
|
||||||
description: Option<String>,
|
|
||||||
icon: Option<String>,
|
|
||||||
banner: Option<String>,
|
|
||||||
enable_downvotes: bool,
|
|
||||||
open_registration: bool,
|
|
||||||
enable_nsfw: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetSite {
|
|
||||||
auth: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct SiteResponse {
|
|
||||||
site: SiteView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetSiteResponse {
|
|
||||||
site: Option<SiteView>,
|
|
||||||
admins: Vec<UserView>,
|
|
||||||
banned: Vec<UserView>,
|
|
||||||
pub online: usize,
|
|
||||||
version: String,
|
|
||||||
my_user: Option<User_>,
|
|
||||||
federated_instances: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct TransferSite {
|
|
||||||
user_id: i32,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetSiteConfig {
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetSiteConfigResponse {
|
|
||||||
config_hjson: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct SaveSiteConfig {
|
|
||||||
config_hjson: String,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for ListCategories {
|
impl Perform for ListCategories {
|
||||||
type Response = ListCategoriesResponse;
|
type Response = ListCategoriesResponse;
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::{check_slurs, claims::Claims, get_user_from_jwt, get_user_from_jwt_opt, is_admin, Perform},
|
||||||
check_slurs,
|
|
||||||
claims::Claims,
|
|
||||||
get_user_from_jwt,
|
|
||||||
get_user_from_jwt_opt,
|
|
||||||
is_admin,
|
|
||||||
APIError,
|
|
||||||
Perform,
|
|
||||||
},
|
|
||||||
apub::ApubObjectType,
|
apub::ApubObjectType,
|
||||||
blocking,
|
blocking,
|
||||||
captcha_espeak_wav_base64,
|
captcha_espeak_wav_base64,
|
||||||
|
@ -15,15 +7,14 @@ use crate::{
|
||||||
messages::{CaptchaItem, CheckCaptcha, JoinUserRoom, SendAllMessage, SendUserRoomMessage},
|
messages::{CaptchaItem, CheckCaptcha, JoinUserRoom, SendAllMessage, SendUserRoomMessage},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
ConnectionId,
|
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use bcrypt::verify;
|
use bcrypt::verify;
|
||||||
use captcha::{gen, Difficulty};
|
use captcha::{gen, Difficulty};
|
||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
|
use lemmy_api_structs::{user::*, APIError};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::*,
|
comment::*,
|
||||||
comment_view::*,
|
comment_view::*,
|
||||||
|
@ -60,242 +51,13 @@ use lemmy_utils::{
|
||||||
remove_slurs,
|
remove_slurs,
|
||||||
send_email,
|
send_email,
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
|
ConnectionId,
|
||||||
EndpointType,
|
EndpointType,
|
||||||
|
LemmyError,
|
||||||
};
|
};
|
||||||
use log::error;
|
use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct Login {
|
|
||||||
username_or_email: String,
|
|
||||||
password: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct Register {
|
|
||||||
pub username: String,
|
|
||||||
pub email: Option<String>,
|
|
||||||
pub password: String,
|
|
||||||
pub password_verify: String,
|
|
||||||
pub admin: bool,
|
|
||||||
pub show_nsfw: bool,
|
|
||||||
pub captcha_uuid: Option<String>,
|
|
||||||
pub captcha_answer: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetCaptcha {}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetCaptchaResponse {
|
|
||||||
ok: Option<CaptchaResponse>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct CaptchaResponse {
|
|
||||||
png: String, // A Base64 encoded png
|
|
||||||
wav: Option<String>, // A Base64 encoded wav audio
|
|
||||||
uuid: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct SaveUserSettings {
|
|
||||||
show_nsfw: bool,
|
|
||||||
theme: String,
|
|
||||||
default_sort_type: i16,
|
|
||||||
default_listing_type: i16,
|
|
||||||
lang: String,
|
|
||||||
avatar: Option<String>,
|
|
||||||
banner: Option<String>,
|
|
||||||
preferred_username: Option<String>,
|
|
||||||
email: Option<String>,
|
|
||||||
bio: Option<String>,
|
|
||||||
matrix_user_id: Option<String>,
|
|
||||||
new_password: Option<String>,
|
|
||||||
new_password_verify: Option<String>,
|
|
||||||
old_password: Option<String>,
|
|
||||||
show_avatars: bool,
|
|
||||||
send_notifications_to_email: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct LoginResponse {
|
|
||||||
pub jwt: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetUserDetails {
|
|
||||||
user_id: Option<i32>,
|
|
||||||
username: Option<String>,
|
|
||||||
sort: String,
|
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
|
||||||
community_id: Option<i32>,
|
|
||||||
saved_only: bool,
|
|
||||||
auth: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetUserDetailsResponse {
|
|
||||||
user: UserView,
|
|
||||||
follows: Vec<CommunityFollowerView>,
|
|
||||||
moderates: Vec<CommunityModeratorView>,
|
|
||||||
comments: Vec<CommentView>,
|
|
||||||
posts: Vec<PostView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetRepliesResponse {
|
|
||||||
replies: Vec<ReplyView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetUserMentionsResponse {
|
|
||||||
mentions: Vec<UserMentionView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct MarkAllAsRead {
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct AddAdmin {
|
|
||||||
user_id: i32,
|
|
||||||
added: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct AddAdminResponse {
|
|
||||||
admins: Vec<UserView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct BanUser {
|
|
||||||
user_id: i32,
|
|
||||||
ban: bool,
|
|
||||||
remove_data: Option<bool>,
|
|
||||||
reason: Option<String>,
|
|
||||||
expires: Option<i64>,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct BanUserResponse {
|
|
||||||
user: UserView,
|
|
||||||
banned: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetReplies {
|
|
||||||
sort: String,
|
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
|
||||||
unread_only: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetUserMentions {
|
|
||||||
sort: String,
|
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
|
||||||
unread_only: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct MarkUserMentionAsRead {
|
|
||||||
user_mention_id: i32,
|
|
||||||
read: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct UserMentionResponse {
|
|
||||||
mention: UserMentionView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct DeleteAccount {
|
|
||||||
password: String,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct PasswordReset {
|
|
||||||
email: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct PasswordResetResponse {}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct PasswordChange {
|
|
||||||
token: String,
|
|
||||||
password: String,
|
|
||||||
password_verify: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct CreatePrivateMessage {
|
|
||||||
content: String,
|
|
||||||
pub recipient_id: i32,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct EditPrivateMessage {
|
|
||||||
edit_id: i32,
|
|
||||||
content: String,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct DeletePrivateMessage {
|
|
||||||
edit_id: i32,
|
|
||||||
deleted: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct MarkPrivateMessageAsRead {
|
|
||||||
edit_id: i32,
|
|
||||||
read: bool,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct GetPrivateMessages {
|
|
||||||
unread_only: bool,
|
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct PrivateMessagesResponse {
|
|
||||||
messages: Vec<PrivateMessageView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct PrivateMessageResponse {
|
|
||||||
pub message: PrivateMessageView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct UserJoin {
|
|
||||||
auth: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
pub struct UserJoinResponse {
|
|
||||||
pub user_id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for Login {
|
impl Perform for Login {
|
||||||
type Response = LoginResponse;
|
type Response = LoginResponse;
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
apub::{activity_queue::send_activity, community::do_announce, insert_activity},
|
apub::{activity_queue::send_activity, community::do_announce, insert_activity},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
base::{Extends, ExtendsExt},
|
base::{Extends, ExtendsExt},
|
||||||
object::AsObject,
|
object::AsObject,
|
||||||
};
|
};
|
||||||
use lemmy_db::{community::Community, user::User_};
|
use lemmy_db::{community::Community, user::User_};
|
||||||
use lemmy_utils::{get_apub_protocol_string, settings::Settings};
|
use lemmy_utils::{get_apub_protocol_string, settings::Settings, LemmyError};
|
||||||
use serde::{export::fmt::Debug, Serialize};
|
use serde::{export::fmt::Debug, Serialize};
|
||||||
use url::{ParseError, Url};
|
use url::{ParseError, Url};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
use crate::{
|
use crate::apub::{check_is_apub_id_valid, extensions::signatures::sign, ActorType};
|
||||||
apub::{check_is_apub_id_valid, extensions::signatures::sign, ActorType},
|
|
||||||
LemmyError,
|
|
||||||
};
|
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
base::{Extends, ExtendsExt},
|
base::{Extends, ExtendsExt},
|
||||||
object::AsObject,
|
object::AsObject,
|
||||||
|
@ -17,7 +14,7 @@ use background_jobs::{
|
||||||
QueueHandle,
|
QueueHandle,
|
||||||
WorkerConfig,
|
WorkerConfig,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{location_info, settings::Settings};
|
use lemmy_utils::{location_info, settings::Settings, LemmyError};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{future::Future, pin::Pin};
|
use std::{future::Future, pin::Pin};
|
||||||
|
|
|
@ -20,7 +20,6 @@ use crate::{
|
||||||
blocking,
|
blocking,
|
||||||
DbPool,
|
DbPool,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{
|
activity::{
|
||||||
|
@ -54,6 +53,7 @@ use lemmy_utils::{
|
||||||
location_info,
|
location_info,
|
||||||
remove_slurs,
|
remove_slurs,
|
||||||
scrape_text_for_mentions,
|
scrape_text_for_mentions,
|
||||||
|
LemmyError,
|
||||||
MentionData,
|
MentionData,
|
||||||
};
|
};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
|
@ -18,7 +18,6 @@ use crate::{
|
||||||
blocking,
|
blocking,
|
||||||
DbPool,
|
DbPool,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{
|
activity::{
|
||||||
|
@ -48,7 +47,7 @@ use lemmy_db::{
|
||||||
post::Post,
|
post::Post,
|
||||||
user::User_,
|
user::User_,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{convert_datetime, get_apub_protocol_string, location_info};
|
use lemmy_utils::{convert_datetime, get_apub_protocol_string, location_info, LemmyError};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::LemmyError;
|
|
||||||
use activitystreams::unparsed::UnparsedMutExt;
|
use activitystreams::unparsed::UnparsedMutExt;
|
||||||
use activitystreams_ext::UnparsedExtension;
|
use activitystreams_ext::UnparsedExtension;
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use lemmy_db::{category::Category, Crud};
|
use lemmy_db::{category::Category, Crud};
|
||||||
|
use lemmy_utils::LemmyError;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{apub::ActorType, LemmyError};
|
use crate::apub::ActorType;
|
||||||
use activitystreams::unparsed::UnparsedMutExt;
|
use activitystreams::unparsed::UnparsedMutExt;
|
||||||
use activitystreams_ext::UnparsedExtension;
|
use activitystreams_ext::UnparsedExtension;
|
||||||
use actix_web::{client::ClientRequest, HttpRequest};
|
use actix_web::{client::ClientRequest, HttpRequest};
|
||||||
|
@ -7,7 +7,7 @@ use http_signature_normalization_actix::{
|
||||||
digest::{DigestClient, SignExt},
|
digest::{DigestClient, SignExt},
|
||||||
Config,
|
Config,
|
||||||
};
|
};
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use openssl::{
|
use openssl::{
|
||||||
hash::MessageDigest,
|
hash::MessageDigest,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::site::SearchResponse,
|
|
||||||
apub::{
|
apub::{
|
||||||
check_is_apub_id_valid,
|
check_is_apub_id_valid,
|
||||||
ActorType,
|
ActorType,
|
||||||
|
@ -12,12 +11,12 @@ use crate::{
|
||||||
blocking,
|
blocking,
|
||||||
request::{retry, RecvError},
|
request::{retry, RecvError},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{base::BaseExt, collection::OrderedCollection, object::Note, prelude::*};
|
use activitystreams::{base::BaseExt, collection::OrderedCollection, object::Note, prelude::*};
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::result::Error::NotFound;
|
use diesel::result::Error::NotFound;
|
||||||
|
use lemmy_api_structs::site::SearchResponse;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
|
@ -32,7 +31,7 @@ use lemmy_db::{
|
||||||
Joinable,
|
Joinable,
|
||||||
SearchType,
|
SearchType,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{get_apub_protocol_string, location_info};
|
use lemmy_utils::{get_apub_protocol_string, location_info, LemmyError};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
|
@ -12,7 +12,6 @@ use crate::{
|
||||||
shared_inbox::{get_community_id_from_activity, receive_unhandled_activity},
|
shared_inbox::{get_community_id_from_activity, receive_unhandled_activity},
|
||||||
},
|
},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::*,
|
activity::*,
|
||||||
|
@ -21,7 +20,7 @@ use activitystreams::{
|
||||||
};
|
};
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
|
|
||||||
pub async fn receive_announce(
|
pub async fn receive_announce(
|
||||||
activity: AnyBase,
|
activity: AnyBase,
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::comment::send_local_notifs,
|
||||||
comment::{send_local_notifs, CommentResponse},
|
|
||||||
post::PostResponse,
|
|
||||||
},
|
|
||||||
apub::{
|
apub::{
|
||||||
inbox::shared_inbox::{
|
inbox::shared_inbox::{
|
||||||
announce_if_community_is_local,
|
announce_if_community_is_local,
|
||||||
|
@ -19,18 +16,18 @@ use crate::{
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{activity::Create, base::AnyBase, object::Note, prelude::*};
|
use activitystreams::{activity::Create, base::AnyBase, object::Note, prelude::*};
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
post::{Post, PostForm},
|
post::{Post, PostForm},
|
||||||
post_view::PostView,
|
post_view::PostView,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{location_info, scrape_text_for_mentions};
|
use lemmy_utils::{location_info, scrape_text_for_mentions, LemmyError};
|
||||||
|
|
||||||
pub async fn receive_create(
|
pub async fn receive_create(
|
||||||
activity: AnyBase,
|
activity: AnyBase,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
|
|
||||||
apub::{
|
apub::{
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::{
|
inbox::shared_inbox::{
|
||||||
|
@ -18,11 +17,15 @@ use crate::{
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{activity::Delete, base::AnyBase, object::Note, prelude::*};
|
use activitystreams::{activity::Delete, base::AnyBase, object::Note, prelude::*};
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use lemmy_api_structs::{
|
||||||
|
comment::CommentResponse,
|
||||||
|
community::CommunityResponse,
|
||||||
|
post::PostResponse,
|
||||||
|
};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
|
@ -33,7 +36,7 @@ use lemmy_db::{
|
||||||
post_view::PostView,
|
post_view::PostView,
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
|
|
||||||
pub async fn receive_delete(
|
pub async fn receive_delete(
|
||||||
activity: AnyBase,
|
activity: AnyBase,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{comment::CommentResponse, post::PostResponse},
|
|
||||||
apub::{
|
apub::{
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::{
|
inbox::shared_inbox::{
|
||||||
|
@ -16,11 +15,11 @@ use crate::{
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{activity::Dislike, base::AnyBase, object::Note, prelude::*};
|
use activitystreams::{activity::Dislike, base::AnyBase, object::Note, prelude::*};
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{CommentForm, CommentLike, CommentLikeForm},
|
comment::{CommentForm, CommentLike, CommentLikeForm},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
|
@ -28,7 +27,7 @@ use lemmy_db::{
|
||||||
post_view::PostView,
|
post_view::PostView,
|
||||||
Likeable,
|
Likeable,
|
||||||
};
|
};
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
|
|
||||||
pub async fn receive_dislike(
|
pub async fn receive_dislike(
|
||||||
activity: AnyBase,
|
activity: AnyBase,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{comment::CommentResponse, post::PostResponse},
|
|
||||||
apub::{
|
apub::{
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::{
|
inbox::shared_inbox::{
|
||||||
|
@ -16,11 +15,11 @@ use crate::{
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{activity::Like, base::AnyBase, object::Note, prelude::*};
|
use activitystreams::{activity::Like, base::AnyBase, object::Note, prelude::*};
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{CommentForm, CommentLike, CommentLikeForm},
|
comment::{CommentForm, CommentLike, CommentLikeForm},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
|
@ -28,7 +27,7 @@ use lemmy_db::{
|
||||||
post_view::PostView,
|
post_view::PostView,
|
||||||
Likeable,
|
Likeable,
|
||||||
};
|
};
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
|
|
||||||
pub async fn receive_like(
|
pub async fn receive_like(
|
||||||
activity: AnyBase,
|
activity: AnyBase,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
|
|
||||||
apub::{
|
apub::{
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::{
|
inbox::shared_inbox::{
|
||||||
|
@ -19,11 +18,15 @@ use crate::{
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{activity::Remove, base::AnyBase, object::Note, prelude::*};
|
use activitystreams::{activity::Remove, base::AnyBase, object::Note, prelude::*};
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
|
use lemmy_api_structs::{
|
||||||
|
comment::CommentResponse,
|
||||||
|
community::CommunityResponse,
|
||||||
|
post::PostResponse,
|
||||||
|
};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
|
@ -34,7 +37,7 @@ use lemmy_db::{
|
||||||
post_view::PostView,
|
post_view::PostView,
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
|
|
||||||
pub async fn receive_remove(
|
pub async fn receive_remove(
|
||||||
activity: AnyBase,
|
activity: AnyBase,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
|
|
||||||
apub::{
|
apub::{
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::{
|
inbox::shared_inbox::{
|
||||||
|
@ -18,7 +17,6 @@ use crate::{
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::*,
|
activity::*,
|
||||||
|
@ -28,6 +26,11 @@ use activitystreams::{
|
||||||
};
|
};
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
|
use lemmy_api_structs::{
|
||||||
|
comment::CommentResponse,
|
||||||
|
community::CommunityResponse,
|
||||||
|
post::PostResponse,
|
||||||
|
};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm, CommentLike},
|
comment::{Comment, CommentForm, CommentLike},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
|
@ -39,7 +42,7 @@ use lemmy_db::{
|
||||||
Crud,
|
Crud,
|
||||||
Likeable,
|
Likeable,
|
||||||
};
|
};
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
|
|
||||||
pub async fn receive_undo(
|
pub async fn receive_undo(
|
||||||
activity: AnyBase,
|
activity: AnyBase,
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::comment::send_local_notifs,
|
||||||
comment::{send_local_notifs, CommentResponse},
|
|
||||||
post::PostResponse,
|
|
||||||
},
|
|
||||||
apub::{
|
apub::{
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::{
|
inbox::shared_inbox::{
|
||||||
|
@ -20,11 +17,11 @@ use crate::{
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{activity::Update, base::AnyBase, object::Note, prelude::*};
|
use activitystreams::{activity::Update, base::AnyBase, object::Note, prelude::*};
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
|
@ -32,7 +29,7 @@ use lemmy_db::{
|
||||||
post_view::PostView,
|
post_view::PostView,
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{location_info, scrape_text_for_mentions};
|
use lemmy_utils::{location_info, scrape_text_for_mentions, LemmyError};
|
||||||
|
|
||||||
pub async fn receive_update(
|
pub async fn receive_update(
|
||||||
activity: AnyBase,
|
activity: AnyBase,
|
||||||
|
|
|
@ -8,7 +8,6 @@ use crate::{
|
||||||
},
|
},
|
||||||
blocking,
|
blocking,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{ActorAndObject, Follow, Undo},
|
activity::{ActorAndObject, Follow, Undo},
|
||||||
|
@ -22,7 +21,7 @@ use lemmy_db::{
|
||||||
user::User_,
|
user::User_,
|
||||||
Followable,
|
Followable,
|
||||||
};
|
};
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
|
@ -21,7 +21,6 @@ use crate::{
|
||||||
insert_activity,
|
insert_activity,
|
||||||
},
|
},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{ActorAndObject, ActorAndObjectRef},
|
activity::{ActorAndObject, ActorAndObjectRef},
|
||||||
|
@ -32,7 +31,7 @@ use activitystreams::{
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_db::user::User_;
|
use lemmy_db::user::User_;
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::user::PrivateMessageResponse,
|
|
||||||
apub::{
|
apub::{
|
||||||
check_is_apub_id_valid,
|
check_is_apub_id_valid,
|
||||||
extensions::signatures::verify,
|
extensions::signatures::verify,
|
||||||
|
@ -10,7 +9,6 @@ use crate::{
|
||||||
blocking,
|
blocking,
|
||||||
websocket::{messages::SendUserRoomMessage, UserOperation},
|
websocket::{messages::SendUserRoomMessage, UserOperation},
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{Accept, ActorAndObject, Create, Delete, Undo, Update},
|
activity::{Accept, ActorAndObject, Create, Delete, Undo, Update},
|
||||||
|
@ -20,6 +18,7 @@ use activitystreams::{
|
||||||
};
|
};
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use lemmy_api_structs::user::PrivateMessageResponse;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
community::{CommunityFollower, CommunityFollowerForm},
|
community::{CommunityFollower, CommunityFollowerForm},
|
||||||
naive_now,
|
naive_now,
|
||||||
|
@ -29,7 +28,7 @@ use lemmy_db::{
|
||||||
Crud,
|
Crud,
|
||||||
Followable,
|
Followable,
|
||||||
};
|
};
|
||||||
use lemmy_utils::location_info;
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
|
@ -20,7 +20,6 @@ use crate::{
|
||||||
routes::webfinger::WebFingerResponse,
|
routes::webfinger::WebFingerResponse,
|
||||||
DbPool,
|
DbPool,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::Follow,
|
activity::Follow,
|
||||||
|
@ -40,6 +39,7 @@ use lemmy_utils::{
|
||||||
get_apub_protocol_string,
|
get_apub_protocol_string,
|
||||||
location_info,
|
location_info,
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
|
LemmyError,
|
||||||
MentionData,
|
MentionData,
|
||||||
};
|
};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
|
@ -18,7 +18,6 @@ use crate::{
|
||||||
blocking,
|
blocking,
|
||||||
DbPool,
|
DbPool,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{
|
activity::{
|
||||||
|
@ -44,7 +43,7 @@ use lemmy_db::{
|
||||||
user::User_,
|
user::User_,
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{convert_datetime, location_info, remove_slurs};
|
use lemmy_utils::{convert_datetime, location_info, remove_slurs, LemmyError};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ use crate::{
|
||||||
blocking,
|
blocking,
|
||||||
DbPool,
|
DbPool,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{
|
activity::{
|
||||||
|
@ -34,7 +33,7 @@ use lemmy_db::{
|
||||||
user::User_,
|
user::User_,
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{convert_datetime, location_info};
|
use lemmy_utils::{convert_datetime, location_info, LemmyError};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
|
|
@ -15,7 +15,6 @@ use crate::{
|
||||||
blocking,
|
blocking,
|
||||||
DbPool,
|
DbPool,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{
|
activity::{
|
||||||
|
@ -34,7 +33,7 @@ use lemmy_db::{
|
||||||
naive_now,
|
naive_now,
|
||||||
user::{UserForm, User_},
|
user::{UserForm, User_},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{convert_datetime, location_info};
|
use lemmy_utils::{convert_datetime, location_info, LemmyError};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// This is for db migrations that require code
|
// This is for db migrations that require code
|
||||||
use crate::LemmyError;
|
|
||||||
use diesel::{
|
use diesel::{
|
||||||
sql_types::{Nullable, Text},
|
sql_types::{Nullable, Text},
|
||||||
*,
|
*,
|
||||||
|
@ -19,6 +18,7 @@ use lemmy_utils::{
|
||||||
make_apub_endpoint,
|
make_apub_endpoint,
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
EndpointType,
|
EndpointType,
|
||||||
|
LemmyError,
|
||||||
};
|
};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
|
|
|
@ -24,20 +24,19 @@ pub extern crate strum;
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod apub;
|
pub mod apub;
|
||||||
pub mod code_migrations;
|
pub mod code_migrations;
|
||||||
pub mod rate_limit;
|
|
||||||
pub mod request;
|
pub mod request;
|
||||||
pub mod routes;
|
pub mod routes;
|
||||||
pub mod version;
|
pub mod version;
|
||||||
pub mod websocket;
|
pub mod websocket;
|
||||||
|
|
||||||
use crate::request::{retry, RecvError};
|
use crate::{
|
||||||
|
request::{retry, RecvError},
|
||||||
use crate::websocket::chat_server::ChatServer;
|
websocket::chat_server::ChatServer,
|
||||||
|
};
|
||||||
use actix::Addr;
|
use actix::Addr;
|
||||||
use actix_web::dev::ConnectionInfo;
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use background_jobs::QueueHandle;
|
use background_jobs::QueueHandle;
|
||||||
use lemmy_utils::{get_apub_protocol_string, settings::Settings};
|
use lemmy_utils::{get_apub_protocol_string, settings::Settings, LemmyError};
|
||||||
use log::error;
|
use log::error;
|
||||||
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
@ -45,33 +44,6 @@ use serde::Deserialize;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
|
pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
|
||||||
pub type ConnectionId = usize;
|
|
||||||
pub type PostId = i32;
|
|
||||||
pub type CommunityId = i32;
|
|
||||||
pub type UserId = i32;
|
|
||||||
pub type IPAddr = String;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct LemmyError {
|
|
||||||
inner: anyhow::Error,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> From<T> for LemmyError
|
|
||||||
where
|
|
||||||
T: Into<anyhow::Error>,
|
|
||||||
{
|
|
||||||
fn from(t: T) -> Self {
|
|
||||||
LemmyError { inner: t.into() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for LemmyError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
||||||
self.inner.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl actix_web::error::ResponseError for LemmyError {}
|
|
||||||
|
|
||||||
pub struct LemmyContext {
|
pub struct LemmyContext {
|
||||||
pub pool: DbPool,
|
pub pool: DbPool,
|
||||||
|
@ -252,16 +224,6 @@ pub async fn is_image_content_type(client: &Client, test: &str) -> Result<(), Le
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_ip(conn_info: &ConnectionInfo) -> String {
|
|
||||||
conn_info
|
|
||||||
.realip_remote_addr()
|
|
||||||
.unwrap_or("127.0.0.1:12345")
|
|
||||||
.split(':')
|
|
||||||
.next()
|
|
||||||
.unwrap_or("127.0.0.1")
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn blocking<F, T>(pool: &DbPool, f: F) -> Result<T, LemmyError>
|
pub async fn blocking<F, T>(pool: &DbPool, f: F) -> Result<T, LemmyError>
|
||||||
where
|
where
|
||||||
F: FnOnce(&diesel::PgConnection) -> T + Send + 'static,
|
F: FnOnce(&diesel::PgConnection) -> T + Send + 'static,
|
||||||
|
|
|
@ -18,17 +18,16 @@ use diesel::{
|
||||||
PgConnection,
|
PgConnection,
|
||||||
};
|
};
|
||||||
use lemmy_db::get_database_url_from_env;
|
use lemmy_db::get_database_url_from_env;
|
||||||
|
use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit};
|
||||||
use lemmy_server::{
|
use lemmy_server::{
|
||||||
apub::activity_queue::create_activity_queue,
|
apub::activity_queue::create_activity_queue,
|
||||||
blocking,
|
blocking,
|
||||||
code_migrations::run_advanced_migrations,
|
code_migrations::run_advanced_migrations,
|
||||||
rate_limit::{rate_limiter::RateLimiter, RateLimit},
|
|
||||||
routes::*,
|
routes::*,
|
||||||
websocket::chat_server::ChatServer,
|
websocket::chat_server::ChatServer,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use lemmy_utils::{settings::Settings, CACHE_CONTROL_REGEX};
|
use lemmy_utils::{settings::Settings, LemmyError, CACHE_CONTROL_REGEX};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::LemmyError;
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
use lemmy_utils::LemmyError;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
use crate::{
|
use crate::{api::Perform, LemmyContext};
|
||||||
api::{comment::*, community::*, post::*, site::*, user::*, Perform},
|
|
||||||
rate_limit::RateLimit,
|
|
||||||
LemmyContext,
|
|
||||||
};
|
|
||||||
use actix_web::{error::ErrorBadRequest, *};
|
use actix_web::{error::ErrorBadRequest, *};
|
||||||
|
use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*};
|
||||||
|
use lemmy_rate_limit::RateLimit;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
|
pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{api::claims::Claims, blocking, LemmyContext, LemmyError};
|
use crate::{api::claims::Claims, blocking, LemmyContext};
|
||||||
use actix_web::{error::ErrorBadRequest, *};
|
use actix_web::{error::ErrorBadRequest, *};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||||
|
@ -13,7 +13,7 @@ use lemmy_db::{
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{markdown_to_html, settings::Settings};
|
use lemmy_utils::{markdown_to_html, settings::Settings, LemmyError};
|
||||||
use rss::{CategoryBuilder, ChannelBuilder, GuidBuilder, Item, ItemBuilder};
|
use rss::{CategoryBuilder, ChannelBuilder, GuidBuilder, Item, ItemBuilder};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::rate_limit::RateLimit;
|
|
||||||
use actix::clock::Duration;
|
use actix::clock::Duration;
|
||||||
use actix_web::{body::BodyStream, http::StatusCode, *};
|
use actix_web::{body::BodyStream, http::StatusCode, *};
|
||||||
use awc::Client;
|
use awc::Client;
|
||||||
|
use lemmy_rate_limit::RateLimit;
|
||||||
use lemmy_utils::settings::Settings;
|
use lemmy_utils::settings::Settings;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::{blocking, version, LemmyContext, LemmyError};
|
use crate::{blocking, version, LemmyContext};
|
||||||
use actix_web::{body::Body, error::ErrorBadRequest, *};
|
use actix_web::{body::Body, error::ErrorBadRequest, *};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use lemmy_db::site_view::SiteView;
|
use lemmy_db::site_view::SiteView;
|
||||||
use lemmy_utils::{get_apub_protocol_string, settings::Settings};
|
use lemmy_utils::{get_apub_protocol_string, settings::Settings, LemmyError};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
use crate::{blocking, LemmyContext, LemmyError};
|
use crate::{blocking, LemmyContext};
|
||||||
use actix_web::{error::ErrorBadRequest, web::Query, *};
|
use actix_web::{error::ErrorBadRequest, web::Query, *};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use lemmy_db::{community::Community, user::User_};
|
use lemmy_db::{community::Community, user::User_};
|
||||||
use lemmy_utils::{settings::Settings, WEBFINGER_COMMUNITY_REGEX, WEBFINGER_USER_REGEX};
|
use lemmy_utils::{
|
||||||
|
settings::Settings,
|
||||||
|
LemmyError,
|
||||||
|
WEBFINGER_COMMUNITY_REGEX,
|
||||||
|
WEBFINGER_USER_REGEX,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
get_ip,
|
|
||||||
websocket::{
|
websocket::{
|
||||||
chat_server::ChatServer,
|
chat_server::ChatServer,
|
||||||
messages::{Connect, Disconnect, StandardMessage, WSMessage},
|
messages::{Connect, Disconnect, StandardMessage, WSMessage},
|
||||||
|
@ -9,6 +8,7 @@ use crate::{
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use actix_web::*;
|
use actix_web::*;
|
||||||
use actix_web_actors::ws;
|
use actix_web_actors::ws;
|
||||||
|
use lemmy_utils::get_ip;
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{comment::*, community::*, post::*, site::*, user::*, APIError},
|
|
||||||
rate_limit::RateLimit,
|
|
||||||
websocket::{
|
websocket::{
|
||||||
handlers::{do_user_operation, to_json_string, Args},
|
handlers::{do_user_operation, to_json_string, Args},
|
||||||
messages::*,
|
messages::*,
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
CommunityId,
|
|
||||||
ConnectionId,
|
|
||||||
IPAddr,
|
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
PostId,
|
|
||||||
UserId,
|
|
||||||
};
|
};
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use anyhow::Context as acontext;
|
use anyhow::Context as acontext;
|
||||||
|
@ -21,7 +13,9 @@ use diesel::{
|
||||||
r2d2::{ConnectionManager, Pool},
|
r2d2::{ConnectionManager, Pool},
|
||||||
PgConnection,
|
PgConnection,
|
||||||
};
|
};
|
||||||
use lemmy_utils::location_info;
|
use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*, APIError};
|
||||||
|
use lemmy_rate_limit::RateLimit;
|
||||||
|
use lemmy_utils::{location_info, CommunityId, ConnectionId, IPAddr, LemmyError, PostId, UserId};
|
||||||
use rand::rngs::ThreadRng;
|
use rand::rngs::ThreadRng;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::Perform,
|
api::Perform,
|
||||||
rate_limit::RateLimit,
|
|
||||||
websocket::{
|
websocket::{
|
||||||
chat_server::{ChatServer, SessionInfo},
|
chat_server::{ChatServer, SessionInfo},
|
||||||
messages::*,
|
messages::*,
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
ConnectionId,
|
|
||||||
IPAddr,
|
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use actix::{Actor, Context, Handler, ResponseFuture};
|
use actix::{Actor, Context, Handler, ResponseFuture};
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
use lemmy_db::naive_now;
|
use lemmy_db::naive_now;
|
||||||
|
use lemmy_rate_limit::RateLimit;
|
||||||
|
use lemmy_utils::{ConnectionId, IPAddr, LemmyError};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
use crate::{
|
use crate::websocket::UserOperation;
|
||||||
api::{comment::CommentResponse, post::PostResponse},
|
|
||||||
websocket::UserOperation,
|
|
||||||
CommunityId,
|
|
||||||
ConnectionId,
|
|
||||||
IPAddr,
|
|
||||||
PostId,
|
|
||||||
UserId,
|
|
||||||
};
|
|
||||||
use actix::{prelude::*, Recipient};
|
use actix::{prelude::*, Recipient};
|
||||||
|
use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
|
||||||
|
use lemmy_utils::{CommunityId, ConnectionId, IPAddr, PostId, UserId};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Chat server sends this messages to session
|
/// Chat server sends this messages to session
|
||||||
|
|
Loading…
Reference in a new issue