1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-22 03:11:08 +00:00

fix frontend compilation

This commit is contained in:
Felix Ableitner 2024-01-18 12:38:31 +01:00
parent 9f4d20494e
commit f41cc01ad3
22 changed files with 120 additions and 119 deletions

View file

@ -1,17 +1,17 @@
use crate::backend::api::ResolveObject;
use crate::backend::database::article::DbArticleForm;
use crate::backend::database::conflict::{ApiConflict, DbConflict, DbConflictForm};
use crate::backend::database::conflict::{DbConflict, DbConflictForm};
use crate::backend::database::edit::DbEditForm;
use crate::backend::database::instance::DbInstance;
use crate::backend::database::MyDataHandle;
use crate::backend::error::MyResult;
use crate::backend::federation::activities::create_article::CreateArticle;
use crate::backend::federation::activities::submit_article_update;
use crate::backend::utils::generate_article_version;
use crate::common::EditVersion;
use crate::common::DbInstance;
use crate::common::GetArticleData;
use crate::common::LocalUserView;
use crate::common::{ApiConflict, ResolveObject};
use crate::common::{ArticleView, DbArticle, DbEdit};
use crate::common::{CreateArticleData, EditArticleData, EditVersion, ForkArticleData};
use activitypub_federation::config::Data;
use activitypub_federation::fetch::object_id::ObjectId;
use anyhow::anyhow;
@ -21,12 +21,6 @@ use axum::Form;
use axum::Json;
use axum_macros::debug_handler;
use diffy::create_patch;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
pub struct CreateArticleData {
pub title: String,
}
/// Create a new article with empty text, and federate it to followers.
#[debug_handler]
@ -56,20 +50,6 @@ pub(in crate::backend::api) async fn create_article(
Ok(Json(DbArticle::read_view(article.id, &data.db_connection)?))
}
#[derive(Deserialize, Serialize, Debug)]
pub struct EditArticleData {
/// Id of the article to edit
pub article_id: i32,
/// Full, new text of the article. A diff against `previous_version` is generated on the backend
/// side to handle conflicts.
pub new_text: String,
/// The version that this edit is based on, ie [DbArticle.latest_version] or
/// [ApiConflict.previous_version]
pub previous_version_id: EditVersion,
/// If you are resolving a conflict, pass the id to delete conflict from the database
pub resolve_conflict_id: Option<EditVersion>,
}
/// Edit an existing article (local or remote).
///
/// It gracefully handles the case where multiple users edit an article at the same time, by
@ -144,14 +124,6 @@ pub(in crate::backend::api) async fn get_article(
}
}
#[derive(Deserialize, Serialize)]
pub struct ForkArticleData {
// TODO: could add optional param new_title so there is no problem with title collision
// in case local article with same title exists. however that makes it harder to discover
// variants of same article.
pub article_id: i32,
}
/// Fork a remote article to local instance. This is useful if there are disagreements about
/// how an article should be edited.
#[debug_handler]

View file

@ -1,16 +1,14 @@
use crate::backend::api::ResolveObject;
use crate::backend::database::instance::{DbInstance, InstanceView};
use crate::backend::database::MyDataHandle;
use crate::backend::error::MyResult;
use crate::backend::federation::activities::follow::Follow;
use crate::common::LocalUserView;
use crate::common::{DbInstance, InstanceView, ResolveObject};
use crate::common::{FollowInstance, LocalUserView};
use activitypub_federation::config::Data;
use activitypub_federation::fetch::object_id::ObjectId;
use axum::extract::Query;
use axum::Extension;
use axum::{Form, Json};
use axum_macros::debug_handler;
use serde::{Deserialize, Serialize};
/// Retrieve the local instance info.
#[debug_handler]
@ -21,11 +19,6 @@ pub(in crate::backend::api) async fn get_local_instance(
Ok(Json(local_instance))
}
#[derive(Deserialize, Serialize, Debug)]
pub struct FollowInstance {
pub id: i32,
}
/// Make the local instance follow a given remote instance, to receive activities about new and
/// updated articles.
#[debug_handler]

View file

@ -6,11 +6,11 @@ use crate::backend::api::user::register_user;
use crate::backend::api::user::validate;
use crate::backend::api::user::{login_user, logout_user};
use crate::backend::api::user::{my_profile, AUTH_COOKIE};
use crate::backend::database::conflict::{ApiConflict, DbConflict};
use crate::backend::database::conflict::DbConflict;
use crate::backend::database::MyDataHandle;
use crate::backend::error::MyResult;
use crate::common::DbArticle;
use crate::common::LocalUserView;
use crate::common::{ApiConflict, DbArticle, SearchArticleData};
use activitypub_federation::config::Data;
use axum::extract::Query;
use axum::routing::{get, post};
@ -26,8 +26,6 @@ use axum_extra::extract::CookieJar;
use axum_macros::debug_handler;
use futures::future::try_join_all;
use log::warn;
use serde::{Deserialize, Serialize};
use url::Url;
pub mod article;
pub mod instance;
@ -70,11 +68,6 @@ async fn auth<B>(
Ok(response)
}
#[derive(Deserialize, Serialize)]
pub struct ResolveObject {
pub id: Url,
}
/// Get a list of all unresolved edit conflicts.
#[debug_handler]
async fn edit_conflicts(
@ -93,11 +86,6 @@ async fn edit_conflicts(
Ok(Json(conflicts))
}
#[derive(Deserialize, Serialize, Clone)]
pub struct SearchArticleData {
pub query: String,
}
/// Search articles for matching title or body text.
#[debug_handler]
async fn search_article(

View file

@ -3,10 +3,10 @@ use crate::backend::database::MyDataHandle;
use crate::backend::error::MyResult;
use crate::backend::federation::activities::submit_article_update;
use crate::backend::utils::generate_article_version;
use crate::common::DbArticle;
use crate::common::DbEdit;
use crate::common::DbLocalUser;
use crate::common::EditVersion;
use crate::common::{ApiConflict, DbArticle};
use activitypub_federation::config::Data;
use diesel::ExpressionMethods;
use diesel::{
@ -30,14 +30,6 @@ pub struct DbConflict {
pub previous_version_id: EditVersion,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct ApiConflict {
pub id: EditVersion,
pub three_way_merge: String,
pub article_id: i32,
pub previous_version_id: EditVersion,
}
#[derive(Debug, Clone, Insertable)]
#[diesel(table_name = conflict, check_for_backend(diesel::pg::Pg))]
pub struct DbConflictForm {

View file

@ -2,37 +2,19 @@ use crate::backend::database::schema::{instance, instance_follow};
use crate::backend::database::MyDataHandle;
use crate::backend::error::MyResult;
use crate::backend::federation::objects::articles_collection::DbArticleCollection;
use crate::common::DbPerson;
use crate::common::{DbInstance, DbPerson, InstanceView};
use activitypub_federation::config::Data;
use activitypub_federation::fetch::collection_id::CollectionId;
use activitypub_federation::fetch::object_id::ObjectId;
use chrono::{DateTime, Utc};
use diesel::ExpressionMethods;
use diesel::{
insert_into, AsChangeset, Identifiable, Insertable, JoinOnDsl, PgConnection, QueryDsl,
Queryable, RunQueryDsl, Selectable,
insert_into, AsChangeset, Insertable, JoinOnDsl, PgConnection, QueryDsl, RunQueryDsl,
};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::ops::DerefMut;
use std::sync::Mutex;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Queryable, Selectable, Identifiable)]
#[diesel(table_name = instance, check_for_backend(diesel::pg::Pg))]
pub struct DbInstance {
pub id: i32,
pub ap_id: ObjectId<DbInstance>,
pub articles_url: CollectionId<DbArticleCollection>,
pub inbox_url: String,
#[serde(skip)]
pub public_key: String,
#[serde(skip)]
pub private_key: Option<String>,
#[serde(skip)]
pub last_refreshed_at: DateTime<Utc>,
pub local: bool,
}
#[derive(Debug, Clone, Insertable, AsChangeset)]
#[diesel(table_name = instance, check_for_backend(diesel::pg::Pg))]
pub struct DbInstanceForm {
@ -45,14 +27,6 @@ pub struct DbInstanceForm {
pub local: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Queryable)]
#[diesel(table_name = article, check_for_backend(diesel::pg::Pg))]
pub struct InstanceView {
pub instance: DbInstance,
pub followers: Vec<DbPerson>,
pub following: Vec<DbInstance>,
}
impl DbInstance {
pub fn create(form: &DbInstanceForm, conn: &Mutex<PgConnection>) -> MyResult<Self> {
let mut conn = conn.lock().unwrap();

View file

@ -1,8 +1,8 @@
use crate::backend::database::instance::DbInstance;
use crate::backend::error::MyResult;
use crate::backend::federation::send_activity;
use crate::backend::utils::generate_activity_id;
use crate::backend::{database::MyDataHandle, federation::activities::follow::Follow};
use crate::common::DbInstance;
use activitypub_federation::traits::Actor;
use activitypub_federation::{
config::Data, fetch::object_id::ObjectId, kinds::activity::AcceptType, traits::ActivityHandler,

View file

@ -1,9 +1,9 @@
use crate::backend::database::instance::DbInstance;
use crate::backend::database::MyDataHandle;
use crate::backend::error::MyResult;
use crate::backend::federation::objects::article::ApubArticle;
use crate::backend::utils::generate_activity_id;
use crate::common::DbArticle;
use crate::common::DbInstance;
use activitypub_federation::kinds::activity::CreateType;
use activitypub_federation::{
config::Data,

View file

@ -1,9 +1,9 @@
use crate::backend::database::instance::DbInstance;
use crate::backend::error::MyResult;
use crate::backend::federation::send_activity;
use crate::backend::{
database::MyDataHandle, federation::activities::accept::Accept, generate_activity_id,
};
use crate::common::DbInstance;
use crate::common::DbPerson;
use activitypub_federation::{
config::Data,

View file

@ -1,9 +1,9 @@
use crate::backend::database::edit::DbEditForm;
use crate::backend::database::instance::DbInstance;
use crate::backend::database::MyDataHandle;
use crate::backend::error::Error;
use crate::backend::federation::activities::update_local_article::UpdateLocalArticle;
use crate::backend::federation::activities::update_remote_article::UpdateRemoteArticle;
use crate::common::DbInstance;
use crate::common::EditVersion;
use crate::common::{DbArticle, DbEdit};
use activitypub_federation::config::Data;

View file

@ -1,9 +1,9 @@
use crate::backend::database::conflict::{DbConflict, DbConflictForm};
use crate::backend::database::instance::DbInstance;
use crate::backend::database::MyDataHandle;
use crate::backend::error::MyResult;
use crate::backend::federation::objects::edit::ApubEdit;
use crate::backend::utils::generate_activity_id;
use crate::common::DbInstance;
use crate::common::EditVersion;
use activitypub_federation::kinds::activity::RejectType;
use activitypub_federation::{

View file

@ -2,8 +2,8 @@ use crate::backend::database::MyDataHandle;
use crate::backend::error::MyResult;
use crate::backend::federation::objects::article::ApubArticle;
use crate::backend::database::instance::DbInstance;
use crate::backend::utils::generate_activity_id;
use crate::common::DbInstance;
use activitypub_federation::kinds::activity::UpdateType;
use activitypub_federation::{
config::Data,

View file

@ -1,7 +1,6 @@
use crate::backend::database::MyDataHandle;
use crate::backend::error::MyResult;
use crate::backend::database::instance::DbInstance;
use crate::backend::federation::activities::reject::RejectEdit;
use crate::backend::federation::activities::update_local_article::UpdateLocalArticle;
use crate::backend::federation::objects::edit::ApubEdit;
@ -9,6 +8,7 @@ use crate::backend::federation::send_activity;
use crate::backend::utils::generate_activity_id;
use crate::common::DbArticle;
use crate::common::DbEdit;
use crate::common::DbInstance;
use activitypub_federation::kinds::activity::UpdateType;
use activitypub_federation::{
config::Data,

View file

@ -1,9 +1,9 @@
use crate::backend::database::article::DbArticleForm;
use crate::backend::database::instance::DbInstance;
use crate::backend::database::MyDataHandle;
use crate::backend::error::Error;
use crate::backend::federation::objects::edits_collection::DbEditCollection;
use crate::common::DbArticle;
use crate::common::DbInstance;
use crate::common::EditVersion;
use activitypub_federation::config::Data;
use activitypub_federation::fetch::collection_id::CollectionId;

View file

@ -1,7 +1,7 @@
use crate::backend::database::instance::DbInstance;
use crate::backend::database::MyDataHandle;
use crate::backend::error::Error;
use crate::backend::federation::objects::article::ApubArticle;
use crate::common::DbInstance;
use crate::common::DbArticle;
use activitypub_federation::kinds::collection::CollectionType;

View file

@ -3,8 +3,8 @@ use crate::backend::error::Error;
use crate::backend::federation::objects::edit::ApubEdit;
use crate::common::DbArticle;
use crate::backend::database::instance::DbInstance;
use crate::common::DbEdit;
use crate::common::DbInstance;
use activitypub_federation::kinds::collection::OrderedCollectionType;
use activitypub_federation::{
config::Data,

View file

@ -1,4 +1,4 @@
use crate::backend::database::instance::{DbInstance, DbInstanceForm};
use crate::backend::database::instance::DbInstanceForm;
use crate::backend::database::MyDataHandle;
use crate::backend::error::Error;
use crate::backend::federation::objects::articles_collection::DbArticleCollection;
@ -8,6 +8,7 @@ use activitypub_federation::fetch::collection_id::CollectionId;
use activitypub_federation::kinds::actor::ServiceType;
use crate::backend::error::MyResult;
use crate::common::DbInstance;
use activitypub_federation::traits::ActivityHandler;
use activitypub_federation::{
config::Data,

View file

@ -1,4 +1,3 @@
use crate::backend::database::instance::DbInstance;
use crate::backend::database::MyDataHandle;
use crate::backend::error::Error;
use crate::backend::error::MyResult;
@ -16,6 +15,7 @@ use crate::backend::federation::objects::edits_collection::{ApubEditCollection,
use crate::backend::federation::objects::instance::ApubInstance;
use crate::backend::federation::objects::user::ApubUser;
use crate::common::DbArticle;
use crate::common::DbInstance;
use crate::common::DbPerson;
use activitypub_federation::axum::inbox::{receive_activity, ActivityData};
use activitypub_federation::axum::json::FederationJson;

View file

@ -1,10 +1,10 @@
use crate::backend::database::article::DbArticleForm;
use crate::backend::database::instance::{DbInstance, DbInstanceForm};
use crate::backend::database::instance::DbInstanceForm;
use crate::backend::database::MyData;
use crate::backend::error::MyResult;
use crate::backend::federation::routes::federation_routes;
use crate::backend::utils::generate_activity_id;
use crate::common::DbArticle;
use crate::common::{DbArticle, DbInstance};
use crate::frontend::app::App;
use activitypub_federation::config::{FederationConfig, FederationMiddleware};
use activitypub_federation::fetch::collection_id::CollectionId;

View file

@ -1,10 +1,14 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use url::Url;
use uuid::Uuid;
#[cfg(feature = "ssr")]
use {
crate::backend::database::schema::{article, edit, local_user, person},
activitypub_federation::fetch::object_id::ObjectId,
crate::backend::{
database::schema::{article, edit, instance, local_user, person},
federation::objects::articles_collection::DbArticleCollection,
},
activitypub_federation::fetch::{collection_id::CollectionId, object_id::ObjectId},
diesel::{Identifiable, Queryable, Selectable},
};
@ -117,3 +121,85 @@ pub struct DbPerson {
pub last_refreshed_at: DateTime<Utc>,
pub local: bool,
}
#[derive(Deserialize, Serialize)]
pub struct CreateArticleData {
pub title: String,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct EditArticleData {
/// Id of the article to edit
pub article_id: i32,
/// Full, new text of the article. A diff against `previous_version` is generated on the backend
/// side to handle conflicts.
pub new_text: String,
/// The version that this edit is based on, ie [DbArticle.latest_version] or
/// [ApiConflict.previous_version]
pub previous_version_id: EditVersion,
/// If you are resolving a conflict, pass the id to delete conflict from the database
pub resolve_conflict_id: Option<EditVersion>,
}
#[derive(Deserialize, Serialize)]
pub struct ForkArticleData {
// TODO: could add optional param new_title so there is no problem with title collision
// in case local article with same title exists. however that makes it harder to discover
// variants of same article.
pub article_id: i32,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct FollowInstance {
pub id: i32,
}
#[derive(Deserialize, Serialize, Clone)]
pub struct SearchArticleData {
pub query: String,
}
#[derive(Deserialize, Serialize)]
pub struct ResolveObject {
pub id: Url,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct ApiConflict {
pub id: EditVersion,
pub three_way_merge: String,
pub article_id: i32,
pub previous_version_id: EditVersion,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Identifiable))]
#[cfg_attr(feature = "ssr", diesel(table_name = instance, check_for_backend(diesel::pg::Pg)))]
pub struct DbInstance {
pub id: i32,
#[cfg(feature = "ssr")]
pub ap_id: ObjectId<DbInstance>,
#[cfg(not(feature = "ssr"))]
pub ap_id: String,
#[cfg(feature = "ssr")]
pub articles_url: CollectionId<DbArticleCollection>,
#[cfg(not(feature = "ssr"))]
pub articles_url: String,
pub inbox_url: String,
#[serde(skip)]
pub public_key: String,
#[serde(skip)]
pub private_key: Option<String>,
#[serde(skip)]
pub last_refreshed_at: DateTime<Utc>,
pub local: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "ssr", derive(Queryable))]
#[cfg_attr(feature = "ssr", diesel(table_name = article, check_for_backend(diesel::pg::Pg)))]
pub struct InstanceView {
pub instance: DbInstance,
pub followers: Vec<DbPerson>,
pub following: Vec<DbInstance>,
}

View file

@ -1,11 +1,9 @@
use crate::backend::api::article::{CreateArticleData, EditArticleData, ForkArticleData};
use crate::backend::api::instance::FollowInstance;
use crate::backend::api::{ResolveObject, SearchArticleData};
use crate::backend::database::conflict::ApiConflict;
use crate::backend::database::instance::{DbInstance, InstanceView};
use crate::common::LocalUserView;
use crate::common::ApiConflict;
use crate::common::ResolveObject;
use crate::common::{ArticleView, LoginUserData, RegisterUserData};
use crate::common::{CreateArticleData, EditArticleData, ForkArticleData, LocalUserView};
use crate::common::{DbArticle, GetArticleData};
use crate::common::{DbInstance, FollowInstance, InstanceView, SearchArticleData};
use crate::frontend::error::MyResult;
use anyhow::anyhow;
use once_cell::sync::Lazy;

View file

@ -3,10 +3,8 @@ use ibis_lib::backend::start;
use ibis_lib::common::RegisterUserData;
use ibis_lib::frontend::api::ApiClient;
use ibis_lib::frontend::error::MyResult;
use reqwest::cookie::Jar;
use reqwest::ClientBuilder;
use std::env::current_dir;
use std::fs::create_dir_all;
use std::ops::Deref;

View file

@ -3,9 +3,8 @@ extern crate ibis_lib;
mod common;
use crate::common::{TestData, TEST_ARTICLE_DEFAULT_TEXT};
use ibis_lib::backend::api::article::{EditArticleData, ForkArticleData};
use ibis_lib::backend::api::SearchArticleData;
use ibis_lib::common::{ArticleView, GetArticleData};
use ibis_lib::common::SearchArticleData;
use ibis_lib::common::{ArticleView, EditArticleData, ForkArticleData, GetArticleData};
use ibis_lib::common::{LoginUserData, RegisterUserData};
use ibis_lib::frontend::error::MyResult;
use pretty_assertions::{assert_eq, assert_ne};