mirror of
https://github.com/Nutomic/ibis.git
synced 2024-12-23 17:21:24 +00:00
partial
This commit is contained in:
parent
10bbc9ed2b
commit
5847e99128
10 changed files with 140 additions and 311 deletions
268
Cargo.lock
generated
268
Cargo.lock
generated
|
@ -20,7 +20,7 @@ dependencies = [
|
|||
"enum_delegate",
|
||||
"futures",
|
||||
"futures-core",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-signature-normalization",
|
||||
"http-signature-normalization-reqwest",
|
||||
"httpdate",
|
||||
|
@ -214,7 +214,7 @@ dependencies = [
|
|||
"axum-core",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
|
@ -248,7 +248,7 @@ dependencies = [
|
|||
"async-trait",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"mime",
|
||||
|
@ -271,7 +271,7 @@ dependencies = [
|
|||
"bytes",
|
||||
"cookie",
|
||||
"futures-util",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"mime",
|
||||
|
@ -1440,108 +1440,6 @@ dependencies = [
|
|||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d15282ece24eaf4bd338d73ef580c6714c8615155c4190c781290ee3fa0fd372"
|
||||
dependencies = [
|
||||
"gloo-console",
|
||||
"gloo-dialogs",
|
||||
"gloo-events",
|
||||
"gloo-file",
|
||||
"gloo-history",
|
||||
"gloo-net 0.5.0",
|
||||
"gloo-render",
|
||||
"gloo-storage",
|
||||
"gloo-timers",
|
||||
"gloo-utils",
|
||||
"gloo-worker",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-console"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a17868f56b4a24f677b17c8cb69958385102fa879418052d60b50bc1727e261"
|
||||
dependencies = [
|
||||
"gloo-utils",
|
||||
"js-sys",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-dialogs"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf4748e10122b01435750ff530095b1217cf6546173459448b83913ebe7815df"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-events"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27c26fb45f7c385ba980f5fa87ac677e363949e065a083722697ef1b2cc91e41"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-file"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97563d71863fb2824b2e974e754a81d19c4a7ec47b09ced8a0e6656b6d54bd1f"
|
||||
dependencies = [
|
||||
"gloo-events",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-history"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "903f432be5ba34427eac5e16048ef65604a82061fe93789f2212afc73d8617d6"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"gloo-events",
|
||||
"gloo-utils",
|
||||
"serde",
|
||||
"serde-wasm-bindgen",
|
||||
"serde_urlencoded",
|
||||
"thiserror 1.0.69",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-net"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43aaa242d1239a8822c15c645f02166398da4f8b5c4bae795c1f5b44e9eee173"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"gloo-utils",
|
||||
"http 0.2.12",
|
||||
"js-sys",
|
||||
"pin-project",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 1.0.69",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-net"
|
||||
version = "0.6.0"
|
||||
|
@ -1552,7 +1450,7 @@ dependencies = [
|
|||
"futures-core",
|
||||
"futures-sink",
|
||||
"gloo-utils",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"js-sys",
|
||||
"pin-project",
|
||||
"serde",
|
||||
|
@ -1563,31 +1461,6 @@ dependencies = [
|
|||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-render"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56008b6744713a8e8d98ac3dcb7d06543d5662358c9c805b4ce2167ad4649833"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-storage"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbc8031e8c92758af912f9bc08fbbadd3c6f3cfcbf6b64cdf3d6a81f0139277a"
|
||||
dependencies = [
|
||||
"gloo-utils",
|
||||
"js-sys",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 1.0.69",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-timers"
|
||||
version = "0.3.0"
|
||||
|
@ -1613,37 +1486,6 @@ dependencies = [
|
|||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-worker"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "085f262d7604911c8150162529cefab3782e91adb20202e8658f7275d2aefe5d"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"futures",
|
||||
"gloo-utils",
|
||||
"gloo-worker-macros",
|
||||
"js-sys",
|
||||
"pinned",
|
||||
"serde",
|
||||
"thiserror 1.0.69",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-worker-macros"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "956caa58d4857bc9941749d55e4bd3000032d8212762586fa5705632967140e7"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guardian"
|
||||
version = "1.2.0"
|
||||
|
@ -1661,7 +1503,7 @@ dependencies = [
|
|||
"fnv",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"indexmap",
|
||||
"slab",
|
||||
"tokio",
|
||||
|
@ -1721,17 +1563,6 @@ dependencies = [
|
|||
"utf8-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "0.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.1.0"
|
||||
|
@ -1750,7 +1581,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1761,7 +1592,7 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f"
|
|||
dependencies = [
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-body",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
@ -1836,7 +1667,7 @@ dependencies = [
|
|||
"futures-channel",
|
||||
"futures-util",
|
||||
"h2",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-body",
|
||||
"httparse",
|
||||
"httpdate",
|
||||
|
@ -1854,7 +1685,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"rustls",
|
||||
|
@ -1890,7 +1721,7 @@ dependencies = [
|
|||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-body",
|
||||
"hyper",
|
||||
"pin-project-lite",
|
||||
|
@ -1948,7 +1779,7 @@ dependencies = [
|
|||
"env_logger",
|
||||
"futures",
|
||||
"getrandom",
|
||||
"gloo",
|
||||
"gloo-net",
|
||||
"hex",
|
||||
"jsonwebtoken",
|
||||
"katex",
|
||||
|
@ -1983,6 +1814,7 @@ dependencies = [
|
|||
"url",
|
||||
"uuid",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2309,7 +2141,7 @@ dependencies = [
|
|||
"default-struct-builder",
|
||||
"futures-util",
|
||||
"gloo-timers",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"js-sys",
|
||||
"lazy_static",
|
||||
"leptos",
|
||||
|
@ -2455,7 +2287,7 @@ dependencies = [
|
|||
"any_spawner",
|
||||
"either_of",
|
||||
"futures",
|
||||
"gloo-net 0.6.0",
|
||||
"gloo-net",
|
||||
"js-sys",
|
||||
"leptos",
|
||||
"leptos_router_macro",
|
||||
|
@ -2782,7 +2614,7 @@ dependencies = [
|
|||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-util",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"httparse",
|
||||
"memchr",
|
||||
"mime",
|
||||
|
@ -3123,17 +2955,6 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "pinned"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a829027bd95e54cfe13e3e258a1ae7b645960553fb82b75ff852c29688ee595b"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"rustversion",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkcs1"
|
||||
version = "0.7.5"
|
||||
|
@ -3218,16 +3039,6 @@ dependencies = [
|
|||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"toml_edit 0.19.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
|
@ -3611,7 +3422,7 @@ dependencies = [
|
|||
"futures-core",
|
||||
"futures-util",
|
||||
"h2",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
|
@ -3657,7 +3468,7 @@ checksum = "562ceb5a604d3f7c885a792d42c199fd8af239d0a51b2fa6a78aafa092452b04"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"thiserror 1.0.69",
|
||||
|
@ -3917,17 +3728,6 @@ dependencies = [
|
|||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde-wasm-bindgen"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.215"
|
||||
|
@ -4005,8 +3805,8 @@ dependencies = [
|
|||
"const_format",
|
||||
"dashmap",
|
||||
"futures",
|
||||
"gloo-net 0.6.0",
|
||||
"http 1.1.0",
|
||||
"gloo-net",
|
||||
"http",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"inventory",
|
||||
|
@ -4540,7 +4340,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit 0.22.22",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4552,17 +4352,6 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.19.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime",
|
||||
"winnow 0.5.40",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.22.22"
|
||||
|
@ -4573,7 +4362,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow 0.6.20",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4616,7 +4405,7 @@ dependencies = [
|
|||
"bitflags 2.6.0",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"http-range-header",
|
||||
|
@ -4641,7 +4430,7 @@ dependencies = [
|
|||
"bitflags 2.6.0",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.1.0",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"http-range-header",
|
||||
|
@ -5152,15 +4941,6 @@ version = "0.52.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.5.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.6.20"
|
||||
|
|
|
@ -121,7 +121,8 @@ tower = { version = "0.5.1", optional = true }
|
|||
tower-layer = { version = "0.3.3", optional = true }
|
||||
console_log = "1.0.0"
|
||||
send_wrapper = "0.6.0"
|
||||
gloo = "0.11.0"
|
||||
gloo-net = "0.6.0"
|
||||
web-sys = "0.3.72"
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1.4.1"
|
||||
|
|
|
@ -7,16 +7,10 @@ use crate::{
|
|||
utils::generate_activity_id,
|
||||
},
|
||||
common::{
|
||||
utils::http_protocol_str,
|
||||
Auth,
|
||||
DbArticle,
|
||||
DbInstance,
|
||||
DbPerson,
|
||||
EditVersion,
|
||||
AUTH_COOKIE,
|
||||
utils::http_protocol_str, Auth, DbArticle, DbInstance, DbPerson, EditVersion, AUTH_COOKIE,
|
||||
MAIN_PAGE_NAME,
|
||||
},
|
||||
frontend::app::App,
|
||||
frontend::app::{shell, App},
|
||||
};
|
||||
use activitypub_federation::{
|
||||
config::{Data, FederationConfig, FederationMiddleware},
|
||||
|
@ -27,12 +21,12 @@ use api::api_routes;
|
|||
use assets::file_and_error_handler;
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::State,
|
||||
http::{HeaderValue, Request},
|
||||
middleware::Next,
|
||||
response::{IntoResponse, Response},
|
||||
routing::get,
|
||||
Router,
|
||||
ServiceExt,
|
||||
Router, ServiceExt,
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use axum_macros::debug_middleware;
|
||||
|
@ -43,8 +37,7 @@ use diesel::{
|
|||
};
|
||||
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||
use federation::objects::{
|
||||
articles_collection::local_articles_url,
|
||||
instance_collection::linked_instances_url,
|
||||
articles_collection::local_articles_url, instance_collection::linked_instances_url,
|
||||
};
|
||||
use leptos::prelude::*;
|
||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||
|
@ -123,13 +116,17 @@ pub async fn start(config: IbisConfig, override_hostname: Option<SocketAddr>) ->
|
|||
}
|
||||
|
||||
/// Make auth token available in hydrate mode
|
||||
async fn leptos_routes_handler(jar: CookieJar, req: Request<Body>) -> Response {
|
||||
async fn leptos_routes_handler(
|
||||
jar: CookieJar,
|
||||
State(leptos_options): State<LeptosOptions>,
|
||||
req: Request<Body>,
|
||||
) -> Response {
|
||||
let handler = leptos_axum::render_app_async_with_context(
|
||||
move || {
|
||||
let cookie = jar.get(AUTH_COOKIE).map(|c| c.value().to_string());
|
||||
provide_context(Auth(cookie));
|
||||
},
|
||||
move || view! { <App /> },
|
||||
move || shell(leptos_options.clone()),
|
||||
);
|
||||
|
||||
handler(req).await.into_response()
|
||||
|
|
|
@ -62,7 +62,7 @@ impl ApiClient {
|
|||
if let Some(query) = query {
|
||||
req = req.query(&query);
|
||||
}
|
||||
send::<T>(req).await
|
||||
self.send::<T>(req).await
|
||||
}
|
||||
|
||||
pub async fn get_article(&self, data: GetArticleForm) -> MyResult<ArticleView> {
|
||||
|
@ -78,7 +78,7 @@ impl ApiClient {
|
|||
.client
|
||||
.post(self.request_endpoint("/api/v1/account/register"))
|
||||
.form(®ister_form);
|
||||
send::<LocalUserView>(req).await
|
||||
self.send::<LocalUserView>(req).await
|
||||
}
|
||||
|
||||
pub async fn login(&self, login_form: LoginUserForm) -> MyResult<LocalUserView> {
|
||||
|
@ -86,7 +86,7 @@ impl ApiClient {
|
|||
.client
|
||||
.post(self.request_endpoint("/api/v1/account/login"))
|
||||
.form(&login_form);
|
||||
send::<LocalUserView>(req).await
|
||||
self.send::<LocalUserView>(req).await
|
||||
}
|
||||
|
||||
pub async fn create_article(&self, data: &CreateArticleForm) -> MyResult<ArticleView> {
|
||||
|
@ -94,7 +94,7 @@ impl ApiClient {
|
|||
.client
|
||||
.post(self.request_endpoint("/api/v1/article"))
|
||||
.form(data);
|
||||
send(req).await
|
||||
self.send(req).await
|
||||
}
|
||||
|
||||
pub async fn edit_article_with_conflict(
|
||||
|
@ -105,7 +105,7 @@ impl ApiClient {
|
|||
.client
|
||||
.patch(self.request_endpoint("/api/v1/article"))
|
||||
.form(edit_form);
|
||||
send(req).await
|
||||
self.send(req).await
|
||||
}
|
||||
|
||||
pub async fn edit_article(&self, edit_form: &EditArticleForm) -> MyResult<ArticleView> {
|
||||
|
@ -124,14 +124,14 @@ impl ApiClient {
|
|||
let req = self
|
||||
.client
|
||||
.get(self.request_endpoint("/api/v1/user/notifications/list"));
|
||||
send(req).await
|
||||
self.send(req).await
|
||||
}
|
||||
|
||||
pub async fn notifications_count(&self) -> MyResult<usize> {
|
||||
let req = self
|
||||
.client
|
||||
.get(self.request_endpoint("/api/v1/user/notifications/count"));
|
||||
send(req).await
|
||||
self.send(req).await
|
||||
}
|
||||
|
||||
pub async fn approve_article(&self, article_id: ArticleId, approve: bool) -> MyResult<()> {
|
||||
|
@ -143,7 +143,7 @@ impl ApiClient {
|
|||
.client
|
||||
.post(self.request_endpoint("/api/v1/article/approve"))
|
||||
.form(&form);
|
||||
send(req).await
|
||||
self.send(req).await
|
||||
}
|
||||
|
||||
pub async fn delete_conflict(&self, conflict_id: ConflictId) -> MyResult<()> {
|
||||
|
@ -152,7 +152,7 @@ impl ApiClient {
|
|||
.client
|
||||
.delete(self.request_endpoint("/api/v1/conflict"))
|
||||
.form(&form);
|
||||
send(req).await
|
||||
self.send(req).await
|
||||
}
|
||||
|
||||
pub async fn search(&self, search_form: &SearchArticleForm) -> MyResult<Vec<DbArticle>> {
|
||||
|
@ -192,6 +192,8 @@ impl ApiClient {
|
|||
}
|
||||
|
||||
pub async fn follow_instance(&self, follow_form: FollowInstance) -> MyResult<()> {
|
||||
todo!();
|
||||
/*
|
||||
// cant use post helper because follow doesnt return json
|
||||
let res = self
|
||||
.client
|
||||
|
@ -204,19 +206,19 @@ impl ApiClient {
|
|||
} else {
|
||||
Err(anyhow!("API error: {}", res.text().await?).into())
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
pub async fn site(&self) -> MyResult<SiteView> {
|
||||
let req = self.client.get(self.request_endpoint("/api/v1/site"));
|
||||
send(req).await
|
||||
self.send(req).await
|
||||
}
|
||||
|
||||
pub async fn logout(&self) -> MyResult<()> {
|
||||
self.client
|
||||
.get(self.request_endpoint("/api/v1/account/logout"))
|
||||
.send()
|
||||
.await?;
|
||||
Ok(())
|
||||
let req = self
|
||||
.client
|
||||
.get(self.request_endpoint("/api/v1/account/logout"));
|
||||
Ok(self.send(req).await.unwrap())
|
||||
}
|
||||
|
||||
pub async fn fork_article(&self, form: &ForkArticleForm) -> MyResult<ArticleView> {
|
||||
|
@ -224,7 +226,7 @@ impl ApiClient {
|
|||
.client
|
||||
.post(self.request_endpoint("/api/v1/article/fork"))
|
||||
.form(form);
|
||||
Ok(send(req).await.unwrap())
|
||||
Ok(self.send(req).await.unwrap())
|
||||
}
|
||||
|
||||
pub async fn protect_article(&self, params: &ProtectArticleForm) -> MyResult<DbArticle> {
|
||||
|
@ -232,7 +234,7 @@ impl ApiClient {
|
|||
.client
|
||||
.post(self.request_endpoint("/api/v1/article/protect"))
|
||||
.form(params);
|
||||
send(req).await
|
||||
self.send(req).await
|
||||
}
|
||||
|
||||
pub async fn resolve_article(&self, id: Url) -> MyResult<ArticleView> {
|
||||
|
@ -249,23 +251,10 @@ impl ApiClient {
|
|||
pub async fn get_user(&self, data: GetUserForm) -> MyResult<DbPerson> {
|
||||
self.get("/api/v1/user", Some(data)).await
|
||||
}
|
||||
|
||||
fn request_endpoint(&self, path: &str) -> String {
|
||||
let protocol = if self.ssl { "https" } else { "http" };
|
||||
format!("{protocol}://{}{path}", &self.hostname)
|
||||
}
|
||||
}
|
||||
|
||||
async fn send<T>(#[allow(unused_mut)] mut req: RequestBuilder) -> MyResult<T>
|
||||
where
|
||||
T: for<'de> Deserialize<'de>,
|
||||
{
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
{
|
||||
req = req.fetch_credentials_include();
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
async fn send<T>(&self, mut req: RequestBuilder) -> MyResult<T>
|
||||
where
|
||||
T: for<'de> Deserialize<'de>,
|
||||
{
|
||||
use crate::common::{Auth, AUTH_COOKIE};
|
||||
use leptos::prelude::use_context;
|
||||
|
@ -275,13 +264,62 @@ where
|
|||
if let Some(Auth(Some(auth))) = auth {
|
||||
req = req.header(HeaderName::from_static(AUTH_COOKIE), auth);
|
||||
}
|
||||
let res = req.send().await?;
|
||||
let status = res.status();
|
||||
let text = res.text().await?;
|
||||
if status == StatusCode::OK {
|
||||
Ok(serde_json::from_str(&text).map_err(|e| anyhow!("Json error on {text}: {e}"))?)
|
||||
} else {
|
||||
Err(anyhow!("API error: {text}").into())
|
||||
}
|
||||
}
|
||||
let res = req.send().await?;
|
||||
let status = res.status();
|
||||
let text = res.text().await?;
|
||||
if status == StatusCode::OK {
|
||||
Ok(serde_json::from_str(&text).map_err(|e| anyhow!("Json error on {text}: {e}"))?)
|
||||
} else {
|
||||
Err(anyhow!("API error: {text}").into())
|
||||
|
||||
#[cfg(feature = "hydrate")]
|
||||
fn send<T>(
|
||||
&self,
|
||||
mut req: RequestBuilder,
|
||||
) -> impl std::future::Future<Output = MyResult<T>> + Send
|
||||
where
|
||||
T: for<'de> Deserialize<'de>,
|
||||
{
|
||||
use gloo_net::http::*;
|
||||
use leptos::prelude::on_cleanup;
|
||||
use send_wrapper::SendWrapper;
|
||||
use web_sys::RequestCredentials;
|
||||
|
||||
SendWrapper::new(async move {
|
||||
let abort_controller = SendWrapper::new(web_sys::AbortController::new().ok());
|
||||
let abort_signal = abort_controller.as_ref().map(|a| a.signal());
|
||||
|
||||
// abort in-flight requests if, e.g., we've navigated away from this page
|
||||
on_cleanup(move || {
|
||||
if let Some(abort_controller) = abort_controller.take() {
|
||||
abort_controller.abort()
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
if status == StatusCode::OK {
|
||||
Ok(serde_json::from_str(&text).map_err(|e| anyhow!("Json error on {text}: {e}"))?)
|
||||
} else {
|
||||
Err(anyhow!("API error: {text}").into())
|
||||
}
|
||||
*/
|
||||
Ok(RequestBuilder::new("/api/v1/site")
|
||||
.method(Method::GET)
|
||||
.abort_signal(abort_signal.as_ref())
|
||||
.credentials(RequestCredentials::Include)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.json()
|
||||
.await
|
||||
.unwrap())
|
||||
})
|
||||
}
|
||||
|
||||
fn request_endpoint(&self, path: &str) -> String {
|
||||
let protocol = if self.ssl { "https" } else { "http" };
|
||||
format!("{protocol}://{}{path}", &self.hostname)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,8 @@ use crate::{
|
|||
dark_mode::DarkMode,
|
||||
pages::{
|
||||
article::{
|
||||
actions::ArticleActions,
|
||||
create::CreateArticle,
|
||||
edit::EditArticle,
|
||||
history::ArticleHistory,
|
||||
list::ListArticles,
|
||||
read::ReadArticle,
|
||||
actions::ArticleActions, create::CreateArticle, edit::EditArticle,
|
||||
history::ArticleHistory, list::ListArticles, read::ReadArticle,
|
||||
},
|
||||
diff::EditDiff,
|
||||
instance::{details::InstanceDetails, list::ListInstances},
|
||||
|
@ -59,6 +55,23 @@ impl<T: Default + Send + Sync> DefaultResource<T> for Resource<T> {
|
|||
})
|
||||
}
|
||||
}
|
||||
pub fn shell(options: LeptosOptions) -> impl IntoView {
|
||||
view! {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<AutoReload options=options.clone() />
|
||||
<HydrationScripts options />
|
||||
<MetaTags />
|
||||
</head>
|
||||
<body>
|
||||
<App />
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
|
|
|
@ -35,7 +35,7 @@ pub fn ArticleNav(article: Resource<ArticleView>, active_tab: ActiveTab) -> impl
|
|||
let form = GetInstance {
|
||||
id: Some(instance_id),
|
||||
};
|
||||
CLIENT.get_instance(form).await.unwrap()
|
||||
CLIENT.get_instance(&form).await.unwrap()
|
||||
},
|
||||
);
|
||||
let article_link = article_link(&article_.article);
|
||||
|
|
|
@ -25,7 +25,7 @@ pub fn ArticleActions() -> impl IntoView {
|
|||
};
|
||||
async move {
|
||||
set_error.update(|e| *e = None);
|
||||
let result = CLIENT.fork_article(params).await;
|
||||
let result = CLIENT.fork_article(¶ms).await;
|
||||
match result {
|
||||
Ok(res) => set_fork_response.set(Some(res.article)),
|
||||
Err(err) => {
|
||||
|
@ -41,7 +41,7 @@ pub fn ArticleActions() -> impl IntoView {
|
|||
};
|
||||
async move {
|
||||
set_error.update(|e| *e = None);
|
||||
let result = CLIENT.protect_article(params).await;
|
||||
let result = CLIENT.protect_article(¶ms).await;
|
||||
match result {
|
||||
Ok(_res) => article.refetch(),
|
||||
Err(err) => {
|
||||
|
|
|
@ -32,7 +32,7 @@ pub fn CreateArticle() -> impl IntoView {
|
|||
summary,
|
||||
};
|
||||
set_wait_for_response.update(|w| *w = true);
|
||||
let res = CLIENT.create_article(form).await;
|
||||
let res = CLIENT.create_article(&form).await;
|
||||
set_wait_for_response.update(|w| *w = false);
|
||||
match res {
|
||||
Ok(_res) => {
|
||||
|
|
|
@ -89,7 +89,7 @@ pub fn EditArticle() -> impl IntoView {
|
|||
resolve_conflict_id,
|
||||
};
|
||||
set_wait_for_response.update(|w| *w = true);
|
||||
let res = CLIENT.edit_article_with_conflict(form).await;
|
||||
let res = CLIENT.edit_article_with_conflict(&form).await;
|
||||
set_wait_for_response.update(|w| *w = false);
|
||||
match res {
|
||||
Ok(Some(conflict)) => {
|
||||
|
|
|
@ -29,7 +29,7 @@ pub fn Search() -> impl IntoView {
|
|||
let mut search_results = SearchResults::default();
|
||||
let url = Url::parse(&query);
|
||||
let search_data = SearchArticleForm { query };
|
||||
let search = CLIENT.search(search_data);
|
||||
let search = CLIENT.search(&search_data);
|
||||
|
||||
match search.await {
|
||||
Ok(mut a) => search_results.articles.append(&mut a),
|
||||
|
|
Loading…
Reference in a new issue