This commit is contained in:
Sebastian Moser
2026-03-25 12:13:00 +01:00
parent 299f00c94f
commit 94f0a960f6
6 changed files with 258 additions and 139 deletions

View File

@@ -18,11 +18,13 @@ reqwest = { version = "0.13.2", features = ["blocking", "json"] }
serde = "1.0.228"
serde_json = "1.0.149"
rusqlite = { version = "0.31", features = ["bundled"], optional = true }
dioxus = { version = "0.7.1", features = ["router", "fullstack", "web", "desktop", "mobile", "server", "ssr"], optional = true }
dioxus = { version = "0.7.1", optional = true }
[features]
default = ["target-os"]
default = ["target-os", "desktop", "server"]
target-os = [ "clap", "mize/target-os", "rustyscript", "rusqlite", "dioxus" ]
desktop = ["dioxus/desktop"]
server = []
target-js = [ "mize/target-js" ]
clap = ["dep:clap"]

View File

@@ -44,11 +44,11 @@ path = "lib.rs"
name = "ppc"
[features]
default = ["target-os"]
target-os = [ "clap", "mize/target-os", "marts/target-os", "server", "tracing", "webbrowser", "base64" ]
default = ["target-os", "desktop", "server"]
target-os = [ "clap", "mize/target-os", "marts/target-os", "tracing", "webbrowser", "base64", "serde_json", "serde" ]
target-obsidian = [ "js-sys", "wasm-bindgen", "mize/target-js", "marts/target-js", "base64", "serde_json", "serde", "openidconnect", "dioxus", "dioxus-web", "web-sys", "web-sys/Document", "dioxus/web" ]
server = [ "axum", "axum-extra", "openidconnect", "serde", "serde_json", "reqwest", "rand", "url", "time", "tokio", "dioxus/ssr", "dioxus/server", "dioxus/fullstack", "dioxus/desktop", "dioxus/router", "dioxus-ssr", "html-escape", "axum-oidc", "tower", "tower-sessions" ]
web-sys = ["dep:web-sys"]
server = [ "axum", "axum-extra", "openidconnect", "serde", "serde_json", "reqwest", "rand", "url", "time", "tokio", "dioxus/ssr", "dioxus/server", "dioxus/fullstack", "dioxus/router", "dioxus-ssr", "html-escape", "axum-oidc", "tower", "tower-sessions", "marts/server", "target-os" ]
desktop = ["dioxus/desktop", "marts/desktop", "target-os"]
[package.metadata.wasm-pack.profile.release]

View File

@@ -9,5 +9,5 @@ edition = "2021"
crate-type = ["cdylib"]
[dependencies]
spacetimedb = "1.11.*"
spacetimedb = "2.1.0"
log = "0.4"

View File

@@ -1,36 +1,89 @@
use log::*;
use spacetimedb::{ReducerContext, Table};
use spacetimedb::{reducer, table, Identity, ReducerContext, Table, Timestamp};
#[spacetimedb::table(name = person, public)]
pub struct Person {
#[table(accessor = profiles, public)]
pub struct Profile {
#[primary_key]
identity: Identity,
#[unique]
username: String,
}
#[spacetimedb::reducer(init)]
#[table(accessor = activities, public)]
pub struct Activity {
#[primary_key]
#[auto_inc]
id: u64,
name: String,
task: Option<u64>,
}
#[table(accessor = tasks, public)]
pub struct Task {
#[primary_key]
#[auto_inc]
id: u64,
done: bool,
name: String,
parent: Option<u64>,
}
#[table(accessor = events, public)]
pub struct Event {
start: Timestamp,
end: Timestamp,
activity: Activity,
}
// TODO....
#[reducer(init)]
pub fn init(_ctx: &ReducerContext) {
// Called when the module is initially published
info!("hiiiiiii");
info!("hiiiiiii from ppc module");
}
#[spacetimedb::reducer(client_connected)]
pub fn identity_connected(_ctx: &ReducerContext) {
// Called everytime a new client connects
// the one from ppc, hardcoded rn, as we for now only support config at run time.
// this needs to be loaded at build time. (this code runs as a wasm module on the spacetimedb server)
const PPC_AUTH_CLIENT_ID: &str = "363331597203734531";
#[reducer(client_connected)]
pub fn connect(ctx: &ReducerContext) -> Result<(), String> {
check_auth(ctx)?;
// add user
ctx.db.profiles().insert(Profile {
identity: ctx.sender(),
username: ctx.identity().to_string(),
});
Ok(())
}
#[spacetimedb::reducer(client_disconnected)]
fn check_auth(ctx: &ReducerContext) -> Result<(), String> {
let jwt = ctx
.sender_auth()
.jwt()
.ok_or("Authentication required".to_string())?;
if jwt.issuer() != "https://auth.ppc.social" {
return Err("Invalid issuer".to_string());
}
if !jwt.audience().iter().any(|a| a == PPC_AUTH_CLIENT_ID) {
return Err("Invalid audience".to_string());
}
Ok(())
}
#[reducer(client_disconnected)]
pub fn identity_disconnected(_ctx: &ReducerContext) {
// Called everytime a client disconnects
}
#[spacetimedb::reducer]
pub fn add(ctx: &ReducerContext, username: String) {
ctx.db.person().insert(Person { username });
}
#[spacetimedb::reducer]
pub fn say_hello(ctx: &ReducerContext) {
for person in ctx.db.person().iter() {
log::info!("Hello, {}!", person.username);
}
log::info!("Hello, World!");
#[reducer]
pub fn add_activity(ctx: &ReducerContext, name: String) {
ctx.db.activities().insert(Activity {
name,
task: None,
id: 0, // auto-increments
});
}