diff --git a/.env.example b/.env.example index 422c1bd..fc98965 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -DATABASE_URL="sqlite:///home/aprl/Documents/lysand-ap-layer/db.sqlite?mode=rwc" -LYSAND_DOMAIN="social.lysand.org" -API_DOMAIN="ap.lysand.org" +DATABASE_URL="sqlite:///home/aprl/Documents/versia-ap-layer/db.sqlite?mode=rwc" +LYSAND_DOMAIN="versia.social" +API_DOMAIN="ap.versia.social" RUST_LOG="debug" \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 0720bbf..f9bbc33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1930,7 +1930,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] -name = "lysand-ap-layer" +name = "versia-ap-layer" version = "0.1.0" dependencies = [ "activitypub_federation", diff --git a/Cargo.toml b/Cargo.toml index e8c24b4..4981d17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "lysand-ap-layer" +name = "versia-ap-layer" version = "0.1.0" edition = "2021" authors = ["April John "] license = "AGPL-3.0-or-later" -repository = "https://github.com/lysand-org/lysand-ap-layer" -description = "A compatibility layer between lysands official server and activitypub" +repository = "https://github.com/versia-pub/versia-ap-layer" +description = "A compatibility layer between versias official server and activitypub" [dependencies] tokio = { version = "1.20.0", features = ["rt", "macros"] } diff --git a/Changelog.md b/Changelog.md index e26e8c6..6ae90d1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,22 +1,22 @@ ## 2024-04-14, Version 0.1.0 ### Commits -- [[`51a708a1c3`](https://github.com/lysand-org/lysand-ap-layer/commit/51a708a1c3d1aa974deb148156c07dfe7e775a8c)] feat! AGPL3 + Contributor Covenant (April John) -- [[`cc663ffc9b`](https://github.com/lysand-org/lysand-ap-layer/commit/cc663ffc9b56b4b1a93ceaa2e488fc554e597790)] arbeiter (aprilthepink) -- [[`1e6c005698`](https://github.com/lysand-org/lysand-ap-layer/commit/1e6c005698df8c781c60abfb1bab94d0b968c4d9)] enable ttp sign (aprilthepink) -- [[`0060d8baa8`](https://github.com/lysand-org/lysand-ap-layer/commit/0060d8baa8b356d61d0aabfcd6b6f5143a47e8fa)] boop (aprilthepink) -- [[`522ecabd07`](https://github.com/lysand-org/lysand-ap-layer/commit/522ecabd078b7b35276f2aa4f255f967f0b958bf)] aaaa (aprilthepink) -- [[`e75b523bb3`](https://github.com/lysand-org/lysand-ap-layer/commit/e75b523bb3d74bcf696313a320c35caa6f78e225)] awa (aprilthepink) -- [[`76d20cb2ef`](https://github.com/lysand-org/lysand-ap-layer/commit/76d20cb2ef8b3ef3ebe68e5a58c6f7588597ad4e)] awa (aprilthepink) -- [[`4d3657132d`](https://github.com/lysand-org/lysand-ap-layer/commit/4d3657132d764e71f70878de1ee1a284427eb7bb)] mew (aprilthepink) -- [[`643dc59b4b`](https://github.com/lysand-org/lysand-ap-layer/commit/643dc59b4bb0d7da13daf8d6ef47f3e0f31d1500)] Use Action badge on readme (aprilthepink) -- [[`3f4618d4d2`](https://github.com/lysand-org/lysand-ap-layer/commit/3f4618d4d2291e16369fbb4ecddd35d6a841833e)] [feat] GH nix builds (aprilthepink) -- [[`9bc640aadc`](https://github.com/lysand-org/lysand-ap-layer/commit/9bc640aadcd2c02374fa195aed09452b4a3bb3ea)] [fix] format files (aprilthepink) -- [[`b90a332b3c`](https://github.com/lysand-org/lysand-ap-layer/commit/b90a332b3c1e23198d1fad3caddcc8b69dee6a4b)] basic AP (aprilthepink) -- [[`1c09eb793d`](https://github.com/lysand-org/lysand-ap-layer/commit/1c09eb793db0e9b29f3d45b044e269311420ed8b)] Rework readme (aprilthepink) -- [[`091b8efe8e`](https://github.com/lysand-org/lysand-ap-layer/commit/091b8efe8e0578304a81722d11e12db906c4edbc)] [feat]: basic nix dev enviroment (aprilthepink) -- [[`51c7a6d6a2`](https://github.com/lysand-org/lysand-ap-layer/commit/51c7a6d6a2054f6dafbbac70c6b41239e56e2fe9)] Removed mod entities from main.rs (Helba) -- [[`9a021e768d`](https://github.com/lysand-org/lysand-ap-layer/commit/9a021e768d62d4355324f9137e63ae279358ebed)] Create LICENSE (Helba) -- [[`9609c7ab83`](https://github.com/lysand-org/lysand-ap-layer/commit/9609c7ab83251ca31ded4f0589a7dac04ceca874)] initial commit (Helba) +- [[`51a708a1c3`](https://github.com/versia-pub/versia-ap-layer/commit/51a708a1c3d1aa974deb148156c07dfe7e775a8c)] feat! AGPL3 + Contributor Covenant (April John) +- [[`cc663ffc9b`](https://github.com/versia-pub/versia-ap-layer/commit/cc663ffc9b56b4b1a93ceaa2e488fc554e597790)] arbeiter (aprilthepink) +- [[`1e6c005698`](https://github.com/versia-pub/versia-ap-layer/commit/1e6c005698df8c781c60abfb1bab94d0b968c4d9)] enable ttp sign (aprilthepink) +- [[`0060d8baa8`](https://github.com/versia-pub/versia-ap-layer/commit/0060d8baa8b356d61d0aabfcd6b6f5143a47e8fa)] boop (aprilthepink) +- [[`522ecabd07`](https://github.com/versia-pub/versia-ap-layer/commit/522ecabd078b7b35276f2aa4f255f967f0b958bf)] aaaa (aprilthepink) +- [[`e75b523bb3`](https://github.com/versia-pub/versia-ap-layer/commit/e75b523bb3d74bcf696313a320c35caa6f78e225)] awa (aprilthepink) +- [[`76d20cb2ef`](https://github.com/versia-pub/versia-ap-layer/commit/76d20cb2ef8b3ef3ebe68e5a58c6f7588597ad4e)] awa (aprilthepink) +- [[`4d3657132d`](https://github.com/versia-pub/versia-ap-layer/commit/4d3657132d764e71f70878de1ee1a284427eb7bb)] mew (aprilthepink) +- [[`643dc59b4b`](https://github.com/versia-pub/versia-ap-layer/commit/643dc59b4bb0d7da13daf8d6ef47f3e0f31d1500)] Use Action badge on readme (aprilthepink) +- [[`3f4618d4d2`](https://github.com/versia-pub/versia-ap-layer/commit/3f4618d4d2291e16369fbb4ecddd35d6a841833e)] [feat] GH nix builds (aprilthepink) +- [[`9bc640aadc`](https://github.com/versia-pub/versia-ap-layer/commit/9bc640aadcd2c02374fa195aed09452b4a3bb3ea)] [fix] format files (aprilthepink) +- [[`b90a332b3c`](https://github.com/versia-pub/versia-ap-layer/commit/b90a332b3c1e23198d1fad3caddcc8b69dee6a4b)] basic AP (aprilthepink) +- [[`1c09eb793d`](https://github.com/versia-pub/versia-ap-layer/commit/1c09eb793db0e9b29f3d45b044e269311420ed8b)] Rework readme (aprilthepink) +- [[`091b8efe8e`](https://github.com/versia-pub/versia-ap-layer/commit/091b8efe8e0578304a81722d11e12db906c4edbc)] [feat]: basic nix dev enviroment (aprilthepink) +- [[`51c7a6d6a2`](https://github.com/versia-pub/versia-ap-layer/commit/51c7a6d6a2054f6dafbbac70c6b41239e56e2fe9)] Removed mod entities from main.rs (Helba) +- [[`9a021e768d`](https://github.com/versia-pub/versia-ap-layer/commit/9a021e768d62d4355324f9137e63ae279358ebed)] Create LICENSE (Helba) +- [[`9609c7ab83`](https://github.com/versia-pub/versia-ap-layer/commit/9609c7ab83251ca31ded4f0589a7dac04ceca874)] initial commit (Helba) ### Stats ```diff diff --git a/README.MD b/README.MD index fc8befe..1789fbe 100644 --- a/README.MD +++ b/README.MD @@ -1,13 +1,13 @@

- Lysand Logo + Versia Logo

-## Lysand ActivityPub Bridge +## Versia ActivityPub Bridge -[![Nix Flake actions](https://github.com/lysand-org/activitypub/actions/workflows/nix-flake.yml/badge.svg)](https://github.com/lysand-org/activitypub/actions/workflows/nix-flake.yml) +[![Nix Flake actions](https://github.com/versia-pub/activitypub/actions/workflows/nix-flake.yml/badge.svg)](https://github.com/versia-pub/activitypub/actions/workflows/nix-flake.yml) -**ActivityPub/ActivityStreams** compatibility layer for [**Lysand Server**](https://github.com/lysand-org/lysand). +**ActivityPub/ActivityStreams** compatibility layer for [**Versia Server**](https://github.com/versia-pub/versia). Designed as a microservice, runs as its own process and communicates with the main server via HTTP. @@ -41,7 +41,7 @@ docker build -t activitypub:latest . To run the docker image, use the [`docker-compose.yml`](./docker-compose.yml) file: ```bash -wget https://raw.githubusercontent.com/lysand-org/activitypub/main/docker-compose.yml +wget https://raw.githubusercontent.com/versia-pub/activitypub/main/docker-compose.yml docker-compose up -d ``` diff --git a/docker-compose.yml b/docker-compose.yml index b91e10b..76ff4a5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,4 +6,4 @@ services: - LISTEN=0.0.0.0:8080 ports: - 8080:8080 - image: ghcr.io/lysand-org/activitypub:main + image: ghcr.io/versia-pub/activitypub:main diff --git a/flake.nix b/flake.nix index 477930a..020f1c0 100644 --- a/flake.nix +++ b/flake.nix @@ -53,11 +53,11 @@ in { overlayAttrs = { - inherit (config.packages) lysand-ap-layer ls-ap-migration; + inherit (config.packages) versia-ap-layer ls-ap-migration; }; # Rust package - packages.default = config.packages.lysand-ap-layer; - packages.lysand-ap-layer = naersk'.buildPackage { + packages.default = config.packages.versia-ap-layer; + packages.versia-ap-layer = naersk'.buildPackage { inherit (cargoToml.package) name version; src = ./.; buildInputs = nonRustDeps; @@ -77,10 +77,10 @@ }; packages.ociImage = pkgs.dockerTools.buildLayeredImage { - name = "ghcr.io/lysand-org/activitypub"; + name = "ghcr.io/versia-pub/activitypub"; tag = "main"; contents = [ - config.packages.lysand-ap-layer + config.packages.versia-ap-layer config.packages.ls-ap-migration pkgs.bash ]; @@ -90,7 +90,7 @@ "${config.packages.ls-ap-migration}/bin/ls-ap-migration" "up" "&&" - "${config.packages.lysand-ap-layer}/bin/lysand-ap-layer" + "${config.packages.versia-ap-layer}/bin/versia-ap-layer" ]; ExposedPorts = { "8080/tcp" = { }; diff --git a/nix-bootstrap.sh b/nix-bootstrap.sh index 65f6b25..4eb2b0a 100755 --- a/nix-bootstrap.sh +++ b/nix-bootstrap.sh @@ -1,2 +1,2 @@ nix run .#ls-ap-migration -nix run .#lysand-ap-layer \ No newline at end of file +nix run .#versia-ap-layer \ No newline at end of file diff --git a/src/activities/follow.rs b/src/activities/follow.rs index 9649eef..179f208 100644 --- a/src/activities/follow.rs +++ b/src/activities/follow.rs @@ -17,7 +17,7 @@ use crate::{ post, prelude, user, }, error, - lysand::funcs::send_follow_accept_to_lysand, + versia::funcs::send_follow_accept_to_versia, utils::{generate_follow_accept_id, generate_random_object_id}, DB, }; @@ -116,7 +116,7 @@ impl ActivityHandler for Follow { } async fn receive(self, data: &Data) -> Result<(), Self::Error> { - //accept_follow(self, data).await?; TODO replace w/ lysand forward + //accept_follow(self, data).await?; TODO replace w/ versia forward Ok(()) } } @@ -184,20 +184,20 @@ async fn save_accept_follow( if query.is_none() { return Err(crate::error::Error(anyhow::anyhow!("oopsie woopise"))); } - let lysand_accept_id = uuid::Uuid::now_v7().to_string(); + let versia_accept_id = uuid::Uuid::now_v7().to_string(); // all values in the ActiveModel that are set, except the id, will be updated let active_query = follow_relation::ActiveModel { id: Set(query.unwrap().id), ap_accept_id: Set(Some(accept_activity.id.to_string())), ap_accept_json: Set(Some(serde_json::to_string(&accept_activity).unwrap())), - accept_id: Set(Some(lysand_accept_id)), + accept_id: Set(Some(versia_accept_id)), ..Default::default() }; // modify db entry let res = prelude::FollowRelation::update(active_query); let model = res.exec(db).await?; - let _ = send_follow_accept_to_lysand(model.clone()).await?; + let _ = send_follow_accept_to_versia(model.clone()).await?; Ok(model) } diff --git a/src/http.rs b/src/http.rs index c398315..838e949 100644 --- a/src/http.rs +++ b/src/http.rs @@ -2,9 +2,9 @@ use crate::{ database::StateHandle, entities::user, error::Error, - lysand::{ + versia::{ self, - conversion::{db_user_from_url, local_db_user_from_name, receive_lysand_note}, + conversion::{db_user_from_url, local_db_user_from_name, receive_versia_note}, }, objects::person::{DbUser, PersonAcceptedActivities}, utils::generate_user_id, @@ -45,12 +45,12 @@ pub fn listen(config: &FederationConfig) -> Result<(), Error> { Ok(()) } -pub fn lysand_inbox( - note: web::Json, +pub fn versia_inbox( + note: web::Json, id: web::Path, data: Data, ) -> Result { - tokio::spawn(receive_lysand_note(note.into_inner(), id.into_inner())); + tokio::spawn(receive_versia_note(note.into_inner(), id.into_inner())); Ok(HttpResponse::Created().finish()) } diff --git a/src/main.rs b/src/main.rs index bec2f0a..ca68ac9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,8 +15,8 @@ use clap::Parser; use database::Database; use entities::post; use http::{http_get_user, http_post_user_inbox, webfinger}; -use lysand::http::{ - create_activity, fetch_lysand_post, fetch_post, fetch_user, lysand_inbox, query_post, +use versia::http::{ + create_activity, fetch_versia_post, fetch_post, fetch_user, versia_inbox, query_post, }; use objects::person::{DbUser, Person}; use sea_orm::{ActiveModelTrait, DatabaseConnection, Set}; @@ -47,7 +47,7 @@ mod database; mod entities; mod error; mod http; -mod lysand; +mod versia; mod objects; mod utils; @@ -157,7 +157,7 @@ async fn follow_manually( Ok(HttpResponse::Ok().json(Response { health: true })) } -const DOMAIN_DEF: &str = "social.lysand.org"; +const DOMAIN_DEF: &str = "versia.social"; const LOCAL_USER_NAME: &str = "apservice"; lazy_static! { @@ -288,7 +288,7 @@ async fn main() -> actix_web::Result<(), anyhow::Error> { .wrap(prometheus.clone()) .wrap(FederationMiddleware::new(data.clone())) .service(post_manually) - .service(lysand_inbox) + .service(versia_inbox) .service(follow_manually) .route("/{user}", web::get().to(http_get_user)) .route("/{user}/inbox", web::post().to(http_post_user_inbox)) @@ -302,7 +302,7 @@ async fn main() -> actix_web::Result<(), anyhow::Error> { .service(fetch_user) .service(create_activity) .service(query_post) - .service(fetch_lysand_post) + .service(fetch_versia_post) }) .bind(SERVER_URL.to_string())? .workers(num_cpus::get()) diff --git a/src/objects/post.rs b/src/objects/post.rs index b62c6b2..ebe7faa 100644 --- a/src/objects/post.rs +++ b/src/objects/post.rs @@ -3,7 +3,7 @@ use crate::{ database::StateHandle, entities::{post, user}, error::Error, - lysand::conversion::db_user_from_url, + versia::conversion::db_user_from_url, objects::person::DbUser, utils::generate_object_id, }; diff --git a/src/utils.rs b/src/utils.rs index 5e9a30d..b29236c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -22,9 +22,9 @@ pub fn generate_follow_req_id(domain: &str, db_id: &str) -> Result Result { +pub fn generate_versia_post_url(domain: &str, db_id: &str) -> Result { Url::parse(&format!( - "https://{}/apbridge/lysand/object/{}", + "https://{}/apbridge/versia/object/{}", domain, db_id )) } diff --git a/src/lysand/conversion.rs b/src/versia/conversion.rs similarity index 94% rename from src/lysand/conversion.rs rename to src/versia/conversion.rs index ac5e0a5..371e595 100644 --- a/src/lysand/conversion.rs +++ b/src/versia/conversion.rs @@ -17,7 +17,7 @@ use crate::{ person::{AttachmentType, EndpointType, IconType, Person, TagType}, post::Mention, }, - utils::{generate_lysand_post_url, generate_object_id, generate_user_id}, + utils::{generate_versia_post_url, generate_object_id, generate_user_id}, API_DOMAIN, DB, FEDERATION_CONFIG, LOCAL_USER_NAME, LYSAND_DOMAIN, USERNAME, }; @@ -32,12 +32,12 @@ pub async fn fetch_user_from_url(url: Url) -> anyhow::Result().await?) } -pub async fn lysand_post_from_db( +pub async fn versia_post_from_db( post: entities::post::Model, ) -> anyhow::Result { let data = FEDERATION_CONFIG.get().unwrap(); let domain = data.domain(); - let url = generate_lysand_post_url(domain, &post.id)?; + let url = generate_versia_post_url(domain, &post.id)?; let creator = prelude::User::find() .filter(entities::user::Column::Id.eq(post.creator.clone())) .one(DB.get().unwrap()) @@ -60,7 +60,7 @@ pub async fn lysand_post_from_db( ContentEntry::from_string(post.content), ); let note = super::objects::Note { - rtype: super::objects::LysandType::Note, + rtype: super::objects::VersiaType::Note, id: uuid::Uuid::parse_str(&post.id)?, author: author.clone(), uri: url.clone(), @@ -81,30 +81,30 @@ pub async fn lysand_post_from_db( Ok(note) } -pub async fn lysand_user_from_db( +pub async fn versia_user_from_db( user: entities::user::Model, ) -> anyhow::Result { let url = Url::parse(&user.url)?; let ap = user.ap_json.unwrap(); let serialized_ap: crate::objects::person::Person = serde_json::from_str(&ap)?; - let inbox_url = Url::parse("https://ap.lysand.org/apbridge/lysand/inbox")?; + let inbox_url = Url::parse("https://ap.versia.social/apbridge/versia/inbox")?; let outbox_url = Url::parse( - ("https://ap.lysand.org/apbridge/lysand/outbox/".to_string() + &user.id).as_str(), + ("https://ap.versia.social/apbridge/versia/outbox/".to_string() + &user.id).as_str(), )?; let followers_url = Url::parse( - ("https://ap.lysand.org/apbridge/lysand/followers/".to_string() + &user.id).as_str(), + ("https://ap.versia.social/apbridge/versia/followers/".to_string() + &user.id).as_str(), )?; let following_url = Url::parse( - ("https://ap.lysand.org/apbridge/lysand/following/".to_string() + &user.id).as_str(), + ("https://ap.versia.social/apbridge/versia/following/".to_string() + &user.id).as_str(), )?; let featured_url = Url::parse( - ("https://ap.lysand.org/apbridge/lysand/featured/".to_string() + &user.id).as_str(), + ("https://ap.versia.social/apbridge/versia/featured/".to_string() + &user.id).as_str(), )?; let likes_url = Url::parse( - ("https://ap.lysand.org/apbridge/lysand/likes/".to_string() + &user.id).as_str(), + ("https://ap.versia.social/apbridge/versia/likes/".to_string() + &user.id).as_str(), )?; let dislikes_url = Url::parse( - ("https://ap.lysand.org/apbridge/lysand/dislikes/".to_string() + &user.id).as_str(), + ("https://ap.versia.social/apbridge/versia/dislikes/".to_string() + &user.id).as_str(), )?; let og_displayname_ref = user.name.clone(); let og_username_ref = user.username.clone(); @@ -206,7 +206,7 @@ pub async fn lysand_user_from_db( custom_emojis: emojis, }; let user = super::objects::User { - rtype: super::objects::LysandType::User, + rtype: super::objects::VersiaType::User, id: uuid::Uuid::parse_str(&user.id)?, uri: url.clone(), username: user.username, @@ -244,7 +244,7 @@ pub async fn option_content_format_text(opt: Option) -> Option anyhow::Result { if !url.domain().eq(&Some(LYSAND_DOMAIN.as_str())) { - return Err(anyhow!("not lysands domain")); + return Err(anyhow!("not versias domain")); } let str_url = url.to_string(); let post_res: Option = prelude::Post::find() @@ -256,7 +256,7 @@ pub async fn db_post_from_url(url: Url) -> anyhow::Result Ok(post) } else { let post = fetch_note_from_url(url.clone()).await?; - let res = receive_lysand_note(post, "https://ap.lysand.org/example".to_string()).await?; // TODO: Replace user id with actual user id + let res = receive_versia_note(post, "https://ap.versia.social/example".to_string()).await?; // TODO: Replace user id with actual user id Ok(res) } } @@ -292,7 +292,7 @@ pub async fn db_user_from_url(url: Url) -> anyhow::Result if !url.domain().eq(&Some(LYSAND_DOMAIN.as_str())) && !url.domain().eq(&Some(API_DOMAIN.as_str())) { - return Err(anyhow!("not lysands domain")); + return Err(anyhow!("not versias domain")); } let user_res: Option = prelude::User::find() .filter(entities::user::Column::Url.eq(url.to_string())) @@ -434,11 +434,11 @@ pub async fn fetch_note_from_url(url: Url) -> anyhow::Result().await?) } #[async_recursion] -pub async fn receive_lysand_note( +pub async fn receive_versia_note( note: Note, db_id: String, ) -> anyhow::Result { - let lysand_author: entities::user::Model = db_user_from_url(note.author.clone()).await?; + let versia_author: entities::user::Model = db_user_from_url(note.author.clone()).await?; let user_res = prelude::User::find_by_id(db_id) .one(DB.get().unwrap()) .await; @@ -559,7 +559,7 @@ pub async fn receive_lysand_note( } let post = entities::post::ActiveModel { id: Set(note.id.to_string()), - creator: Set(lysand_author.id.clone()), + creator: Set(versia_author.id.clone()), content: Set(ap_note.content.clone()), sensitive: Set(ap_note.sensitive.unwrap_or_default()), created_at: Set(Utc diff --git a/src/lysand/funcs.rs b/src/versia/funcs.rs similarity index 73% rename from src/lysand/funcs.rs rename to src/versia/funcs.rs index 68d2049..a3b3458 100644 --- a/src/lysand/funcs.rs +++ b/src/versia/funcs.rs @@ -9,12 +9,12 @@ use crate::{ }; use super::{ - conversion::{fetch_user_from_url, lysand_user_from_db}, + conversion::{fetch_user_from_url, versia_user_from_db}, objects::FollowResult, superx::request_client, }; -pub async fn send_follow_accept_to_lysand(model: follow_relation::Model) -> anyhow::Result<()> { +pub async fn send_follow_accept_to_versia(model: follow_relation::Model) -> anyhow::Result<()> { let request_client = request_client(); let db = DB.get().unwrap(); @@ -27,26 +27,26 @@ pub async fn send_follow_accept_to_lysand(model: follow_relation::Model) -> anyh .one(db) .await? .unwrap(); - let lysand_follower = fetch_user_from_url(Url::parse(&follower_model.url)?).await?; + let versia_follower = fetch_user_from_url(Url::parse(&follower_model.url)?).await?; let followee_model = prelude::User::find() .filter(user::Column::Id.eq(model.followee_id)) .one(db) .await? .unwrap(); - let lysand_followee = lysand_user_from_db(followee_model).await?; + let versia_followee = versia_user_from_db(followee_model).await?; let entity = FollowResult { - rtype: super::objects::LysandType::FollowAccept, + rtype: super::objects::VersiaType::FollowAccept, id, uri, created_at: OffsetDateTime::now_utc(), - author: lysand_followee.uri, - follower: lysand_follower.uri, + author: versia_followee.uri, + follower: versia_follower.uri, }; let request = request_client - .post(lysand_follower.inbox.as_str()) + .post(versia_follower.inbox.as_str()) .header("Content-Type", "application/json; charset=utf-8") .header("Accept", "application/json") .header("Date", entity.created_at.clone().to_string()) @@ -57,6 +57,6 @@ pub async fn send_follow_accept_to_lysand(model: follow_relation::Model) -> anyh if response.status().is_success() { Ok(()) } else { - Err(anyhow::anyhow!("Failed to send follow accept to Lysand")) + Err(anyhow::anyhow!("Failed to send follow accept to Versia")) } } diff --git a/src/lysand/http.rs b/src/versia/http.rs similarity index 88% rename from src/lysand/http.rs rename to src/versia/http.rs index 224657c..e94a3cf 100644 --- a/src/lysand/http.rs +++ b/src/versia/http.rs @@ -16,8 +16,8 @@ use crate::{ prelude, user, }, error, - lysand::{ - conversion::{lysand_post_from_db, lysand_user_from_db}, + versia::{ + conversion::{versia_post_from_db, versia_user_from_db}, inbox::inbox_entry, }, objects::{self, person::Person}, @@ -28,7 +28,7 @@ use crate::{ use super::conversion::db_user_from_url; #[derive(serde::Deserialize)] -struct LysandQuery { +struct VersiaQuery { // Post url url: Option, // User handle @@ -37,9 +37,9 @@ struct LysandQuery { user_url: Option, } -#[get("/apbridge/lysand/query")] +#[get("/apbridge/versia/query")] async fn query_post( - query: web::Query, + query: web::Query, state: web::Data, ) -> actix_web::Result { if query.url.is_none() && query.user.is_none() && query.user_url.is_none() { @@ -56,19 +56,19 @@ async fn query_post( webfinger_resolve_actor::(user.as_str(), &data.to_request_data()) .await?; println!("!!!!!!! DB USER GOT"); - let lysand_user = lysand_user_from_db(target).await?; + let versia_user = versia_user_from_db(target).await?; return Ok(HttpResponse::Ok() .content_type("application/json") - .json(lysand_user)); + .json(versia_user)); } if let Some(user) = query.user_url.clone() { - let lysand_user = lysand_url_to_user(user).await?; + let versia_user = versia_url_to_user(user).await?; return Ok(HttpResponse::Ok() .content_type("application/json") - .json(lysand_user)); + .json(versia_user)); } let opt_model = prelude::Post::find() @@ -86,11 +86,11 @@ async fn query_post( Ok(HttpResponse::Ok() .content_type("application/json") - .json(lysand_post_from_db(target).await?)) + .json(versia_post_from_db(target).await?)) } -#[post("/apbridge/lysand/inbox")] -async fn lysand_inbox( +#[post("/apbridge/versia/inbox")] +async fn versia_inbox( body: web::Bytes, state: web::Data, ) -> actix_web::Result { @@ -145,8 +145,8 @@ async fn fetch_user( .json(WithContext::new_default(deserialized_user))) } -#[get("/apbridge/lysand/object/{post}")] -async fn fetch_lysand_post( +#[get("/apbridge/versia/object/{post}")] +async fn fetch_versia_post( path: web::Path, state: web::Data, ) -> actix_web::Result { @@ -164,7 +164,7 @@ async fn fetch_lysand_post( Ok(HttpResponse::Ok() .content_type("application/json") - .json(lysand_post_from_db(post).await?)) + .json(versia_post_from_db(post).await?)) } #[get("/apbridge/create/{id}/{base64url}")] @@ -204,7 +204,7 @@ async fn create_activity( .json(create_with_context)) } -pub async fn lysand_url_to_user(url: Url) -> anyhow::Result { +pub async fn versia_url_to_user(url: Url) -> anyhow::Result { let db = DB.get().unwrap(); let data = FEDERATION_CONFIG.get().unwrap(); @@ -222,10 +222,10 @@ pub async fn lysand_url_to_user(url: Url) -> anyhow::Result anyhow::Result<(super::objects::User, user::Model)> { let db = DB.get().unwrap(); @@ -245,10 +245,10 @@ pub async fn lysand_url_to_user_and_model( .unwrap(); } - Ok((lysand_user_from_db(target.clone()).await?, target)) + Ok((versia_user_from_db(target.clone()).await?, target)) } -pub async fn main_lysand_url_to_user_and_model( +pub async fn main_versia_url_to_user_and_model( url: Url, ) -> anyhow::Result<(super::objects::User, user::Model)> { let db = DB.get().unwrap(); @@ -265,5 +265,5 @@ pub async fn main_lysand_url_to_user_and_model( target = db_user_from_url(url.clone()).await?; } - Ok((lysand_user_from_db(target.clone()).await?, target)) + Ok((versia_user_from_db(target.clone()).await?, target)) } diff --git a/src/lysand/inbox.rs b/src/versia/inbox.rs similarity index 92% rename from src/lysand/inbox.rs rename to src/versia/inbox.rs index 789002f..cbf29ca 100644 --- a/src/lysand/inbox.rs +++ b/src/versia/inbox.rs @@ -5,7 +5,7 @@ use crate::{ prelude::{self, FollowRelation}, user, }, - lysand::http::main_lysand_url_to_user_and_model, + versia::http::main_versia_url_to_user_and_model, utils::generate_follow_req_id, API_DOMAIN, DB, FEDERATION_CONFIG, }; @@ -19,9 +19,9 @@ use serde::Deserialize; use url::Url; use super::{ - conversion::lysand_user_from_db, - http::{lysand_url_to_user, lysand_url_to_user_and_model}, - objects::LysandType, + conversion::versia_user_from_db, + http::{versia_url_to_user, versia_url_to_user_and_model}, + objects::VersiaType, }; pub async fn inbox_entry(json: &str) -> Result<()> { @@ -30,7 +30,7 @@ pub async fn inbox_entry(json: &str) -> Result<()> { // Extract the "type" field from the JSON if let Some(json_type) = value.get("type") { - // Match the "type" field with the corresponding LysandType + // Match the "type" field with the corresponding VersiaType match json_type.as_str() { Some("Note") => { let note: super::objects::Note = serde_json::from_str(json)?; @@ -76,9 +76,9 @@ async fn follow_request(follow: super::objects::Follow) -> Result<()> { )); } let data = FEDERATION_CONFIG.get().unwrap(); - let author = main_lysand_url_to_user_and_model(follow.author.into()).await?; + let author = main_versia_url_to_user_and_model(follow.author.into()).await?; println!("Followee URL: {}", &follow.followee.to_string()); - let followee = lysand_url_to_user_and_model(follow.followee.into()).await?; + let followee = versia_url_to_user_and_model(follow.followee.into()).await?; let serial_ap_author = serde_json::from_str::( &(author.1.ap_json.clone()).unwrap(), )?; diff --git a/src/lysand/mod.rs b/src/versia/mod.rs similarity index 100% rename from src/lysand/mod.rs rename to src/versia/mod.rs diff --git a/src/lysand/objects.rs b/src/versia/objects.rs similarity index 92% rename from src/lysand/objects.rs rename to src/versia/objects.rs index 7b1b7a6..6984f4a 100644 --- a/src/lysand/objects.rs +++ b/src/versia/objects.rs @@ -22,7 +22,7 @@ const FORMAT: Iso8601<6651332276412969266533270467398074368> = Iso8601::< .encode() }, >; -time::serde::format_description!(iso_lysand, OffsetDateTime, FORMAT); +time::serde::format_description!(iso_versia, OffsetDateTime, FORMAT); fn sort_alphabetically( value: &T, @@ -36,7 +36,7 @@ fn sort_alphabetically( pub struct SortAlphabetically(#[serde(serialize_with = "sort_alphabetically")] pub T); #[derive(Debug, Serialize, Deserialize, Clone)] -pub enum LysandType { +pub enum VersiaType { User, Note, Patch, @@ -71,26 +71,26 @@ pub enum VisibilityType { } #[derive(Debug, Serialize, Deserialize, Clone)] -pub enum LysandExtensions { - #[serde(rename = "org.lysand:microblogging/Announce")] +pub enum VersiaExtensions { + #[serde(rename = "org.versia:microblogging/Announce")] Announce, - #[serde(rename = "org.lysand:custom_emojis")] + #[serde(rename = "org.versia:custom_emojis")] CustomEmojis, - #[serde(rename = "org.lysand:reactions/Reaction")] + #[serde(rename = "org.versia:reactions/Reaction")] Reaction, - #[serde(rename = "org.lysand:reactions")] + #[serde(rename = "org.versia:reactions")] Reactions, - #[serde(rename = "org.lysand:polls")] + #[serde(rename = "org.versia:polls")] Polls, - #[serde(rename = "org.lysand:is_cat")] + #[serde(rename = "org.versia:is_cat")] IsCat, - #[serde(rename = "org.lysand:server_endorsement/Endorsement")] + #[serde(rename = "org.versia:server_endorsement/Endorsement")] Endorsement, - #[serde(rename = "org.lysand:server_endorsement")] + #[serde(rename = "org.versia:server_endorsement")] EndorsementCollection, - #[serde(rename = "org.lysand:reports/Report")] + #[serde(rename = "org.versia:reports/Report")] Report, - #[serde(rename = "org.lysand:vanity")] + #[serde(rename = "org.versia:vanity")] Vanity, } @@ -254,10 +254,10 @@ impl ContentEntry { pub struct User { pub public_key: PublicKey, #[serde(rename = "type")] - pub rtype: LysandType, + pub rtype: VersiaType, pub id: Uuid, pub uri: Url, - #[serde(with = "iso_lysand")] + #[serde(with = "iso_versia")] pub created_at: OffsetDateTime, #[serde(skip_serializing_if = "Option::is_none")] pub display_name: Option, @@ -284,7 +284,7 @@ pub struct User { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ExtensionSpecs { - #[serde(rename = "org.lysand:custom_emojis")] + #[serde(rename = "org.versia:custom_emojis")] #[serde(skip_serializing_if = "Option::is_none")] pub custom_emojis: Option, } @@ -321,11 +321,11 @@ pub struct LinkPreview { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Note { #[serde(rename = "type")] - pub rtype: LysandType, + pub rtype: VersiaType, pub id: Uuid, pub uri: Url, pub author: Url, - #[serde(with = "iso_lysand")] + #[serde(with = "iso_versia")] pub created_at: OffsetDateTime, #[serde(skip_serializing_if = "Option::is_none")] pub category: Option, @@ -357,13 +357,13 @@ pub struct Note { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Patch { #[serde(rename = "type")] - pub rtype: LysandType, + pub rtype: VersiaType, pub id: Uuid, pub uri: Url, pub author: Url, - #[serde(with = "iso_lysand")] + #[serde(with = "iso_versia")] pub created_at: OffsetDateTime, - #[serde(with = "iso_lysand")] + #[serde(with = "iso_versia")] pub patched_at: OffsetDateTime, #[serde(skip_serializing_if = "Option::is_none")] pub category: Option, @@ -406,11 +406,11 @@ pub struct Outbox { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Follow { #[serde(rename = "type")] - pub rtype: LysandType, + pub rtype: VersiaType, pub id: Uuid, pub uri: Url, pub author: Url, - #[serde(with = "iso_lysand")] + #[serde(with = "iso_versia")] pub created_at: OffsetDateTime, pub followee: Url, } @@ -418,11 +418,11 @@ pub struct Follow { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct FollowResult { #[serde(rename = "type")] - pub rtype: LysandType, + pub rtype: VersiaType, pub id: Uuid, pub uri: Url, pub author: Url, - #[serde(with = "iso_lysand")] + #[serde(with = "iso_versia")] pub created_at: OffsetDateTime, pub follower: Url, } diff --git a/src/lysand/superx.rs b/src/versia/superx.rs similarity index 81% rename from src/lysand/superx.rs rename to src/versia/superx.rs index a7843de..714ca94 100644 --- a/src/lysand/superx.rs +++ b/src/versia/superx.rs @@ -10,15 +10,15 @@ pub async fn serialize_user(user: super::objects::User) -> anyhow::Result anyhow::Result { - let lysand_type: super::objects::LysandType = serde_json::from_str(&data)?; - Ok(lysand_type) +pub async fn deserialize_versia_type(data: String) -> anyhow::Result { + let versia_type: super::objects::VersiaType = serde_json::from_str(&data)?; + Ok(versia_type) } -pub async fn serialize_lysand_type( - lysand_type: super::objects::LysandType, +pub async fn serialize_versia_type( + versia_type: super::objects::VersiaType, ) -> anyhow::Result { - let data = serde_json::to_string(&lysand_type)?; + let data = serde_json::to_string(&versia_type)?; Ok(data) } diff --git a/src/lysand/test.rs b/src/versia/test.rs similarity index 82% rename from src/lysand/test.rs rename to src/versia/test.rs index 556f4bc..dfae98a 100644 --- a/src/lysand/test.rs +++ b/src/versia/test.rs @@ -1,4 +1,4 @@ -use crate::lysand::objects::SortAlphabetically; +use crate::versia::objects::SortAlphabetically; use super::superx::request_client; @@ -6,7 +6,7 @@ use super::superx::request_client; async fn test_user_serial() { let client = request_client(); let response = client - .get("https://social.lysand.org/users/018ec082-0ae1-761c-b2c5-22275a611771") + .get("https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771") .send() .await .unwrap(); @@ -25,7 +25,7 @@ pub async fn main() -> anyhow::Result<()> { println!("Requesting user"); let response = client - .get("https://social.lysand.org/users/018ec082-0ae1-761c-b2c5-22275a611771") + .get("https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771") .send() .await?; println!("Response: {:?}", response); @@ -50,9 +50,9 @@ pub async fn main() -> anyhow::Result<()> { println!("\n\n\nas AP:"); for item in outbox.items { - let ap_item = super::conversion::receive_lysand_note( + let ap_item = super::conversion::receive_versia_note( item, - "https://ap.lysand.org/example".to_string(), + "https://ap.versia.social/example".to_string(), ) .await?; println!("{:#?}", ap_item);