From c036a26ea266f3235a6660f6314389b416879a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Mon, 19 Feb 2024 23:32:39 +0800 Subject: [PATCH] feat: implement fep-4adb (#15) --- FEDERATION.md | 1 + crates/api_apub/src/users/user.rs | 22 ++++++++++++++++++++-- crates/apub/src/actors/db_user.rs | 6 +++++- crates/apub/src/actors/service.rs | 4 ++++ docs/src/others/federation.md | 1 + 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/FEDERATION.md b/FEDERATION.md index 77d08daa..5118d36f 100644 --- a/FEDERATION.md +++ b/FEDERATION.md @@ -13,6 +13,7 @@ - [FEP-67ff: FEDERATION.md](https://codeberg.org/fediverse/fep/src/branch/main/fep/67ff/fep-67ff.md) - [FEP-f1d5: NodeInfo in Fediverse Software](https://codeberg.org/fediverse/fep/src/branch/main/fep/f1d5/fep-f1d5.md) - [FEP-fffd: Proxy Objects](https://codeberg.org/fediverse/fep/src/branch/main/fep/fffd/fep-fffd.md) +- [FEP-4adb: Dereferencing identifiers with webfinger](https://codeberg.org/fediverse/fep/src/branch/main/fep/4adb/fep-4adb.md) ## ActivityPub diff --git a/crates/api_apub/src/users/user.rs b/crates/api_apub/src/users/user.rs index c7e14ec0..63767e5d 100644 --- a/crates/api_apub/src/users/user.rs +++ b/crates/api_apub/src/users/user.rs @@ -16,7 +16,7 @@ use hatsu_db_schema::prelude::User; use hatsu_utils::{AppData, AppError}; use sea_orm::EntityTrait; // use serde::Deserialize; -use serde_json::Value; +use serde_json::{json, Value}; // #[derive(TypedPath, Deserialize)] // #[typed_path("/u/:name")] @@ -52,11 +52,29 @@ pub async fn user( let url = hatsu_utils::url::generate_user_url(data.domain(), &name)?; // "@context": [ // "https://www.w3.org/ns/activitystreams", - // "https://w3id.org/security/v1" + // "https://w3id.org/security/v1", + // { + // "xrd": "http://docs.oasis-open.org/ns/xri/xrd-1.0#", + // "aliases": { + // "@id": "xrd:Alias", + // "@type": "@id", + // "@container": "@list" + // } + // } // ] let context = vec![ Value::String(context().to_string()), Value::String(security().to_string()), + // FEP-4adb + // https://github.com/importantimport/hatsu/issues/15 + json!({ + "xrd": "http://docs.oasis-open.org/ns/xri/xrd-1.0#", + "aliases": { + "@id": "xrd:Alias", + "@type": "@id", + "@container": "@list" + }, + }) ]; match User::find_by_id(&url.to_string()).one(&data.conn).await? { diff --git a/crates/apub/src/actors/db_user.rs b/crates/apub/src/actors/db_user.rs index 9a4a827c..eaff1fbd 100644 --- a/crates/apub/src/actors/db_user.rs +++ b/crates/apub/src/actors/db_user.rs @@ -112,7 +112,7 @@ impl Object for ApubUser { Ok(user.into()) } - async fn into_json(self, _data: &Data) -> Result { + async fn into_json(self, data: &Data) -> Result { Ok(Service { kind: ServiceType::Service.to_string(), name: self.name.clone(), @@ -133,6 +133,10 @@ impl Object for ApubUser { outbox: Url::parse(&self.outbox)?, followers: Url::parse(&self.followers)?, following: Url::parse(&self.following)?, + // FEP-4adb + // https://github.com/importantimport/hatsu/issues/15 + // TODO: customize via _hatsu.aliases + aliases: Some(vec![format!("acct:{}@{}", &self.preferred_username, &self.preferred_username), format!("acct:{}@{}", &self.preferred_username, data.domain())]), public_key: self.public_key(), }) } diff --git a/crates/apub/src/actors/service.rs b/crates/apub/src/actors/service.rs index adff4b0f..7d071340 100644 --- a/crates/apub/src/actors/service.rs +++ b/crates/apub/src/actors/service.rs @@ -48,6 +48,10 @@ pub struct Service { pub followers: Url, // 正在关注 pub following: Url, + /// FEP-4adb + /// https://github.com/importantimport/hatsu/issues/15 + #[serde(skip_serializing_if = "Option::is_none")] + pub aliases: Option>, // 公钥 #[schema(value_type = PublicKeySchema)] pub public_key: PublicKey, diff --git a/docs/src/others/federation.md b/docs/src/others/federation.md index 77d08daa..5118d36f 100644 --- a/docs/src/others/federation.md +++ b/docs/src/others/federation.md @@ -13,6 +13,7 @@ - [FEP-67ff: FEDERATION.md](https://codeberg.org/fediverse/fep/src/branch/main/fep/67ff/fep-67ff.md) - [FEP-f1d5: NodeInfo in Fediverse Software](https://codeberg.org/fediverse/fep/src/branch/main/fep/f1d5/fep-f1d5.md) - [FEP-fffd: Proxy Objects](https://codeberg.org/fediverse/fep/src/branch/main/fep/fffd/fep-fffd.md) +- [FEP-4adb: Dereferencing identifiers with webfinger](https://codeberg.org/fediverse/fep/src/branch/main/fep/4adb/fep-4adb.md) ## ActivityPub