Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
32 changes: 0 additions & 32 deletions src/routes/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

impl IndexTemplate {
pub async fn new(
context: AppStateContext,
Expand All @@ -49,32 +40,9 @@ impl IndexTemplate {
}
}

impl UploadTemplate {
pub async fn new(context: AppStateContext) -> Result<Self, AppStateError> {
let categories: Vec<String> = 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<FlashTemplate<IndexTemplate>, AppStateError> {
IndexTemplate::new(context, status).await
}

pub async fn upload(context: AppStateContext) -> Result<UploadTemplate, AppStateError> {
UploadTemplate::new(context).await
}
2 changes: 0 additions & 2 deletions src/state/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use super::*;
/// by rendering the AppStateError into an axum Response.
pub struct AppStateContext {
pub db: DatabaseOperator,
pub errors: Vec<AppStateError>,
pub free_space: FreeSpace,
pub state: AppState,
pub user: Option<User>,
Expand All @@ -29,7 +28,6 @@ impl FromRequestParts<AppState> for AppStateContext {

Ok(Self {
db: DatabaseOperator::new(state.clone(), user.clone()),
errors: vec![],
free_space: state.free_space()?,
state: state.clone(),
user,
Expand Down
20 changes: 4 additions & 16 deletions src/state/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppStateError>,
}

impl From<AppStateError> for AppStateErrorContext {
impl From<AppStateError> 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()
}
}
Expand Down
16 changes: 1 addition & 15 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,7 @@
{% include "menus/header.html" %}

<section class="section" style="padding-top: 100px;">
<div class="container">
{% for error in state.errors %}
<div class="notification is-danger">
<details>
<summary>{{ error }}</summary>
<ul class="ml-5">
{% for inner_error in error.inner_errors() %}
<li>→ {{ inner_error }}</li>
{% endfor %}
</ul>
</details>
</div>
{% endfor %}
</div>

{% block errors %}{% endblock %}
{% block main %}{% endblock %}
</section>

Expand Down
17 changes: 16 additions & 1 deletion templates/error.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
{% extends "base.html" %}

{% block main %}
{% block errors %}
<div class="container">
{% for error in errors %}
<div class="notification is-danger">
<details>
<summary>{{ error }}</summary>
<ul class="ml-5">
{% for inner_error in error.inner_errors() %}
<li>→ {{ inner_error }}</li>
{% endfor %}
</ul>
</details>
</div>
{% endfor %}
</div>
{% endblock %}

{% block footer_extra %}
{# Maybe we failed to load some of the global state displayed in the footer #}
{% endblock %}
4 changes: 1 addition & 3 deletions templates/progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ <h1>Torrents list</h1>

<div class="card mt-4">
<div class="card-body">
{% if state.errors.len() != 0 %}
<h2>Could not reach Bittorrent client (see errors above)</h2>
{% else if torrent_list.torrents.len() == 0 %}
{% if torrent_list.torrents.len() == 0 %}
{% include "shared/empty_state.html" %}
{% else %}
{% include "progress_table.html" %}
Expand Down
16 changes: 0 additions & 16 deletions templates/sources/magnet.html

This file was deleted.

14 changes: 0 additions & 14 deletions templates/sources/torrent.html

This file was deleted.

71 changes: 0 additions & 71 deletions templates/upload.html

This file was deleted.