diff --git a/src/lib.rs b/src/lib.rs index ae60294..5ce54d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,6 @@ pub fn router(state: state::AppState) -> Router { Router::new() // Register dynamic routes .route("/", get(routes::index::index)) - .route("/upload", get(routes::index::upload)) .route("/progress/{view_request}", get(routes::progress::progress)) .route("/categories", post(routes::category::create)) .route("/categories/new", get(routes::category::new)) diff --git a/src/routes/index.rs b/src/routes/index.rs index aa6f73d..4a3dc6b 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -24,15 +24,6 @@ impl FallibleTemplate for IndexTemplate { } } -#[derive(Template, WebTemplate)] -#[template(path = "upload.html")] -pub struct UploadTemplate { - /// Global application state (errors/warnings) - pub state: AppStateContext, - /// Categories - pub categories: Vec, -} - impl IndexTemplate { pub async fn new( context: AppStateContext, @@ -49,32 +40,9 @@ impl IndexTemplate { } } -impl UploadTemplate { - pub async fn new(context: AppStateContext) -> Result { - let categories: Vec = context - .db - .category() - .list() - .await - .context(CategorySnafu)? - .into_iter() - .map(|x| x.name.to_string()) - .collect(); - - Ok(UploadTemplate { - state: context, - categories, - }) - } -} - pub async fn index( context: AppStateContext, status: StatusCookie, ) -> Result, AppStateError> { IndexTemplate::new(context, status).await } - -pub async fn upload(context: AppStateContext) -> Result { - UploadTemplate::new(context).await -} diff --git a/src/state/context.rs b/src/state/context.rs index e075e9a..b964849 100644 --- a/src/state/context.rs +++ b/src/state/context.rs @@ -12,7 +12,6 @@ use super::*; /// by rendering the AppStateError into an axum Response. pub struct AppStateContext { pub db: DatabaseOperator, - pub errors: Vec, pub free_space: FreeSpace, pub state: AppState, pub user: Option, @@ -29,7 +28,6 @@ impl FromRequestParts for AppStateContext { Ok(Self { db: DatabaseOperator::new(state.clone(), user.clone()), - errors: vec![], free_space: state.free_space()?, state: state.clone(), user, diff --git a/src/state/error.rs b/src/state/error.rs index a2a3876..5123667 100644 --- a/src/state/error.rs +++ b/src/state/error.rs @@ -61,33 +61,21 @@ impl AppStateError { /// Global error page generated from an [AppStateError]. #[derive(Debug, Template, WebTemplate)] #[template(path = "error.html")] -pub struct AppStateErrorContext { - state: AppStateErrorContextInner, -} - -/// Helper struct so we can reuse base.html -/// with all it's `state.foo` expressions. -#[derive(Debug)] -pub struct AppStateErrorContextInner { - // TODO: askama doesn't handle recursion well, so we convert - // all errors to strings. Maybe related to: - // https://github.com/askama-rs/askama/issues/393 +pub struct AppStateErrorTemplate { errors: Vec, } -impl From for AppStateErrorContext { +impl From for AppStateErrorTemplate { fn from(e: AppStateError) -> Self { // An error is being displayed to the user, make sure it's also written in the logs e.log(); - Self { - state: AppStateErrorContextInner { errors: vec![e] }, - } + Self { errors: vec![e] } } } impl IntoResponse for AppStateError { fn into_response(self) -> Response { - let error_context = AppStateErrorContext::from(self); + let error_context = AppStateErrorTemplate::from(self); (StatusCode::INTERNAL_SERVER_ERROR, error_context).into_response() } } diff --git a/templates/base.html b/templates/base.html index f474fe1..9e5a1b9 100755 --- a/templates/base.html +++ b/templates/base.html @@ -15,21 +15,7 @@ {% include "menus/header.html" %}
-
- {% for error in state.errors %} -
-
- {{ error }} -
    - {% for inner_error in error.inner_errors() %} -
  • → {{ inner_error }}
  • - {% endfor %} -
-
-
- {% endfor %} -
- + {% block errors %}{% endblock %} {% block main %}{% endblock %}
diff --git a/templates/error.html b/templates/error.html index 0226523..ac04f4b 100755 --- a/templates/error.html +++ b/templates/error.html @@ -1,7 +1,22 @@ {% extends "base.html" %} -{% block main %} +{% block errors %} +
+ {% for error in errors %} +
+
+ {{ error }} +
    + {% for inner_error in error.inner_errors() %} +
  • → {{ inner_error }}
  • + {% endfor %} +
+
+
+ {% endfor %} +
{% endblock %} {% block footer_extra %} +{# Maybe we failed to load some of the global state displayed in the footer #} {% endblock %} diff --git a/templates/progress.html b/templates/progress.html index 9f4b505..ef0e157 100755 --- a/templates/progress.html +++ b/templates/progress.html @@ -20,9 +20,7 @@

Torrents list

- {% if state.errors.len() != 0 %} -

Could not reach Bittorrent client (see errors above)

- {% else if torrent_list.torrents.len() == 0 %} + {% if torrent_list.torrents.len() == 0 %} {% include "shared/empty_state.html" %} {% else %} {% include "progress_table.html" %} diff --git a/templates/sources/magnet.html b/templates/sources/magnet.html deleted file mode 100755 index 2d1485d..0000000 --- a/templates/sources/magnet.html +++ /dev/null @@ -1,16 +0,0 @@ -
-
-

- -

- -
-
- -
-
- -
-
-
-
diff --git a/templates/sources/torrent.html b/templates/sources/torrent.html deleted file mode 100755 index 41a951d..0000000 --- a/templates/sources/torrent.html +++ /dev/null @@ -1,14 +0,0 @@ -
-
-

Torrent file

- -
-
- -
-
- -
-
-
-
diff --git a/templates/upload.html b/templates/upload.html deleted file mode 100644 index 05a8542..0000000 --- a/templates/upload.html +++ /dev/null @@ -1,71 +0,0 @@ -{% extends "base.html" %} - -{% block main %} -
-

Download files

- - {% if state.free_space.free_space_percent < 5 %} -
- The disks are almost full : {{ state.free_space.free_space_gib }} GiB left -
- {% endif %} - -
-
-
-
- -
Choose the type of content you want to download.
- -
-
-
- -
-
- {% include "sources/magnet.html" %} -
- -
-
-

OR

-
-
- -
- {% include "sources/torrent.html" %} -
-
- -
- -
-
- - {% if categories.len() == 0 %} - - - - {% endif %} -
-{% endblock %}