mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-23 08:57:35 +00:00
Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05a49ceb60 | ||
|
|
728c5828ba | ||
|
|
50c94d85a1 | ||
|
|
0cc188f62c | ||
|
|
6451671f66 | ||
|
|
ca21a885d5 | ||
|
|
4af4110f6d | ||
|
|
51b450c05c | ||
|
|
f9d1f71343 | ||
|
|
7901e4b996 | ||
|
|
7b6bf4b78e | ||
|
|
67d5619ccb | ||
|
|
bf001f96d6 | ||
|
|
ae2b87f03f | ||
|
|
957cd3502f | ||
|
|
a109542eb8 | ||
|
|
8c4844b00b | ||
|
|
eec7103910 | ||
|
|
43aa172829 | ||
|
|
9b4c483b6d | ||
|
|
b885e206ce | ||
|
|
07a935f625 | ||
|
|
d13801e976 | ||
|
|
5716c36b47 | ||
|
|
f11943b956 | ||
|
|
8b726a9c94 | ||
|
|
ffa3c53847 | ||
|
|
da8833fca4 | ||
|
|
267feb3c09 | ||
|
|
3d50af0943 |
No files matched your search
@@ -969,3 +969,6 @@ needless_raw_string_hashes = "allow"
|
||||
|
||||
# TODO: Enable this lint & fix all instances
|
||||
collapsible_if = "allow"
|
||||
|
||||
# TODO: break these apart
|
||||
cognitive_complexity = "allow"
|
||||
@@ -1,10 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::{
|
||||
Router,
|
||||
response::{IntoResponse, Redirect},
|
||||
routing::get,
|
||||
};
|
||||
use axum::{Router, response::IntoResponse};
|
||||
use conduwuit::Error;
|
||||
use conduwuit_service::{Services, state, state::Guard};
|
||||
use http::{StatusCode, Uri};
|
||||
@@ -14,8 +10,7 @@ pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
|
||||
let router = Router::<state::State>::new();
|
||||
let (state, guard) = state::create(services.clone());
|
||||
let router = conduwuit_api::router::build(router, &services.server)
|
||||
.nest("/_continuwuity/", conduwuit_web::build())
|
||||
.route("/", get(async || Redirect::permanent("/_continuwuity/")))
|
||||
.merge(conduwuit_web::build())
|
||||
.fallback(not_found)
|
||||
.with_state(state);
|
||||
|
||||
@@ -23,5 +18,5 @@ pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
|
||||
}
|
||||
|
||||
async fn not_found(_uri: Uri) -> impl IntoResponse {
|
||||
Error::Request(ErrorKind::Unrecognized, "Not Found".into(), StatusCode::NOT_FOUND)
|
||||
Error::Request(ErrorKind::Unrecognized, "not found :(".into(), StatusCode::NOT_FOUND)
|
||||
}
|
||||
+35
-13
@@ -1,3 +1,5 @@
|
||||
use std::any::Any;
|
||||
|
||||
use askama::Template;
|
||||
use axum::{
|
||||
Router,
|
||||
@@ -6,7 +8,7 @@ use axum::{
|
||||
response::{Html, IntoResponse, Response},
|
||||
};
|
||||
use conduwuit_service::state;
|
||||
use tower_http::set_header::SetResponseHeaderLayer;
|
||||
use tower_http::{catch_panic::CatchPanicLayer, set_header::SetResponseHeaderLayer};
|
||||
use tower_sec_fetch::SecFetchLayer;
|
||||
|
||||
use crate::pages::TemplateContext;
|
||||
@@ -15,24 +17,29 @@ mod pages;
|
||||
|
||||
type State = state::State;
|
||||
|
||||
const CATASTROPHIC_FAILURE: &str = "cat-astrophic failure! we couldn't even render the error template. \
|
||||
please contact the team @ https://continuwuity.org";
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
enum WebError {
|
||||
#[error("Failed to render template: {0}")]
|
||||
Render(#[from] askama::Error),
|
||||
#[error("Failed to validate form body: {0}")]
|
||||
ValidationError(#[from] validator::ValidationErrors),
|
||||
|
||||
#[error("{0}")]
|
||||
QueryRejection(#[from] QueryRejection),
|
||||
#[error("{0}")]
|
||||
FormRejection(#[from] FormRejection),
|
||||
|
||||
#[error("Bad request: {0}")]
|
||||
#[error("{0}")]
|
||||
BadRequest(String),
|
||||
|
||||
#[error("This page does not exist.")]
|
||||
NotFound,
|
||||
#[error("Internal server error: {0}")]
|
||||
|
||||
#[error("Failed to render template: {0}")]
|
||||
Render(#[from] askama::Error),
|
||||
#[error("{0}")]
|
||||
InternalError(#[from] conduwuit_core::Error),
|
||||
#[error("Request handler panicked! {0}")]
|
||||
Panic(String),
|
||||
}
|
||||
|
||||
impl IntoResponse for WebError {
|
||||
@@ -58,8 +65,7 @@ impl IntoResponse for WebError {
|
||||
error: self,
|
||||
status,
|
||||
context: TemplateContext {
|
||||
// Statically set false to prevent error pages from being indexed and to prevent
|
||||
// further errors if services.config is having issues.
|
||||
// Statically set false to prevent error pages from being indexed.
|
||||
allow_indexing: false,
|
||||
},
|
||||
};
|
||||
@@ -67,7 +73,7 @@ impl IntoResponse for WebError {
|
||||
if let Ok(body) = template.render() {
|
||||
(status, Html(body)).into_response()
|
||||
} else {
|
||||
(status, "Something went wrong").into_response()
|
||||
(status, CATASTROPHIC_FAILURE).into_response()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,9 +84,25 @@ pub fn build() -> Router<state::State> {
|
||||
|
||||
Router::new()
|
||||
.merge(index::build())
|
||||
.merge(resources::build())
|
||||
.merge(password_reset::build())
|
||||
.fallback(async || WebError::NotFound)
|
||||
.nest(
|
||||
"/_continuwuity/",
|
||||
Router::new()
|
||||
.merge(resources::build())
|
||||
.merge(password_reset::build())
|
||||
.merge(debug::build())
|
||||
.fallback(async || WebError::NotFound),
|
||||
)
|
||||
.layer(CatchPanicLayer::custom(|panic: Box<dyn Any + Send + 'static>| {
|
||||
let details = if let Some(s) = panic.downcast_ref::<String>() {
|
||||
s.clone()
|
||||
} else if let Some(s) = panic.downcast_ref::<&str>() {
|
||||
(*s).to_owned()
|
||||
} else {
|
||||
"(opaque panic payload)".to_owned()
|
||||
};
|
||||
|
||||
WebError::Panic(details).into_response()
|
||||
}))
|
||||
.layer(SetResponseHeaderLayer::if_not_present(
|
||||
header::CONTENT_SECURITY_POLICY,
|
||||
HeaderValue::from_static("default-src 'self'; img-src 'self' data:;"),
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
use std::convert::Infallible;
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
use conduwuit_core::Error;
|
||||
|
||||
use crate::WebError;
|
||||
|
||||
pub(crate) fn build() -> Router<crate::State> {
|
||||
Router::new()
|
||||
.route("/_debug/panic", get(async || -> Infallible { panic!("Guru meditation error") }))
|
||||
.route(
|
||||
"/_debug/error",
|
||||
get(async || -> WebError {
|
||||
Error::Err(std::borrow::Cow::Borrowed("Guru meditation error")).into()
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -3,7 +3,11 @@ use axum::{Router, extract::State, response::IntoResponse, routing::get};
|
||||
|
||||
use crate::{WebError, template};
|
||||
|
||||
pub(crate) fn build() -> Router<crate::State> { Router::new().route("/", get(index_handler)) }
|
||||
pub(crate) fn build() -> Router<crate::State> {
|
||||
Router::new()
|
||||
.route("/", get(index_handler))
|
||||
.route("/_continuwuity/", get(index_handler))
|
||||
}
|
||||
|
||||
async fn index_handler(
|
||||
State(services): State<crate::State>,
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
mod components;
|
||||
pub(super) mod debug;
|
||||
pub(super) mod index;
|
||||
pub(super) mod password_reset;
|
||||
pub(super) mod resources;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct TemplateContext {
|
||||
pub allow_indexing: bool,
|
||||
}
|
||||
|
||||
impl From<&crate::State> for TemplateContext {
|
||||
fn from(state: &crate::State) -> Self {
|
||||
Self {
|
||||
@@ -13,6 +16,7 @@ impl From<&crate::State> for TemplateContext {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! template {
|
||||
(
|
||||
|
||||
@@ -18,6 +18,8 @@ use crate::{
|
||||
template,
|
||||
};
|
||||
|
||||
const INVALID_TOKEN_ERROR: &str = "Invalid reset token. Your reset link may have expired.";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct PasswordResetQuery {
|
||||
token: String,
|
||||
@@ -67,7 +69,7 @@ async fn password_reset_form(
|
||||
reset_form: Form<'static>,
|
||||
) -> Result<impl IntoResponse, WebError> {
|
||||
let Some(token) = services.password_reset.check_token(&query.token).await else {
|
||||
return Err(WebError::BadRequest("Invalid reset token".to_owned()));
|
||||
return Err(WebError::BadRequest(INVALID_TOKEN_ERROR.to_owned()));
|
||||
};
|
||||
|
||||
let user_card = UserCard::for_local_user(&services, &token.info.user).await;
|
||||
@@ -96,7 +98,7 @@ async fn post_password_reset(
|
||||
match form.validate() {
|
||||
| Ok(()) => {
|
||||
let Some(token) = services.password_reset.check_token(&query.token).await else {
|
||||
return Err(WebError::BadRequest("Invalid reset token".to_owned()));
|
||||
return Err(WebError::BadRequest(INVALID_TOKEN_ERROR.to_owned()));
|
||||
};
|
||||
let user_id = token.info.user.clone();
|
||||
|
||||
|
||||
@@ -24,12 +24,17 @@
|
||||
<h1>
|
||||
{% if status == StatusCode::NOT_FOUND %}
|
||||
Not found
|
||||
{% else if status == StatusCode::INTERNAL_SERVER_ERROR %}
|
||||
Internal server error
|
||||
{% else %}
|
||||
Request error
|
||||
Bad request
|
||||
{% endif %}
|
||||
<small aria-hidden>(︶^︶)</small>
|
||||
</h1>
|
||||
|
||||
{% if status == StatusCode::INTERNAL_SERVER_ERROR %}
|
||||
<p>Please <a href="https://forgejo.ellis.link/continuwuation/continuwuity/issues/new">submit a bug report</a> 🥺</p>
|
||||
{% endif %}
|
||||
|
||||
<pre><code>{{ error }}</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user