update deps
This commit is contained in:
@ -15,23 +15,23 @@ futures = "0.3"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
sled = "0.34"
|
||||
semver = "0.11"
|
||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||
uuid = { version = "1.8.0", features = ["serde", "v4"] }
|
||||
duplicate = "0.2"
|
||||
bincode = "1"
|
||||
handlebars = "3"
|
||||
handlebars = "4.1.0"
|
||||
itertools = "0.10.0"
|
||||
|
||||
[dependencies.stl_lib]
|
||||
path = "../lib"
|
||||
|
||||
[dependencies.tokio]
|
||||
version = "1"
|
||||
version = "1.37.0"
|
||||
features = ["sync", "time"]
|
||||
|
||||
[dependencies.rocket]
|
||||
version = "0.5.0-rc.1"
|
||||
version = "0.5.0"
|
||||
features = ["secrets", "json", "uuid"]
|
||||
|
||||
[dependencies.rocket_dyn_templates]
|
||||
version = "0.1.0-rc.1"
|
||||
version = "0.1.0"
|
||||
features = ["handlebars"]
|
||||
|
||||
@ -5,7 +5,7 @@ use rocket::{
|
||||
http::{Cookie, CookieJar, Status},
|
||||
post,
|
||||
request::{FromRequest, Outcome, Request},
|
||||
response::{content::Html, Redirect},
|
||||
response::{content::RawHtml, Redirect},
|
||||
uri, State,
|
||||
};
|
||||
use rocket_dyn_templates::Template;
|
||||
@ -45,7 +45,7 @@ impl<'a> FromRequest<'a> for Authorized {
|
||||
request
|
||||
.guard::<&State<MasterPassword>>()
|
||||
.await
|
||||
.map_failure(|_| (Status::Unauthorized, Unauthorized))
|
||||
.map_error(|_| (Status::Unauthorized, Unauthorized))
|
||||
.and_then(|master_pass| {
|
||||
// Check if query string contains password
|
||||
request
|
||||
@ -65,14 +65,14 @@ impl<'a> FromRequest<'a> for Authorized {
|
||||
.filter(|(_, v)| v == &master_pass.0)
|
||||
.map(|_| Outcome::Success(Authorized))
|
||||
.next()
|
||||
.unwrap_or(Outcome::Failure((Status::Unauthorized, Unauthorized)))
|
||||
.unwrap_or(Outcome::Error((Status::Unauthorized, Unauthorized)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[catch(401)]
|
||||
pub fn login_page(_req: &Request) -> Html<Template> {
|
||||
Html(Template::render("login", &()))
|
||||
pub fn login_page(_req: &Request) -> RawHtml<Template> {
|
||||
RawHtml(Template::render("login", &()))
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
|
||||
@ -28,8 +28,8 @@ pub fn migrate(db: &mut Db) -> Result<(), MigrationError> {
|
||||
// Convert to new value
|
||||
let v2_value = v2::trees::session::V {
|
||||
category,
|
||||
started: DateTime::<Utc>::from_utc(started, Utc).into(),
|
||||
ended: DateTime::<Utc>::from_utc(ended, Utc).into(),
|
||||
started: DateTime::<Utc>::from_naive_utc_and_offset(started, Utc).into(),
|
||||
ended: DateTime::<Utc>::from_naive_utc_and_offset(ended, Utc).into(),
|
||||
deleted: false,
|
||||
};
|
||||
|
||||
@ -63,7 +63,8 @@ pub fn migrate(db: &mut Db) -> Result<(), MigrationError> {
|
||||
name,
|
||||
description: None,
|
||||
color,
|
||||
started: started.map(|ndt| DateTime::<Utc>::from_utc(ndt, Utc).into()),
|
||||
started: started
|
||||
.map(|ndt| DateTime::<Utc>::from_naive_utc_and_offset(ndt, Utc).into()),
|
||||
parent: None,
|
||||
deleted: false,
|
||||
};
|
||||
|
||||
@ -33,7 +33,9 @@ async fn main() -> io::Result<()> {
|
||||
|
||||
let birth_date: BirthDate = env::var("BIRTH_DATE")
|
||||
.map(|s| BirthDate(s.parse().expect("failed to parse BIRTH_DATE")))
|
||||
.unwrap_or_else(|_| BirthDate(NaiveDate::from_ymd(2000, 1, 1)));
|
||||
.unwrap_or_else(|_| {
|
||||
BirthDate(NaiveDate::from_ymd_opt(2000, 1, 1).expect("Date is correct"))
|
||||
});
|
||||
|
||||
let mut sled = sled::open(db_path)?;
|
||||
match sled.insert(
|
||||
|
||||
@ -9,7 +9,7 @@ use crate::status_json::StatusJson;
|
||||
use crate::util::EventNotifier;
|
||||
use bincode::{deserialize, serialize};
|
||||
use rocket::http::Status;
|
||||
use rocket::response::content::Html;
|
||||
use rocket::response::content::RawHtml;
|
||||
use rocket::response::Redirect;
|
||||
use rocket::serde::uuid::Uuid;
|
||||
use rocket::{get, post, uri, State};
|
||||
@ -19,7 +19,7 @@ use std::collections::{BTreeMap, HashMap};
|
||||
use std::time::Duration;
|
||||
|
||||
#[get("/")]
|
||||
pub fn index(_auth: Authorized, db: &State<sled::Db>) -> Result<Html<Template>, StatusJson> {
|
||||
pub fn index(_auth: Authorized, db: &State<sled::Db>) -> Result<RawHtml<Template>, StatusJson> {
|
||||
#[derive(Debug, Serialize, Deserialize, PartialOrd, Ord, PartialEq, Eq)]
|
||||
struct Node {
|
||||
category: category::V,
|
||||
@ -92,7 +92,7 @@ pub fn index(_auth: Authorized, db: &State<sled::Db>) -> Result<Html<Template>,
|
||||
categories: top_level_nodes,
|
||||
};
|
||||
|
||||
Ok(Html(Template::render("index", &context)))
|
||||
Ok(RawHtml(Template::render("index", &context)))
|
||||
}
|
||||
|
||||
#[post("/category/<category_uuid>/start_session")]
|
||||
@ -166,7 +166,7 @@ pub fn session_edit(
|
||||
_auth: Authorized,
|
||||
session_uuid: Uuid,
|
||||
db: &State<sled::Db>,
|
||||
) -> Result<Html<Template>, StatusJson> {
|
||||
) -> Result<RawHtml<Template>, StatusJson> {
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct SessionPageContext {
|
||||
session: session::V,
|
||||
@ -184,13 +184,13 @@ pub fn session_edit(
|
||||
session_id: session_uuid,
|
||||
};
|
||||
|
||||
Ok(Html(Template::render("edit_session", &context)))
|
||||
Ok(RawHtml(Template::render("edit_session", &context)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/history")]
|
||||
pub fn history(_auth: Authorized, db: &State<sled::Db>) -> Result<Html<Template>, StatusJson> {
|
||||
pub fn history(_auth: Authorized, db: &State<sled::Db>) -> Result<RawHtml<Template>, StatusJson> {
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct HistoryEntryContext {
|
||||
category: category::V,
|
||||
@ -237,5 +237,5 @@ pub fn history(_auth: Authorized, db: &State<sled::Db>) -> Result<Html<Template>
|
||||
context.entries.sort_by_key(|entry| entry.session.started);
|
||||
context.entries.reverse();
|
||||
|
||||
Ok(Html(Template::render("history", &context)))
|
||||
Ok(RawHtml(Template::render("history", &context)))
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use rocket::{get, response::content::Html, State};
|
||||
use rocket::{get, response::content::RawHtml, State};
|
||||
use rocket_dyn_templates::Template;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -7,7 +7,7 @@ use crate::{
|
||||
};
|
||||
|
||||
#[get("/")]
|
||||
pub fn dailies(_auth: Authorized, db: &State<sled::Db>) -> Result<Html<Template>, StatusJson> {
|
||||
pub fn dailies(_auth: Authorized, db: &State<sled::Db>) -> Result<RawHtml<Template>, StatusJson> {
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct TemplateContext {
|
||||
dailies: Vec<Daily>,
|
||||
|
||||
@ -2,9 +2,9 @@ use crate::auth::Authorized;
|
||||
use crate::database::latest::trees::{category, session};
|
||||
use crate::status_json::StatusJson;
|
||||
use crate::util::OrdL;
|
||||
use chrono::{Date, DateTime, Datelike, Duration, Local, Timelike};
|
||||
use chrono::{DateTime, Datelike, Duration, Local, NaiveDate, Timelike};
|
||||
use itertools::Itertools;
|
||||
use rocket::{get, http::Status, response::content::Html, serde::uuid::Uuid, State};
|
||||
use rocket::{get, http::Status, response::content::RawHtml, serde::uuid::Uuid, State};
|
||||
use rocket_dyn_templates::Template;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
@ -141,7 +141,7 @@ pub fn single_stats(
|
||||
_auth: Authorized,
|
||||
category_id: Uuid,
|
||||
db: &State<sled::Db>,
|
||||
) -> Result<Html<Template>, StatusJson> {
|
||||
) -> Result<RawHtml<Template>, StatusJson> {
|
||||
let categories_tree = db.open_tree(category::NAME)?;
|
||||
let sessions_tree = db.open_tree(session::NAME)?;
|
||||
|
||||
@ -153,11 +153,11 @@ pub fn single_stats(
|
||||
|
||||
let now = Local::now();
|
||||
let ctx = category_stats_ctx(now, category_id, category, &sessions, &child_map);
|
||||
Ok(Html(Template::render("stats_single", dbg!(&ctx))))
|
||||
Ok(RawHtml(Template::render("stats_single", dbg!(&ctx))))
|
||||
}
|
||||
|
||||
#[get("/stats")]
|
||||
pub fn all_stats(_auth: Authorized, db: &State<sled::Db>) -> Result<Html<Template>, StatusJson> {
|
||||
pub fn all_stats(_auth: Authorized, db: &State<sled::Db>) -> Result<RawHtml<Template>, StatusJson> {
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct StatsContext {
|
||||
categories_stats: Vec<CategoryStatsCtx>,
|
||||
@ -185,15 +185,11 @@ pub fn all_stats(_auth: Authorized, db: &State<sled::Db>) -> Result<Html<Templat
|
||||
|
||||
let context = StatsContext { categories_stats };
|
||||
|
||||
Ok(Html(Template::render("stats_all", &context)))
|
||||
Ok(RawHtml(Template::render("stats_all", &context)))
|
||||
}
|
||||
|
||||
/// Compute the duration of `day` that is covered by the span `start..end`
|
||||
fn span_duration_of_day(
|
||||
start: DateTime<Local>,
|
||||
end: DateTime<Local>,
|
||||
day: Date<Local>,
|
||||
) -> Duration {
|
||||
/// Compute the subset of `day` that is covered by the span `start..end`
|
||||
fn span_duration_of_day(start: DateTime<Local>, end: DateTime<Local>, day: NaiveDate) -> Duration {
|
||||
if end < start {
|
||||
panic!("start must come before end");
|
||||
}
|
||||
@ -201,26 +197,29 @@ fn span_duration_of_day(
|
||||
// if the span is 0
|
||||
// or if the day is not in the span
|
||||
// the duration is zero
|
||||
if end == start || start.date() > day || end.date() < day {
|
||||
if end == start || start.date_naive() > day || end.date_naive() < day {
|
||||
return Duration::zero();
|
||||
}
|
||||
|
||||
if start.date() < day {
|
||||
if end.date() > day {
|
||||
// TODO: deal with unwrap
|
||||
let day_start = day.and_hms_opt(0, 0, 0).unwrap().and_local_timezone(Local).unwrap();
|
||||
|
||||
if start.date_naive() < day {
|
||||
if end.date_naive() > day {
|
||||
Duration::days(1)
|
||||
} else {
|
||||
debug_assert_eq!(end.date(), day);
|
||||
debug_assert_eq!(end.date_naive(), day);
|
||||
|
||||
end - day.and_hms(0, 0, 0)
|
||||
end - day_start
|
||||
}
|
||||
} else if end.date() > day {
|
||||
debug_assert_eq!(start.date(), day);
|
||||
} else if end.date_naive() > day {
|
||||
debug_assert_eq!(start.date_naive(), day);
|
||||
|
||||
day.and_hms(0, 0, 0) + Duration::days(1) - start
|
||||
day_start + Duration::days(1) - start
|
||||
} else {
|
||||
debug_assert!(start < end);
|
||||
debug_assert_eq!(start.date(), day);
|
||||
debug_assert_eq!(end.date(), day);
|
||||
debug_assert_eq!(start.date_naive(), day);
|
||||
debug_assert_eq!(end.date_naive(), day);
|
||||
|
||||
end - start
|
||||
}
|
||||
@ -307,14 +306,14 @@ where
|
||||
{
|
||||
const NUM_WEEKS: usize = 12;
|
||||
|
||||
let today = Local::today();
|
||||
let today = Local::now().date_naive();
|
||||
let last_day = today
|
||||
// take at least NUM_WEEKS * 7 days
|
||||
- Duration::weeks(NUM_WEEKS as i64)
|
||||
// round up to nearest monday
|
||||
- Duration::days(today.weekday().num_days_from_monday() as i64);
|
||||
|
||||
let mut days: BTreeMap<Date<Local>, Duration> = Default::default();
|
||||
let mut days: BTreeMap<NaiveDate, Duration> = Default::default();
|
||||
|
||||
// calculate the time spent logging this category for every day of the last NUM_WEEKS
|
||||
for session in sessions {
|
||||
@ -350,8 +349,8 @@ where
|
||||
|
||||
let month = day.month();
|
||||
|
||||
let month_border = |other_day: Date<_>| other_day.month() != month;
|
||||
let month_or_week_border = |other_day: Date<_>| {
|
||||
let month_border = |other_day: NaiveDate| other_day.month() != month;
|
||||
let month_or_week_border = |other_day: NaiveDate| {
|
||||
other_day.iso_week() != week || month_border(other_day)
|
||||
};
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ use crate::auth::Authorized;
|
||||
use crate::status_json::StatusJson;
|
||||
use chrono::{Duration, Local, NaiveDate};
|
||||
use itertools::Itertools;
|
||||
use rocket::{get, response::content::Html, State};
|
||||
use rocket::{get, response::content::RawHtml, State};
|
||||
use rocket_dyn_templates::Template;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Cow;
|
||||
@ -14,7 +14,7 @@ pub struct BirthDate(pub NaiveDate);
|
||||
pub fn weeks(
|
||||
_auth: Authorized,
|
||||
birth_date: &State<BirthDate>,
|
||||
) -> Result<Html<Template>, StatusJson> {
|
||||
) -> Result<RawHtml<Template>, StatusJson> {
|
||||
type Color<'a> = Cow<'a, str>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
@ -57,10 +57,10 @@ pub fn weeks(
|
||||
periods: Vec<PeriodCtx<'a>>,
|
||||
}
|
||||
|
||||
let now = Local::now().date();
|
||||
let now = Local::now().date_naive();
|
||||
let birth_date = birth_date.0;
|
||||
|
||||
let lived: Duration = now.naive_local() - birth_date;
|
||||
let lived: Duration = now - birth_date;
|
||||
let one_year = Duration::days(365);
|
||||
|
||||
let life_expectancy = (one_year * 81).num_weeks();
|
||||
@ -108,5 +108,5 @@ pub fn weeks(
|
||||
.collect(),
|
||||
};
|
||||
|
||||
Ok(Html(Template::render("weeks", &context)))
|
||||
Ok(RawHtml(Template::render("weeks", &context)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user