File upload and persistence extension
- index.html extended with form input - pasta.html and pastalist.html show link to /file/{pasta.id}/{filename} path - files are saved in pasta_data folder - all data is now stored in pasta_data/database.json - changed pastalist.html date format to exclude year - added custom 404 error handler
This commit is contained in:
parent
c98aad7256
commit
36fa6598a8
9 changed files with 371 additions and 223 deletions
83
src/pasta.rs
83
src/pasta.rs
|
@ -1,58 +1,51 @@
|
|||
use std::fmt;
|
||||
use actix_web::cookie::time::macros::format_description;
|
||||
use chrono::{Datelike, DateTime, NaiveDateTime, Timelike, Utc};
|
||||
use serde::Deserialize;
|
||||
|
||||
use chrono::{DateTime, Datelike, NaiveDateTime, Timelike, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::to_animal_names;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Pasta {
|
||||
pub id: u64,
|
||||
pub content: String,
|
||||
pub created: i64,
|
||||
pub expiration: i64,
|
||||
pub pasta_type: String
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PastaFormData {
|
||||
pub content: String,
|
||||
pub expiration: String
|
||||
pub id: u64,
|
||||
pub content: String,
|
||||
pub file: String,
|
||||
pub created: i64,
|
||||
pub expiration: i64,
|
||||
pub pasta_type: String,
|
||||
}
|
||||
|
||||
impl Pasta {
|
||||
pub fn id_as_animals(&self) -> String {
|
||||
to_animal_names(self.id)
|
||||
}
|
||||
|
||||
pub fn idAsAnimals(&self) -> String {
|
||||
to_animal_names(self.id)
|
||||
}
|
||||
|
||||
pub fn createdAsString(&self) -> String {
|
||||
let date = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(self.created, 0), Utc);
|
||||
format!(
|
||||
"{}-{:02}-{:02} {}:{}",
|
||||
date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn expirationAsString(&self) -> String {
|
||||
let date = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(self.expiration, 0), Utc);
|
||||
format!(
|
||||
"{}-{:02}-{:02} {}:{}",
|
||||
date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
)
|
||||
}
|
||||
pub fn created_as_string(&self) -> String {
|
||||
let date = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(self.created, 0), Utc);
|
||||
format!(
|
||||
"{:02}-{:02} {}:{}",
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn expiration_as_string(&self) -> String {
|
||||
let date =
|
||||
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(self.expiration, 0), Utc);
|
||||
format!(
|
||||
"{:02}-{:02} {}:{}",
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl fmt::Display for Pasta {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.content)
|
||||
}
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.content)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue