mirror of
https://github.com/Nutomic/ibis.git
synced 2024-12-04 19:01:13 +00:00
Fix test cases
This commit is contained in:
parent
805c669d00
commit
c21d6fe08c
7 changed files with 33 additions and 30 deletions
12
Cargo.toml
12
Cargo.toml
|
@ -5,12 +5,7 @@ edition = "2021"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["ssr"]
|
default = ["ssr"]
|
||||||
ssr = [
|
ssr = ["katex/duktape", "leptos/ssr", "leptos-use/ssr", "leptos-use/axum"]
|
||||||
"katex/duktape",
|
|
||||||
"leptos/ssr",
|
|
||||||
"leptos-use/ssr",
|
|
||||||
"leptos-use/axum",
|
|
||||||
]
|
|
||||||
hydrate = ["leptos/hydrate", "katex/wasm-js"]
|
hydrate = ["leptos/hydrate", "katex/wasm-js"]
|
||||||
|
|
||||||
# This profile significantly speeds up build time. If debug info is needed you can comment the line
|
# This profile significantly speeds up build time. If debug info is needed you can comment the line
|
||||||
|
@ -101,10 +96,7 @@ async-trait = { version = "0.1.83" }
|
||||||
config = { version = "0.14.1", features = ["toml"] }
|
config = { version = "0.14.1", features = ["toml"] }
|
||||||
tower = { version = "0.5.1" }
|
tower = { version = "0.5.1" }
|
||||||
tower-layer = { version = "0.3.3" }
|
tower-layer = { version = "0.3.3" }
|
||||||
reqwest = { version = "0.12.9", features = [
|
reqwest = { version = "0.12.9", features = ["json", "cookies"] }
|
||||||
"json",
|
|
||||||
"cookies",
|
|
||||||
] }
|
|
||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
env_logger = { version = "0.11.5", default-features = false }
|
env_logger = { version = "0.11.5", default-features = false }
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,7 @@ pub(in crate::backend::api) async fn get_article(
|
||||||
Query(query): Query<GetArticleForm>,
|
Query(query): Query<GetArticleForm>,
|
||||||
data: Data<IbisData>,
|
data: Data<IbisData>,
|
||||||
) -> MyResult<Json<ArticleView>> {
|
) -> MyResult<Json<ArticleView>> {
|
||||||
|
dbg!(&query);
|
||||||
match (query.title, query.id) {
|
match (query.title, query.id) {
|
||||||
(Some(title), None) => Ok(Json(DbArticle::read_view_title(
|
(Some(title), None) => Ok(Json(DbArticle::read_view_title(
|
||||||
&title,
|
&title,
|
||||||
|
|
|
@ -3,11 +3,11 @@ use crate::{
|
||||||
common::{
|
common::{
|
||||||
DbInstance,
|
DbInstance,
|
||||||
FollowInstance,
|
FollowInstance,
|
||||||
FollowInstanceResponse,
|
|
||||||
GetInstance,
|
GetInstance,
|
||||||
InstanceView,
|
InstanceView,
|
||||||
LocalUserView,
|
LocalUserView,
|
||||||
ResolveObject,
|
ResolveObject,
|
||||||
|
SuccessResponse,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
|
use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
|
||||||
|
@ -31,13 +31,13 @@ pub(in crate::backend::api) async fn follow_instance(
|
||||||
Extension(user): Extension<LocalUserView>,
|
Extension(user): Extension<LocalUserView>,
|
||||||
data: Data<IbisData>,
|
data: Data<IbisData>,
|
||||||
Form(query): Form<FollowInstance>,
|
Form(query): Form<FollowInstance>,
|
||||||
) -> MyResult<Json<FollowInstanceResponse>> {
|
) -> MyResult<Json<SuccessResponse>> {
|
||||||
let target = DbInstance::read(query.id, &data)?;
|
let target = DbInstance::read(query.id, &data)?;
|
||||||
let pending = !target.local;
|
let pending = !target.local;
|
||||||
DbInstance::follow(&user.person, &target, pending, &data)?;
|
DbInstance::follow(&user.person, &target, pending, &data)?;
|
||||||
let instance = DbInstance::read(query.id, &data)?;
|
let instance = DbInstance::read(query.id, &data)?;
|
||||||
Follow::send(user.person, &instance, &data).await?;
|
Follow::send(user.person, &instance, &data).await?;
|
||||||
Ok(Json(FollowInstanceResponse { success: true }))
|
Ok(Json(SuccessResponse::default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch a remote instance actor. This automatically synchronizes the remote articles collection to
|
/// Fetch a remote instance actor. This automatically synchronizes the remote articles collection to
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub fn api_routes() -> Router<()> {
|
||||||
.route("/user/notifications/count", get(count_notifications))
|
.route("/user/notifications/count", get(count_notifications))
|
||||||
.route("/account/register", post(register_user))
|
.route("/account/register", post(register_user))
|
||||||
.route("/account/login", post(login_user))
|
.route("/account/login", post(login_user))
|
||||||
.route("/account/logout", get(logout_user))
|
.route("/account/logout", post(logout_user))
|
||||||
.route("/site", get(site_view))
|
.route("/site", get(site_view))
|
||||||
.route_layer(middleware::from_fn(auth))
|
.route_layer(middleware::from_fn(auth))
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ use crate::{
|
||||||
LoginUserForm,
|
LoginUserForm,
|
||||||
Notification,
|
Notification,
|
||||||
RegisterUserForm,
|
RegisterUserForm,
|
||||||
|
SuccessResponse,
|
||||||
AUTH_COOKIE,
|
AUTH_COOKIE,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -125,9 +126,9 @@ fn create_cookie(jwt: String, data: &Data<IbisData>) -> Cookie<'static> {
|
||||||
pub(in crate::backend::api) async fn logout_user(
|
pub(in crate::backend::api) async fn logout_user(
|
||||||
data: Data<IbisData>,
|
data: Data<IbisData>,
|
||||||
jar: CookieJar,
|
jar: CookieJar,
|
||||||
) -> MyResult<CookieJar> {
|
) -> MyResult<(CookieJar, Json<SuccessResponse>)> {
|
||||||
let jar = jar.remove(create_cookie(String::new(), &data));
|
let jar = jar.remove(create_cookie(String::new(), &data));
|
||||||
Ok(jar)
|
Ok((jar, Json(SuccessResponse::default())))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
|
|
|
@ -245,8 +245,14 @@ pub struct FollowInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
pub struct FollowInstanceResponse {
|
pub struct SuccessResponse {
|
||||||
pub success: bool,
|
success: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for SuccessResponse {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { success: true }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, Debug)]
|
#[derive(Deserialize, Serialize, Clone, Debug)]
|
||||||
|
|
|
@ -12,7 +12,6 @@ use crate::{
|
||||||
DeleteConflictForm,
|
DeleteConflictForm,
|
||||||
EditArticleForm,
|
EditArticleForm,
|
||||||
FollowInstance,
|
FollowInstance,
|
||||||
FollowInstanceResponse,
|
|
||||||
ForkArticleForm,
|
ForkArticleForm,
|
||||||
GetArticleForm,
|
GetArticleForm,
|
||||||
GetInstance,
|
GetInstance,
|
||||||
|
@ -27,6 +26,7 @@ use crate::{
|
||||||
ResolveObject,
|
ResolveObject,
|
||||||
SearchArticleForm,
|
SearchArticleForm,
|
||||||
SiteView,
|
SiteView,
|
||||||
|
SuccessResponse,
|
||||||
},
|
},
|
||||||
frontend::error::MyResult,
|
frontend::error::MyResult,
|
||||||
};
|
};
|
||||||
|
@ -105,7 +105,8 @@ impl ApiClient {
|
||||||
&self,
|
&self,
|
||||||
edit_form: &EditArticleForm,
|
edit_form: &EditArticleForm,
|
||||||
) -> MyResult<Option<ApiConflict>> {
|
) -> MyResult<Option<ApiConflict>> {
|
||||||
self.get("/api/v1/article", Some(&edit_form)).await
|
self.send(Method::PATCH, "/api/v1/article", Some(&edit_form))
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn edit_article(&self, edit_form: &EditArticleForm) -> MyResult<ArticleView> {
|
pub async fn edit_article(&self, edit_form: &EditArticleForm) -> MyResult<ArticleView> {
|
||||||
|
@ -180,10 +181,7 @@ impl ApiClient {
|
||||||
Ok(instance_resolved)
|
Ok(instance_resolved)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn follow_instance(
|
pub async fn follow_instance(&self, follow_form: FollowInstance) -> MyResult<SuccessResponse> {
|
||||||
&self,
|
|
||||||
follow_form: FollowInstance,
|
|
||||||
) -> MyResult<FollowInstanceResponse> {
|
|
||||||
self.post("/api/v1/instance/follow", Some(follow_form))
|
self.post("/api/v1/instance/follow", Some(follow_form))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -192,8 +190,8 @@ impl ApiClient {
|
||||||
self.get("/api/v1/site", None::<()>).await
|
self.get("/api/v1/site", None::<()>).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn logout(&self) -> MyResult<()> {
|
pub async fn logout(&self) -> MyResult<SuccessResponse> {
|
||||||
self.get("/api/v1/account/logout", None::<()>).await
|
self.post("/api/v1/account/logout", None::<()>).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fork_article(&self, form: &ForkArticleForm) -> MyResult<ArticleView> {
|
pub async fn fork_article(&self, form: &ForkArticleForm) -> MyResult<ArticleView> {
|
||||||
|
@ -246,8 +244,12 @@ impl ApiClient {
|
||||||
use reqwest::header::HeaderName;
|
use reqwest::header::HeaderName;
|
||||||
let mut req = self
|
let mut req = self
|
||||||
.client
|
.client
|
||||||
.request(method, self.request_endpoint(path))
|
.request(method.clone(), self.request_endpoint(path));
|
||||||
.query(¶ms);
|
req = if method == Method::GET {
|
||||||
|
req.query(¶ms)
|
||||||
|
} else {
|
||||||
|
req.form(¶ms)
|
||||||
|
};
|
||||||
let auth = use_context::<Auth>();
|
let auth = use_context::<Auth>();
|
||||||
if let Some(Auth(Some(auth))) = auth {
|
if let Some(Auth(Some(auth))) = auth {
|
||||||
req = req.header(HeaderName::from_static(AUTH_COOKIE), auth);
|
req = req.header(HeaderName::from_static(AUTH_COOKIE), auth);
|
||||||
|
@ -288,17 +290,18 @@ impl ApiClient {
|
||||||
let path_with_endpoint = self.request_endpoint(path);
|
let path_with_endpoint = self.request_endpoint(path);
|
||||||
let params_encoded = serde_urlencoded::to_string(¶ms).unwrap();
|
let params_encoded = serde_urlencoded::to_string(¶ms).unwrap();
|
||||||
let path = if method == Method::GET {
|
let path = if method == Method::GET {
|
||||||
// Cannot pass the struct directly but need to convert it manually
|
// Cannot pass the form data directly but need to convert it manually
|
||||||
// https://github.com/rustwasm/gloo/issues/378
|
// https://github.com/rustwasm/gloo/issues/378
|
||||||
format!("{path_with_endpoint}?{params_encoded}")
|
format!("{path_with_endpoint}?{params_encoded}")
|
||||||
} else {
|
} else {
|
||||||
path_with_endpoint
|
path_with_endpoint
|
||||||
};
|
};
|
||||||
|
|
||||||
let builder = RequestBuilder::new(&path)
|
let builder = RequestBuilder::new(&path)
|
||||||
.method(method.clone())
|
.method(method.clone())
|
||||||
.abort_signal(abort_signal.as_ref())
|
.abort_signal(abort_signal.as_ref())
|
||||||
.credentials(RequestCredentials::Include);
|
.credentials(RequestCredentials::Include);
|
||||||
let req = if method == Method::POST {
|
let req = if method != Method::GET {
|
||||||
builder
|
builder
|
||||||
.header("content-type", "application/x-www-form-urlencoded")
|
.header("content-type", "application/x-www-form-urlencoded")
|
||||||
.body(params_encoded)
|
.body(params_encoded)
|
||||||
|
|
Loading…
Reference in a new issue