Basic functionality done

This commit is contained in:
Raphaël Thériault 2020-10-01 13:28:11 -04:00
parent 95a2495b5b
commit fe3ac87a0f
No known key found for this signature in database
GPG Key ID: D4E92B68275D389F
4 changed files with 30 additions and 8 deletions

View File

@ -41,7 +41,7 @@ impl Config {
"info".to_owned()
}
#[inline]
fn log_level_is_default(level: &String) -> bool {
fn log_level_is_default(level: &str) -> bool {
level.to_lowercase() == Self::default_log_level()
}
}

View File

@ -18,10 +18,10 @@ pub fn connect(config: &DatabaseConfig) -> Result<&'static Db> {
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Filite {
owner: String,
creation: DateTime<Utc>,
inner: FiliteInner,
views: usize,
pub owner: String,
pub creation: DateTime<Utc>,
pub inner: FiliteInner,
pub views: usize,
}
#[derive(Debug, Clone, Deserialize, Serialize)]

View File

@ -11,7 +11,6 @@ mod tests;
use anyhow::Error;
use config::Config;
use sled::Db;
use structopt::StructOpt;
use tracing_subscriber::fmt::format::FmtSpan;
use warp::{Filter, Reply};

View File

@ -1,6 +1,11 @@
use crate::{config::Config, db::User, reject::TryExt};
use crate::{
config::Config,
db::{Filite, FiliteInner, User},
reject::TryExt,
};
use bytes::Bytes;
use sled::Db;
use warp::reply::Response;
use warp::{http::Uri, Filter, Rejection, Reply};
pub fn handler(
@ -58,7 +63,25 @@ pub fn handler(
.or(put_text)
}
async fn filite(id: String, db: &Db) -> Result<impl Reply, Rejection> {}
async fn filite(id: String, db: &Db) -> Result<impl Reply, Rejection> {
impl Reply for Filite {
fn into_response(self) -> Response {
match self.inner {
FiliteInner::File { data, mime } => {
warp::reply::with_header(data, "Content-Type", mime).into_response()
}
FiliteInner::Link { location } => {
warp::redirect::temporary(Uri::from_maybe_shared(location).unwrap_or_default())
.into_response()
}
FiliteInner::Text { data } => data.into_response(),
}
}
}
let filite = crate::db::filite(&id, true, db).or_500()?.or_404()?;
Ok(filite)
}
async fn post_file(
user: User,