Browse Source

Add a Downloader page and the force download button.

tags/0.1.0
Bauke 10 months ago
parent
commit
87011c14ee
Signed by: Bauke <me@bauke.xyz> GPG Key ID: C1C0F29952BCF558
6 changed files with 78 additions and 0 deletions
  1. +2
    -0
      source/main.rs
  2. +37
    -0
      source/routes/html/downloader.rs
  3. +1
    -0
      source/routes/html/mod.rs
  4. +6
    -0
      source/scss/downloader.scss
  5. +31
    -0
      source/templates/downloader.html.tera
  6. +1
    -0
      source/templates/includes/footer.html.tera

+ 2
- 0
source/main.rs View File

@@ -103,6 +103,8 @@ fn create_rocket(
// TODO: Add HTML minifying for Template-based responses.
let html_routes = routes![
routes::html::index,
routes::html::downloader::downloader_get,
routes::html::downloader::force_download_post,
routes::html::feed::add,
routes::html::feed::delete,
routes::html::feed::edit_get,


+ 37
- 0
source/routes/html/downloader.rs View File

@@ -0,0 +1,37 @@
use std::sync::Mutex;

use rocket::request::FlashMessage;
use rocket::response::{Flash, Redirect};
use rocket::State;
use rocket_contrib::templates::Template;

use crate::downloader::{DownloaderInstruction, DownloaderInstructor};
use crate::models::settings::DefaultContext;

#[get("/downloader")]
pub fn downloader_get(
context: DefaultContext,
flash: Option<FlashMessage>,
) -> Template {
let mut context = context.ctx;
context.insert("page_title", "Downloader");

if let Some(value) = flash {
context.insert("flash_name", &value.name());
context.insert("flash_message", &value.msg());
}

Template::render("downloader", &context.into_json())
}

#[post("/downloader/force_download")]
pub fn force_download_post(
dl_instructor: State<Mutex<DownloaderInstructor>>,
) -> Flash<Redirect> {
let instructor = dl_instructor.lock().unwrap();
instructor
.send(DownloaderInstruction::ForceDownloadAll)
.unwrap();

Flash::new(Redirect::to(uri!(downloader_get)), "info", "Starting the downloader and force downloading all feeds, this may take a while.")
}

+ 1
- 0
source/routes/html/mod.rs View File

@@ -37,5 +37,6 @@ pub fn index(
Template::render("index", &context.into_json())
}

pub mod downloader;
pub mod feed;
pub mod settings;

+ 6
- 0
source/scss/downloader.scss View File

@@ -0,0 +1,6 @@
.section:not(.flash) {
h2,
p {
margin-bottom: 8px;
}
}

+ 31
- 0
source/templates/downloader.html.tera View File

@@ -0,0 +1,31 @@
{% extends "base" %}

{% import "macros/base" as m_base %}

{% block head %}
<link rel="stylesheet" href="/css/downloader.css">
{% endblock %}

{% block body %}
<div class="responsive-width">
{{ m_base::header(title="Downloader") }}

{% include "includes/flash" %}

<div class="section">
<h2>Force Download</h2>
<p>
Force downloading all feeds will go through and download each feed,
even if it had been downloaded in the last 30 minutes. Depending on how many feeds
are saved this could take a while and be resource intensive.
</p>
<form action="/downloader/force_download" method="POST">
<button class="button" title="Force Download All Feeds" type="submit">
Force Download All Feeds
</button>
</form>
</div>

{% include "includes/footer" %}
</div>
{% endblock %}

+ 1
- 0
source/templates/includes/footer.html.tera View File

@@ -1,6 +1,7 @@
<footer id="footer" class="section">
<div class="on-site">
<a href="/">Home</a>
<a href="/downloader">Downloader</a>
<a href="/settings">Settings</a>
</div>
<div class="off-site">


Loading…
Cancel
Save