1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-24 23:51:09 +00:00

simplify trunk setup

This commit is contained in:
Felix Ableitner 2024-01-11 16:21:44 +01:00
parent 0052054a19
commit b6c1512479
13 changed files with 129 additions and 374 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target
/.idea
/assets/dist

283
Cargo.lock generated
View file

@ -69,17 +69,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "ahash"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd"
dependencies = [
"getrandom",
"once_cell",
"version_check",
]
[[package]]
name = "ahash"
version = "0.8.7"
@ -308,18 +297,6 @@ version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "bitvec"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
dependencies = [
"funty",
"radium",
"tap",
"wyz",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
@ -345,29 +322,6 @@ version = "3.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
[[package]]
name = "bytecheck"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b6372023ac861f6e6dc89c8344a8f398fb42aaba2b5dbc649ca0c0e9dbcb627"
dependencies = [
"bytecheck_derive",
"ptr_meta",
"simdutf8",
"uuid",
]
[[package]]
name = "bytecheck_derive"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7ec4c6f261935ad534c0c22dbef2201b45918860eb1c574b972bd213a76af61"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "bytecount"
version = "0.6.7"
@ -406,7 +360,7 @@ version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c878c71c2821aa2058722038a59a67583a4240524687c6028571c9b395ded61f"
dependencies = [
"darling 0.14.4",
"darling",
"proc-macro2",
"quote",
"syn 1.0.109",
@ -576,12 +530,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "convert_case"
version = "0.6.0"
@ -664,18 +612,8 @@ version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
dependencies = [
"darling_core 0.14.4",
"darling_macro 0.14.4",
]
[[package]]
name = "darling"
version = "0.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e"
dependencies = [
"darling_core 0.20.3",
"darling_macro 0.20.3",
"darling_core",
"darling_macro",
]
[[package]]
@ -692,42 +630,17 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "darling_core"
version = "0.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn 2.0.39",
]
[[package]]
name = "darling_macro"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
dependencies = [
"darling_core 0.14.4",
"darling_core",
"quote",
"syn 1.0.109",
]
[[package]]
name = "darling_macro"
version = "0.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5"
dependencies = [
"darling_core 0.20.3",
"quote",
"syn 2.0.39",
]
[[package]]
name = "deranged"
version = "0.3.10"
@ -737,17 +650,6 @@ dependencies = [
"powerfmt",
]
[[package]]
name = "derivative"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "derive-where"
version = "1.2.7"
@ -774,7 +676,7 @@ version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f"
dependencies = [
"darling 0.14.4",
"darling",
"proc-macro2",
"quote",
"syn 1.0.109",
@ -790,19 +692,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "derive_more"
version = "0.99.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
dependencies = [
"convert_case 0.4.0",
"proc-macro2",
"quote",
"rustc_version",
"syn 1.0.109",
]
[[package]]
name = "diesel"
version = "2.1.4"
@ -1013,12 +902,6 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "funty"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
[[package]]
name = "futures"
version = "0.3.29"
@ -1206,9 +1089,6 @@ name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
dependencies = [
"ahash 0.7.7",
]
[[package]]
name = "hashbrown"
@ -1222,7 +1102,7 @@ version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
dependencies = [
"ahash 0.8.7",
"ahash",
"allocator-api2",
]
@ -1461,7 +1341,6 @@ dependencies = [
"jsonwebtoken",
"leptos",
"leptos_axum",
"leptos_form",
"leptos_meta",
"leptos_router",
"log",
@ -1701,62 +1580,6 @@ dependencies = [
"web-sys",
]
[[package]]
name = "leptos_form"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b900a4aa333561feaab096899077dab6a75e46072988cf5a4c45b71f2c1e52e2"
dependencies = [
"leptos",
"leptos_form_core",
"leptos_form_proc_macros",
"leptos_router",
"rustc_version",
"wasm-bindgen",
]
[[package]]
name = "leptos_form_core"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea205a16d85564b6c7b368ae53eae1f9690c37166db3f7dee19279f32ea4784a"
dependencies = [
"derivative",
"derive_more",
"indexmap 2.1.0",
"leptos",
"paste",
"rustc_version",
"thiserror",
"typed-builder",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "leptos_form_proc_macros"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66f51d4e76639a2bc58eccea205b06cb84c672feee38bb3145c682801daaef6e"
dependencies = [
"leptos_form_proc_macros_core",
]
[[package]]
name = "leptos_form_proc_macros_core"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907e75aeb43fb660b0247bb55cf6129c1c5e67c881dc60f976aad78c0130bc4f"
dependencies = [
"convert_case 0.6.0",
"darling 0.20.3",
"derive_more",
"itertools 0.12.0",
"proc-macro2",
"quote",
"syn 2.0.39",
]
[[package]]
name = "leptos_hot_reload"
version = "0.5.4"
@ -1797,7 +1620,7 @@ checksum = "a7e96f4c450f4b5e2ccb135c2b1328890f911ca4ee89da9ed6d582df929e6cb5"
dependencies = [
"attribute-derive",
"cfg-if",
"convert_case 0.6.0",
"convert_case",
"html-escape",
"itertools 0.11.0",
"leptos_hot_reload",
@ -1839,7 +1662,6 @@ dependencies = [
"js-sys",
"paste",
"pin-project",
"rkyv",
"rustc-hash",
"self_cell",
"serde",
@ -2423,26 +2245,6 @@ dependencies = [
"yansi 1.0.0-rc.1",
]
[[package]]
name = "ptr_meta"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1"
dependencies = [
"ptr_meta_derive",
]
[[package]]
name = "ptr_meta_derive"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "pulldown-cmark"
version = "0.9.3"
@ -2502,12 +2304,6 @@ dependencies = [
"syn 2.0.39",
]
[[package]]
name = "radium"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
[[package]]
name = "rand"
version = "0.8.5"
@ -2585,15 +2381,6 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "rend"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2571463863a6bd50c32f94402933f03457a3fbaf697a707c5be741e459f08fd"
dependencies = [
"bytecheck",
]
[[package]]
name = "reqwest"
version = "0.11.22"
@ -2664,35 +2451,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "rkyv"
version = "0.7.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "527a97cdfef66f65998b5f3b637c26f5a5ec09cc52a3f9932313ac645f4190f5"
dependencies = [
"bitvec",
"bytecheck",
"bytes",
"hashbrown 0.12.3",
"ptr_meta",
"rend",
"rkyv_derive",
"seahash",
"tinyvec",
"uuid",
]
[[package]]
name = "rkyv_derive"
version = "0.7.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5c462a1328c8e67e4d6dbad1eb0355dd43e8ab432c6e227a43657f16ade5033"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "rstml"
version = "0.11.2"
@ -2777,12 +2535,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "seahash"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
[[package]]
name = "security-framework"
version = "2.9.2"
@ -2996,12 +2748,6 @@ dependencies = [
"libc",
]
[[package]]
name = "simdutf8"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a"
[[package]]
name = "simple_asn1"
version = "0.6.2"
@ -3159,12 +2905,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
[[package]]
name = "tap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "task-local-extensions"
version = "0.1.4"
@ -3800,15 +3540,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "wyz"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
dependencies = [
"tap",
]
[[package]]
name = "xxhash-rust"
version = "0.8.8"

View file

@ -28,9 +28,9 @@ anyhow = "1.0.75"
async-trait = "0.1.74"
axum = { version = "0.6.20", optional = true }
axum-macros = { version = "0.3.8", optional = true }
leptos = { version = "0.5.4", features = ["nightly"] }
leptos_meta = { version = "0.5.4", features = ["nightly"] }
leptos_router = { version = "0.5.4", features = ["nightly"] }
leptos = "0.5.4"
leptos_meta = "0.5.4"
leptos_router = "0.5.4"
leptos_axum = { version = "0.5.4", optional = true }
bcrypt = "0.15.0"
chrono = { version = "0.4.31", features = ["serde"] }
@ -62,8 +62,6 @@ once_cell = "1.18.0"
wasm-bindgen = "0.2.89"
console_error_panic_hook = "0.1.7"
console_log = "1.0.0"
#leptos_form = { path = "../leptos_form/leptos_form" }
leptos_form = "0.1.8"
[dev-dependencies]
pretty_assertions = "1.4.0"

View file

@ -9,9 +9,13 @@ The Ibis is a [bird which is related to the Egyptian god of knowledge and scienc
## Development
You need to install [cargo](https://rustup.rs/) and [trunk](https://trunkrs.dev). Then run the following commands in separate terminals:
```
# start backend
cargo run
trunk serve --no-default-features --features csr,hydrate --filehash false --proxy-backend http://[::1]:8131
# start frontend
trunk serve
```
## License

6
Trunk.toml Normal file
View file

@ -0,0 +1,6 @@
[build]
filehash = false
target = "assets/index.html"
[[proxy]]
backend = "http://[::1]:8131"

11
assets/index.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<link data-trunk rel="rust" data-wasm-opt="z"
href=".."
data-bin="ibis"
data-cargo-no-default-features
data-cargo-features="csr,hydrate" />
</head>
<body></body>
</html>

View file

@ -1,7 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link data-trunk rel="rust" data-wasm-opt="z" data-bin="ibis" />
</head>
<body></body>
</html>

View file

@ -1,5 +1,5 @@
use crate::backend::database::user::{DbLocalUser, DbPerson, LocalUserView};
use crate::backend::database::{read_jwt_secret, MyDataHandle};
use crate::backend::database::{MyDataHandle, read_jwt_secret};
use crate::backend::error::MyResult;
use activitypub_federation::config::Data;
use anyhow::anyhow;
@ -12,9 +12,10 @@ use jsonwebtoken::Validation;
use jsonwebtoken::{decode, get_current_timestamp};
use jsonwebtoken::{encode, EncodingKey, Header};
use serde::{Deserialize, Serialize};
use crate::common::{LoginResponse, LoginUserData, RegisterUserData};
#[derive(Debug, Serialize, Deserialize)]
pub struct Claims {
struct Claims {
/// local_user.id
pub sub: String,
/// hostname
@ -25,7 +26,7 @@ pub struct Claims {
pub exp: u64,
}
pub(in crate::backend::api) fn generate_login_token(
fn generate_login_token(
local_user: DbLocalUser,
data: &Data<MyDataHandle>,
) -> MyResult<LoginResponse> {
@ -51,17 +52,6 @@ pub async fn validate(jwt: &str, data: &Data<MyDataHandle>) -> MyResult<LocalUse
DbPerson::read_local_from_id(claims.claims.sub.parse()?, data)
}
#[derive(Deserialize, Serialize)]
pub struct RegisterUserData {
pub username: String,
pub password: String,
}
#[derive(Deserialize, Serialize)]
pub struct LoginResponse {
pub jwt: String,
}
#[debug_handler]
pub(in crate::backend::api) async fn register_user(
data: Data<MyDataHandle>,
@ -71,12 +61,6 @@ pub(in crate::backend::api) async fn register_user(
Ok(Json(generate_login_token(user.local_user, &data)?))
}
#[derive(Deserialize, Serialize)]
pub struct LoginUserData {
pub username: String,
pub password: String,
}
#[debug_handler]
pub(in crate::backend::api) async fn login_user(
data: Data<MyDataHandle>,

View file

@ -54,3 +54,20 @@ pub struct DbEdit {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "ssr", derive(diesel_derive_newtype::DieselNewType))]
pub struct EditVersion(pub(crate) Uuid);
#[derive(Deserialize, Serialize)]
pub struct RegisterUserData {
pub username: String,
pub password: String,
}
#[derive(Deserialize, Serialize)]
pub struct LoginResponse {
pub jwt: String,
}
#[derive(Deserialize, Serialize)]
pub struct LoginUserData {
pub username: String,
pub password: String,
}

View file

@ -1,4 +1,4 @@
use crate::common::ArticleView;
use crate::common::{ArticleView, LoginResponse, LoginUserData, RegisterUserData};
use crate::common::GetArticleData;
use anyhow::anyhow;
use once_cell::sync::Lazy;
@ -39,3 +39,29 @@ where
Err(anyhow!("API error: {text}")).unwrap()
}
}
pub async fn register(hostname: &str, username: &str, password: &str) -> LoginResponse {
let register_form = RegisterUserData {
username: username.to_string(),
password: password.to_string(),
};
let req = CLIENT
.post(format!("http://{}/api/v1/user/register", hostname))
.form(&register_form);
handle_json_res(req).await
}
pub async fn login(
hostname: &str,
username: &str,
password: &str,
) -> LoginResponse {
let login_form = LoginUserData {
username: username.to_string(),
password: password.to_string(),
};
let req = CLIENT
.post(format!("http://{}/api/v1/user/login", hostname))
.form(&login_form);
handle_json_res(req).await
}

View file

@ -1,41 +1,52 @@
use leptos::*;
use leptos_form::prelude::*;
use leptos::ev::{SubmitEvent};
use log::info;
use serde::{Deserialize, Serialize};
use crate::frontend::api::login;
#[derive(Clone, Debug, Deserialize, Default, Form, Serialize)]
#[form(
component(
action = create_my_data(my_data),
on_success = |DbMyData { id, .. }, _| view!(<div>{format!("Created {id}")}</div>)
)
)
]
pub struct MyData {
pub username: String,
pub password: String,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DbMyData {
pub id: i32,
pub name: String,
}
async fn create_my_data(my_data: MyData) -> Result<DbMyData, ServerFnError> {
info!("{:?}", &my_data);
Ok(DbMyData {
id: 1,
name: my_data.username,
})
// TODO: this seems to be working, but need to implement registration also
// TODO: use leptos_form if possible
// https://github.com/leptos-form/leptos_form/issues/18
fn do_login(ev: SubmitEvent, username: String, password: String) {
ev.prevent_default();
spawn_local(
async move {
let res = login("localhost:8080", &username, &password).await;
info!("{}", res.jwt);
});
}
#[component]
pub fn Login() -> impl IntoView {
let name = RwSignal::new(String::new());
let password = RwSignal::new(String::new());
view! {
<MyData
initial={MyData::default()}
top=|| view!(<input type="button" value="Login" />)
<form on:submit=move |ev| do_login(ev, name.get(), password.get())>
<div>
<label for="username">Username: </label>
<input
id="username"
type="text"
on:input=move |ev| name.set(event_target_value(&ev))
label="Username"
/>
</div>
<div>
<label for="password">Password: </label>
<input
id="password"
type="password"
on:input=move |ev| password.set(event_target_value(&ev))
/>
</div>
<div>
<button type="submit">
"Login"
</button>
</div>
</form>
}
}

View file

@ -1,5 +1,3 @@
use log::info;
#[cfg(feature = "ssr")]
#[tokio::main]
pub async fn main() -> ibis_lib::backend::error::MyResult<()> {
@ -25,5 +23,5 @@ fn main() {
mount_to_body(|| {
view! { <App/> }
});
info!("test 2");
log::info!("test 2");
}

View file

@ -24,6 +24,7 @@ use std::time::Duration;
use tokio::task::JoinHandle;
use tracing::log::LevelFilter;
use url::Url;
use ibis_lib::frontend::api;
pub static CLIENT: Lazy<Client> = Lazy::new(Client::new);
@ -122,7 +123,7 @@ impl IbisInstance {
});
// wait a moment for the backend to start
tokio::time::sleep(Duration::from_millis(100)).await;
let register_res = register(&hostname, username, "hunter2").await.unwrap();
let register_res = api::register(&hostname, username, "hunter2").await.unwrap();
assert!(!register_res.jwt.is_empty());
Self {
jwt: register_res.jwt,
@ -243,29 +244,3 @@ pub async fn follow_instance(instance: &IbisInstance, follow_instance: &str) ->
Err(anyhow!("API error: {}", res.text().await?).into())
}
}
pub async fn register(hostname: &str, username: &str, password: &str) -> MyResult<LoginResponse> {
let register_form = RegisterUserData {
username: username.to_string(),
password: password.to_string(),
};
let req = CLIENT
.post(format!("http://{}/api/v1/user/register", hostname))
.form(&register_form);
api::handle_json_res(req).await
}
pub async fn login(
instance: &IbisInstance,
username: &str,
password: &str,
) -> MyResult<LoginResponse> {
let login_form = LoginUserData {
username: username.to_string(),
password: password.to_string(),
};
let req = CLIENT
.post(format!("http://{}/api/v1/user/login", instance.hostname))
.form(&login_form);
api::handle_json_res(req).await
}