use i64 for timestamp

This commit is contained in:
Joseph Montanaro 2022-01-18 22:10:06 -08:00
parent 00f4dce4f9
commit f22bea78ff
3 changed files with 19 additions and 5 deletions

View File

@ -1,8 +1,9 @@
use rocket_sync_db_pools::database;
use rocket::serde::Serialize;
use serde::Serialize;
use diesel::prelude::*;
use crate::schema::uploads;
use crate::lib;
#[database("punt")]
@ -13,8 +14,10 @@ pub struct DbConn(diesel::SqliteConnection);
#[table_name="uploads"]
pub struct FileInfo {
pub id: String,
#[serde(default)]
pub name: Option<String>,
pub created_at: Option<i32> // figure out how to marshal this to a proper time type later
#[serde(default)]
pub created_at: Option<i64> // figure out how to marshal this to a proper time type later
}
@ -27,7 +30,7 @@ pub async fn put_file_info(id: &str, name: Option<&str>, conn: DbConn) -> QueryR
let file_info = FileInfo {
id: id.to_owned(),
name: name.map(|n| n.to_owned()),
created_at: Some(1642371865),
created_at: Some(lib::timestamp()),
};
conn.run(|c| {

View File

@ -1,6 +1,8 @@
use std::io::ErrorKind;
use std::time::SystemTime;
use rand::{Rng, distributions::Alphanumeric};
use tokio::fs::create_dir;
use std::io::ErrorKind;
use rocket::fs::TempFile;
@ -13,6 +15,15 @@ pub fn gen_id() -> String {
}
pub fn timestamp() -> i64 {
let now = SystemTime::now();
match now.duration_since(SystemTime::UNIX_EPOCH) {
Ok(dur) => dur.as_secs() as i64,
Err(e) => -(e.duration().as_secs() as i64),
}
}
pub async fn persist_file(file: &mut TempFile<'_>, filename: &str) -> std::io::Result<()> {
let dst = format!("uploads/{filename}");
match file.persist_to(&dst).await {

View File

@ -2,6 +2,6 @@ table! {
uploads (id) {
id -> Text,
name -> Nullable<Text>,
created_at -> Nullable<Integer>,
created_at -> Nullable<BigInt>,
}
}