mirror of
https://github.com/nullishamy/ferri.git
synced 2025-06-28 00:54:17 +00:00
feat: http wrapper, start type rewrite, add nextest
This commit is contained in:
parent
9bc6c12392
commit
d59660da37
18 changed files with 369 additions and 144 deletions
|
@ -12,8 +12,8 @@ uuid = { workspace = true }
|
|||
rand = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
base64 = "0.22.1"
|
||||
rsa = { version = "0.9.8", features = ["sha2"] }
|
||||
url = "2.5.4"
|
||||
serde_json = "1.0.140"
|
|
@ -3,7 +3,7 @@ use chrono::{DateTime, Utc};
|
|||
use serde::Serialize;
|
||||
use sqlx::Sqlite;
|
||||
|
||||
const POST_TYPE: &str = "Post";
|
||||
const POST_TYPE: &str = "Note";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Post {
|
||||
|
|
|
@ -42,6 +42,9 @@ impl RequestQueue {
|
|||
let recv = self.recv;
|
||||
|
||||
while let Ok(req) = recv.recv() {
|
||||
// FIXME: When we make this do async things we will need to add tokio and
|
||||
// use proper async handled spans as the enter/drop won't work.
|
||||
// See inbox.rs for how we handle that.
|
||||
let s = span!(Level::INFO, "queue", queue_name = self.name);
|
||||
let _enter = s.enter();
|
||||
|
||||
|
|
|
@ -106,9 +106,10 @@ impl User {
|
|||
"#,
|
||||
username
|
||||
)
|
||||
.fetch_one(conn)
|
||||
.await
|
||||
.unwrap();
|
||||
.fetch_one(conn)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
User {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
pub mod ap;
|
||||
pub mod config;
|
||||
mod types_rewrite;
|
||||
|
||||
use rand::{Rng, distributions::Alphanumeric};
|
||||
|
||||
pub fn gen_token(len: usize) -> String {
|
||||
|
|
28
ferri-main/src/types_rewrite/convert.rs
Normal file
28
ferri-main/src/types_rewrite/convert.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use crate::types_rewrite::api;
|
||||
use crate::types_rewrite::ap;
|
||||
use crate::types_rewrite::db;
|
||||
|
||||
use crate::types_rewrite::{Object, as_context};
|
||||
|
||||
impl From<db::Actor> for ap::Actor {
|
||||
fn from(val: db::Actor) -> ap::Actor {
|
||||
ap::Actor {
|
||||
obj: Object {
|
||||
context: as_context(),
|
||||
id: val.id
|
||||
},
|
||||
inbox: val.inbox,
|
||||
outbox: val.outbox
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ap::Actor> for db::Actor {
|
||||
fn from(val: ap::Actor) -> db::Actor {
|
||||
db::Actor {
|
||||
id: val.obj.id,
|
||||
inbox: val.inbox,
|
||||
outbox: val.outbox
|
||||
}
|
||||
}
|
||||
}
|
87
ferri-main/src/types_rewrite/mod.rs
Normal file
87
ferri-main/src/types_rewrite/mod.rs
Normal file
|
@ -0,0 +1,87 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
|
||||
mod convert;
|
||||
pub use convert::*;
|
||||
|
||||
pub const AS_CONTEXT_RAW: &'static str = "https://www.w3.org/ns/activitystreams";
|
||||
pub fn as_context() -> ObjectContext {
|
||||
ObjectContext::Str(AS_CONTEXT_RAW.to_string())
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
pub enum ObjectContext {
|
||||
Str(String),
|
||||
Vec(Vec<serde_json::Value>),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||
pub struct ObjectUri(String);
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||
pub struct Object {
|
||||
#[serde(rename = "@context")]
|
||||
context: ObjectContext,
|
||||
id: ObjectUri,
|
||||
}
|
||||
|
||||
pub mod db {
|
||||
use serde::{Serialize, Deserialize};
|
||||
use super::*;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||
pub struct Actor {
|
||||
pub id: ObjectUri,
|
||||
pub inbox: String,
|
||||
pub outbox: String,
|
||||
}
|
||||
}
|
||||
|
||||
pub mod ap {
|
||||
use serde::{Serialize, Deserialize};
|
||||
use super::*;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||
pub struct Actor {
|
||||
#[serde(flatten)]
|
||||
pub obj: Object,
|
||||
|
||||
pub inbox: String,
|
||||
pub outbox: String,
|
||||
}
|
||||
}
|
||||
|
||||
pub mod api {
|
||||
use serde::{Serialize, Deserialize};
|
||||
use super::*;
|
||||
|
||||
// API will not really use actors so treat them as DB actors
|
||||
// until we require specificity
|
||||
pub type Actor = db::Actor;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn ap_actor_to_db() {
|
||||
let domain = "https://example.com";
|
||||
let ap = ap::Actor {
|
||||
obj: Object {
|
||||
context: as_context(),
|
||||
id: ObjectUri(format!("{}/users/sample", domain)),
|
||||
},
|
||||
inbox: format!("{}/users/sample/inbox", domain),
|
||||
outbox: format!("{}/users/sample/outbox", domain),
|
||||
};
|
||||
|
||||
let db: db::Actor = ap.into();
|
||||
|
||||
assert_eq!(db, db::Actor {
|
||||
id: ObjectUri("https://example.com/users/sample".to_string()),
|
||||
inbox: "https://example.com/users/sample/inbox".to_string(),
|
||||
outbox: "https://example.com/users/sample/outbox".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue