diff --git a/.dev/Caddyfile b/.dev/Caddyfile
index 546372f..c302e22 100644
--- a/.dev/Caddyfile
+++ b/.dev/Caddyfile
@@ -15,6 +15,10 @@ nattyarch.local {
reverse_proxy 127.0.0.1:4939
}
+ handle /mag/* {
+ reverse_proxy 127.0.0.1:4939
+ }
+
@render_html {
not path /api* /proxy* /files* /avatar* /identicon* /streaming
header Accept text/html*
diff --git a/Cargo.lock b/Cargo.lock
index 624db9e..72ad8ca 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -125,6 +125,7 @@ checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39"
dependencies = [
"async-trait",
"axum-core",
+ "axum-macros",
"bitflags",
"bytes",
"futures-util",
@@ -167,6 +168,18 @@ dependencies = [
"tower-service",
]
+[[package]]
+name = "axum-macros"
+version = "0.3.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cdca6a10ecad987bda04e95606ef85a5417dcaac1a78455242d72e031e2b6b62"
+dependencies = [
+ "heck 0.4.1",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.16",
+]
+
[[package]]
name = "bae"
version = "0.1.7"
@@ -325,6 +338,42 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
+[[package]]
+name = "cached"
+version = "0.44.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b195e4fbc4b6862bbd065b991a34750399c119797efff72492f28a5864de8700"
+dependencies = [
+ "async-trait",
+ "cached_proc_macro",
+ "cached_proc_macro_types",
+ "futures",
+ "hashbrown 0.13.2",
+ "instant",
+ "once_cell",
+ "thiserror",
+ "tokio",
+]
+
+[[package]]
+name = "cached_proc_macro"
+version = "0.17.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b48814962d2fd604c50d2b9433c2a41a0ab567779ee2c02f7fba6eca1221f082"
+dependencies = [
+ "cached_proc_macro_types",
+ "darling",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "cached_proc_macro_types"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663"
+
[[package]]
name = "cc"
version = "1.0.79"
@@ -419,6 +468,20 @@ dependencies = [
"os_str_bytes",
]
+[[package]]
+name = "combine"
+version = "4.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4"
+dependencies = [
+ "bytes",
+ "futures-core",
+ "memchr",
+ "pin-project-lite",
+ "tokio",
+ "tokio-util",
+]
+
[[package]]
name = "core-foundation-sys"
version = "0.8.4"
@@ -463,6 +526,41 @@ dependencies = [
"typenum",
]
+[[package]]
+name = "darling"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
+dependencies = [
+ "darling_core",
+ "darling_macro",
+]
+
+[[package]]
+name = "darling_core"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "strsim",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "darling_macro"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
+dependencies = [
+ "darling_core",
+ "quote",
+ "syn 1.0.109",
+]
+
[[package]]
name = "deunicode"
version = "0.4.3"
@@ -594,6 +692,17 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
+[[package]]
+name = "futures-macro"
+version = "0.3.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.16",
+]
+
[[package]]
name = "futures-sink"
version = "0.3.28"
@@ -615,6 +724,7 @@ dependencies = [
"futures-channel",
"futures-core",
"futures-io",
+ "futures-macro",
"futures-sink",
"futures-task",
"memchr",
@@ -883,6 +993,12 @@ dependencies = [
"cc",
]
+[[package]]
+name = "ident_case"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
+
[[package]]
name = "idna"
version = "0.3.0"
@@ -989,7 +1105,11 @@ name = "magnetar"
version = "0.2.0"
dependencies = [
"axum",
+ "cached",
+ "cfg-if",
+ "chrono",
"dotenvy",
+ "headers",
"hyper",
"magnetar_calckey_model",
"magnetar_common",
@@ -1000,6 +1120,7 @@ dependencies = [
"percent-encoding",
"serde",
"serde_json",
+ "strum",
"thiserror",
"tokio",
"toml 0.7.4",
@@ -1041,12 +1162,17 @@ dependencies = [
"ck",
"dotenvy",
"ext_calckey_model_migration",
+ "futures-core",
+ "futures-util",
"magnetar_common",
+ "redis",
"sea-orm",
"serde",
"serde_json",
+ "strum",
"thiserror",
"tokio",
+ "tokio-util",
"tracing",
]
@@ -1571,6 +1697,29 @@ dependencies = [
"getrandom",
]
+[[package]]
+name = "redis"
+version = "0.23.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ff5d95dd18a4d76650f0c2607ed8ebdbf63baf9cb934e1c233cd220c694db1d7"
+dependencies = [
+ "async-trait",
+ "bytes",
+ "combine",
+ "futures-util",
+ "itoa",
+ "percent-encoding",
+ "pin-project-lite",
+ "ryu",
+ "serde",
+ "serde_json",
+ "sha1_smol",
+ "socket2",
+ "tokio",
+ "tokio-util",
+ "url",
+]
+
[[package]]
name = "redox_syscall"
version = "0.2.16"
@@ -1992,6 +2141,12 @@ dependencies = [
"digest",
]
+[[package]]
+name = "sha1_smol"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
+
[[package]]
name = "sha2"
version = "0.10.6"
@@ -2192,6 +2347,34 @@ dependencies = [
"unicode-normalization",
]
+[[package]]
+name = "strsim"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
+[[package]]
+name = "strum"
+version = "0.25.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
+dependencies = [
+ "strum_macros",
+]
+
+[[package]]
+name = "strum_macros"
+version = "0.25.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6069ca09d878a33f883cc06aaa9718ede171841d3832450354410b718b097232"
+dependencies = [
+ "heck 0.4.1",
+ "proc-macro2",
+ "quote",
+ "rustversion",
+ "syn 2.0.16",
+]
+
[[package]]
name = "subtle"
version = "2.4.1"
diff --git a/Cargo.toml b/Cargo.toml
index de549d9..6b6540f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,19 +22,27 @@ edition = "2021"
[workspace.dependencies]
axum = "0.6"
+cached = "0.44"
+cfg-if = "1"
chrono = "0.4"
dotenvy = "0.15"
+futures-core = "0.3"
+futures-util = "0.3"
+headers = "0.3"
hyper = "0.14"
log = "0.4"
miette = "5.9"
percent-encoding = "2.2"
+redis = "0.23"
sea-orm = "0.11"
sea-orm-migration = "0.11"
serde = "1"
serde_json = "1"
+strum = "0.25"
tera = { version = "1", default-features = false }
thiserror = "1"
tokio = "1.24"
+tokio-util = "0.7"
toml = "0.7"
tower = "0.4"
tower-http = "0.4"
@@ -50,9 +58,12 @@ magnetar_webfinger = { path = "./ext_webfinger" }
magnetar_nodeinfo = { path = "./ext_nodeinfo" }
magnetar_calckey_model = { path = "./ext_calckey_model" }
+cached = { workspace = true }
+chrono = { workspace = true }
dotenvy = { workspace = true }
-axum = { workspace = true }
+axum = { workspace = true, features = ["macros"] }
+headers = { workspace = true }
hyper = { workspace = true, features = ["full"] }
tokio = { workspace = true, features = ["full"] }
tower = { workspace = true }
@@ -61,12 +72,14 @@ tower-http = { workspace = true, features = ["cors", "trace", "fs"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing = { workspace = true }
+cfg-if = { workspace = true }
+
+strum = { workspace = true, features = ["derive"] }
thiserror = { workspace = true }
miette = { workspace = true }
percent-encoding = { workspace = true }
serde = { workspace = true, features = ["derive"] }
+serde_json = { workspace = true }
toml = { workspace = true }
-
-serde_json = { workspace = true }
\ No newline at end of file
diff --git a/config/default.toml b/config/default.toml
index 662b777..07cd085 100644
--- a/config/default.toml
+++ b/config/default.toml
@@ -58,10 +58,14 @@
# ----------------------------------[ DATA ]-----------------------------------
# [REQUIRED]
-# An URL pointing to a Postgres database, with a Calckey database
+# An URI pointing to a Postgres database, with a Calckey database
# Environment variables: MAG_C_DATABASE_URL, DATABASE_URL
# data.database_url = "postgres://username:password@db:5432/calckey"
+# [REQUIRED]
+# An URI pointing to a Redis instance
+# Environment variables: MAG_C_REDIS_URL
+# data.redis_url = "redis://redis:6379"
# -------------------------------[ FEDERATION ]--------------------------------
diff --git a/ext_calckey_model/Cargo.toml b/ext_calckey_model/Cargo.toml
index e8646cf..12e6a72 100644
--- a/ext_calckey_model/Cargo.toml
+++ b/ext_calckey_model/Cargo.toml
@@ -13,10 +13,15 @@ ext_calckey_model_migration = { path = "./migration" }
magnetar_common = { path = "../magnetar_common" }
dotenvy = { workspace = true}
+futures-core = { workspace = true }
+futures-util = { workspace = true }
tokio = { workspace = true, features = ["full"] }
+tokio-util = { workspace = true}
+redis = { workspace = true, features = ["tokio-comp", "json", "serde_json"]}
sea-orm = { workspace = true, features = ["sqlx-postgres", "runtime-tokio-rustls", "macros"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
+strum = { workspace = true }
chrono = { workspace = true }
tracing = { workspace = true }
thiserror = { workspace = true }
\ No newline at end of file
diff --git a/ext_calckey_model/src/lib.rs b/ext_calckey_model/src/lib.rs
index 6f4d0c7..ee74e8e 100644
--- a/ext_calckey_model/src/lib.rs
+++ b/ext_calckey_model/src/lib.rs
@@ -1,8 +1,21 @@
-use ck::user;
+use chrono::Utc;
+pub use ck::*;
use ext_calckey_model_migration::{Migrator, MigratorTrait};
-use sea_orm::{ColumnTrait, ConnectOptions, DatabaseConnection, EntityTrait, QueryFilter};
+use futures_util::StreamExt;
+use redis::IntoConnectionInfo;
+use sea_orm::ActiveValue::Set;
+use sea_orm::{
+ ColumnTrait, ConnectOptions, DatabaseConnection, DbErr, EntityTrait, QueryFilter, QueryOrder,
+ TransactionTrait,
+};
+use serde::{Deserialize, Serialize};
+use std::future::Future;
+use strum::IntoStaticStr;
use thiserror::Error;
+use tokio::select;
+use tokio_util::sync::CancellationToken;
use tracing::log::LevelFilter;
+use tracing::{error, info};
#[derive(Debug)]
pub struct ConnectorConfig {
@@ -12,10 +25,10 @@ pub struct ConnectorConfig {
#[derive(Clone, Debug)]
pub struct CalckeyModel(DatabaseConnection);
-#[derive(Debug, Error)]
+#[derive(Debug, Error, IntoStaticStr)]
pub enum CalckeyDbError {
#[error("Database error: {0}")]
- DbError(#[from] sea_orm::DbErr),
+ DbError(#[from] DbErr),
}
impl CalckeyModel {
@@ -36,6 +49,10 @@ impl CalckeyModel {
Ok(())
}
+ pub fn inner(&self) -> &DatabaseConnection {
+ &self.0
+ }
+
pub async fn get_user_by_tag(
&self,
name: &str,
@@ -61,10 +78,256 @@ impl CalckeyModel {
Ok(user)
}
+ pub async fn get_note_by_id(&self, id: &str) -> Result