use i64 for timestamp
This commit is contained in:
parent
00f4dce4f9
commit
f22bea78ff
@ -1,8 +1,9 @@
|
|||||||
use rocket_sync_db_pools::database;
|
use rocket_sync_db_pools::database;
|
||||||
use rocket::serde::Serialize;
|
use serde::Serialize;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
|
||||||
use crate::schema::uploads;
|
use crate::schema::uploads;
|
||||||
|
use crate::lib;
|
||||||
|
|
||||||
|
|
||||||
#[database("punt")]
|
#[database("punt")]
|
||||||
@ -13,8 +14,10 @@ pub struct DbConn(diesel::SqliteConnection);
|
|||||||
#[table_name="uploads"]
|
#[table_name="uploads"]
|
||||||
pub struct FileInfo {
|
pub struct FileInfo {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
#[serde(default)]
|
||||||
pub name: Option<String>,
|
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 {
|
let file_info = FileInfo {
|
||||||
id: id.to_owned(),
|
id: id.to_owned(),
|
||||||
name: name.map(|n| n.to_owned()),
|
name: name.map(|n| n.to_owned()),
|
||||||
created_at: Some(1642371865),
|
created_at: Some(lib::timestamp()),
|
||||||
};
|
};
|
||||||
|
|
||||||
conn.run(|c| {
|
conn.run(|c| {
|
||||||
|
13
src/lib.rs
13
src/lib.rs
@ -1,6 +1,8 @@
|
|||||||
|
use std::io::ErrorKind;
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use rand::{Rng, distributions::Alphanumeric};
|
use rand::{Rng, distributions::Alphanumeric};
|
||||||
use tokio::fs::create_dir;
|
use tokio::fs::create_dir;
|
||||||
use std::io::ErrorKind;
|
|
||||||
use rocket::fs::TempFile;
|
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<()> {
|
pub async fn persist_file(file: &mut TempFile<'_>, filename: &str) -> std::io::Result<()> {
|
||||||
let dst = format!("uploads/{filename}");
|
let dst = format!("uploads/{filename}");
|
||||||
match file.persist_to(&dst).await {
|
match file.persist_to(&dst).await {
|
||||||
|
@ -2,6 +2,6 @@ table! {
|
|||||||
uploads (id) {
|
uploads (id) {
|
||||||
id -> Text,
|
id -> Text,
|
||||||
name -> Nullable<Text>,
|
name -> Nullable<Text>,
|
||||||
created_at -> Nullable<Integer>,
|
created_at -> Nullable<BigInt>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user