fix clippy performance and sus warnings, remove 1 unwrap, forgot to increment db version
Signed-off-by: strawberry <strawberry@pupbrain.dev>
This commit is contained in:
parent
b4e2f7ca37
commit
2dc1c1fdcb
7 changed files with 47 additions and 22 deletions
|
@ -21,7 +21,10 @@ where
|
||||||
SendAccessToken::IfRequired(hs_token),
|
SendAccessToken::IfRequired(hs_token),
|
||||||
&[MatrixVersion::V1_0],
|
&[MatrixVersion::V1_0],
|
||||||
)
|
)
|
||||||
.unwrap()
|
.map_err(|e| {
|
||||||
|
warn!("Failed to find destination {}: {}", destination, e);
|
||||||
|
Error::BadServerResponse("Invalid destination")
|
||||||
|
})?
|
||||||
.map(|body| body.freeze());
|
.map(|body| body.freeze());
|
||||||
|
|
||||||
let mut parts = http_request.uri().clone().into_parts();
|
let mut parts = http_request.uri().clone().into_parts();
|
||||||
|
|
|
@ -84,12 +84,11 @@ pub async fn set_displayname_route(
|
||||||
);
|
);
|
||||||
let state_lock = mutex_state.lock().await;
|
let state_lock = mutex_state.lock().await;
|
||||||
|
|
||||||
let _ = services().rooms.timeline.build_and_append_pdu(
|
let _ = services()
|
||||||
pdu_builder,
|
.rooms
|
||||||
sender_user,
|
.timeline
|
||||||
&room_id,
|
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock)
|
||||||
&state_lock,
|
.await;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if services().globals.allow_local_presence() {
|
if services().globals.allow_local_presence() {
|
||||||
|
@ -207,12 +206,11 @@ pub async fn set_avatar_url_route(
|
||||||
);
|
);
|
||||||
let state_lock = mutex_state.lock().await;
|
let state_lock = mutex_state.lock().await;
|
||||||
|
|
||||||
let _ = services().rooms.timeline.build_and_append_pdu(
|
let _ = services()
|
||||||
pdu_builder,
|
.rooms
|
||||||
sender_user,
|
.timeline
|
||||||
&room_id,
|
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock)
|
||||||
&state_lock,
|
.await;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if services().globals.allow_local_presence() {
|
if services().globals.allow_local_presence() {
|
||||||
|
|
|
@ -427,7 +427,14 @@ impl KeyValueDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the database has any data, perform data migrations before starting
|
// If the database has any data, perform data migrations before starting
|
||||||
let latest_database_version = 13;
|
let latest_database_version: u64;
|
||||||
|
|
||||||
|
// do not increment the db version if the user is not using sha256_media
|
||||||
|
if cfg!(feature = "sha256_media") {
|
||||||
|
latest_database_version = 14;
|
||||||
|
} else {
|
||||||
|
latest_database_version = 13;
|
||||||
|
}
|
||||||
|
|
||||||
if services().users.count()? > 0 {
|
if services().users.count()? > 0 {
|
||||||
// MIGRATIONS
|
// MIGRATIONS
|
||||||
|
@ -959,7 +966,7 @@ impl KeyValueDatabase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
services().globals.bump_database_version(13)?;
|
services().globals.bump_database_version(14)?;
|
||||||
|
|
||||||
warn!("Migration: 13 -> 14 finished");
|
warn!("Migration: 13 -> 14 finished");
|
||||||
} else {
|
} else {
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -17,7 +17,7 @@ use axum::{
|
||||||
extract::{DefaultBodyLimit, FromRequestParts, MatchedPath},
|
extract::{DefaultBodyLimit, FromRequestParts, MatchedPath},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
routing::{get, on, MethodFilter},
|
routing::{get, on, MethodFilter},
|
||||||
Router,
|
Json, Router,
|
||||||
};
|
};
|
||||||
use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle};
|
use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle};
|
||||||
use conduit::api::{client_server, server_server};
|
use conduit::api::{client_server, server_server};
|
||||||
|
@ -38,6 +38,7 @@ use ruma::api::{
|
||||||
},
|
},
|
||||||
IncomingRequest,
|
IncomingRequest,
|
||||||
};
|
};
|
||||||
|
use serde::Deserialize;
|
||||||
use tokio::{net::UnixListener, signal, sync::oneshot};
|
use tokio::{net::UnixListener, signal, sync::oneshot};
|
||||||
use tower::ServiceBuilder;
|
use tower::ServiceBuilder;
|
||||||
use tower_http::{
|
use tower_http::{
|
||||||
|
@ -214,7 +215,7 @@ async fn run_server() -> io::Result<()> {
|
||||||
|
|
||||||
let app: axum::routing::IntoMakeService<Router>;
|
let app: axum::routing::IntoMakeService<Router>;
|
||||||
|
|
||||||
if cfg!(feature = "zstd_compression") && config.zstd_compression == true {
|
if cfg!(feature = "zstd_compression") && config.zstd_compression {
|
||||||
debug!("zstd body compression is enabled");
|
debug!("zstd body compression is enabled");
|
||||||
app = routes()
|
app = routes()
|
||||||
.layer(middlewares.compression())
|
.layer(middlewares.compression())
|
||||||
|
@ -489,6 +490,7 @@ fn routes() -> Router {
|
||||||
"/_matrix/client/v3/rooms/:room_id/initialSync",
|
"/_matrix/client/v3/rooms/:room_id/initialSync",
|
||||||
get(initial_sync),
|
get(initial_sync),
|
||||||
)
|
)
|
||||||
|
//.route("/client/server.json", get(syncv3_client_server_json))
|
||||||
.route("/", get(it_works))
|
.route("/", get(it_works))
|
||||||
.fallback(not_found)
|
.fallback(not_found)
|
||||||
}
|
}
|
||||||
|
@ -543,9 +545,22 @@ async fn initial_sync(_uri: Uri) -> impl IntoResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn it_works() -> &'static str {
|
async fn it_works() -> &'static str {
|
||||||
"Hello from Conduit!"
|
"hewwo from cowonduit woof!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// TODO: add /client/server.json support by querying our client well-known for the true matrix homeserver URL
|
||||||
|
async fn syncv3_client_server_json(uri: Uri) -> impl IntoResponse {
|
||||||
|
let server_name = services().globals.server_name().to_string();
|
||||||
|
let response = services().globals.default_client().get(&format!("https://{server_name"))
|
||||||
|
let server = uri.scheme_str().unwrap_or("https").to_owned() + "://" + uri.host().unwrap();
|
||||||
|
let version = format!("cowonduit {}", env!("CARGO_PKG_VERSION").to_owned());
|
||||||
|
let body = format!("{{\"server\":\"{server}\",\"version\":\"{version}\"}}");
|
||||||
|
|
||||||
|
Json(body)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
trait RouterExt {
|
trait RouterExt {
|
||||||
fn ruma_route<H, T>(self, handler: H) -> Self
|
fn ruma_route<H, T>(self, handler: H) -> Self
|
||||||
where
|
where
|
||||||
|
|
|
@ -490,7 +490,7 @@ impl Service {
|
||||||
if self.unix_socket_path().is_some() {
|
if self.unix_socket_path().is_some() {
|
||||||
match &self.unix_socket_path() {
|
match &self.unix_socket_path() {
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
std::fs::remove_file(path.to_owned()).unwrap();
|
std::fs::remove_file(path).unwrap();
|
||||||
}
|
}
|
||||||
None => error!(
|
None => error!(
|
||||||
"Unable to remove socket file at {:?} during shutdown.",
|
"Unable to remove socket file at {:?} during shutdown.",
|
||||||
|
|
|
@ -149,7 +149,9 @@ impl Service {
|
||||||
// TODO: Sort children
|
// TODO: Sort children
|
||||||
children_ids.reverse();
|
children_ids.reverse();
|
||||||
|
|
||||||
let chunk = self.get_room_chunk(sender_user, ¤t_room, children_pdus);
|
let chunk = self
|
||||||
|
.get_room_chunk(sender_user, ¤t_room, children_pdus)
|
||||||
|
.await;
|
||||||
if let Ok(chunk) = chunk {
|
if let Ok(chunk) = chunk {
|
||||||
if left_to_skip > 0 {
|
if left_to_skip > 0 {
|
||||||
left_to_skip -= 1;
|
left_to_skip -= 1;
|
||||||
|
@ -303,7 +305,7 @@ impl Service {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_room_chunk(
|
async fn get_room_chunk(
|
||||||
&self,
|
&self,
|
||||||
sender_user: &UserId,
|
sender_user: &UserId,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
|
|
|
@ -859,7 +859,7 @@ impl Service {
|
||||||
|
|
||||||
let target = pdu
|
let target = pdu
|
||||||
.state_key()
|
.state_key()
|
||||||
.filter(|v| v.starts_with("@"))
|
.filter(|v| v.starts_with('@'))
|
||||||
.unwrap_or(sender.as_str());
|
.unwrap_or(sender.as_str());
|
||||||
let server_name = services().globals.server_name();
|
let server_name = services().globals.server_name();
|
||||||
let server_user = format!("@conduit:{}", server_name);
|
let server_user = format!("@conduit:{}", server_name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue