Always display content as text if user uploaded it as such

Fixes #8
master
neri 2 years ago
parent 3bed4de127
commit 313da6b583

@ -12,8 +12,8 @@ use sqlx::{
Row,
};
use crate::config::Config;
use crate::deleter;
use crate::{config::Config, file_kind::FileKind};
const VIEW_HTML: &str = include_str!("../template/view.html");
@ -23,10 +23,11 @@ pub async fn download(
config: web::Data<Config>,
) -> Result<HttpResponse, Error> {
let id = req.match_info().query("id");
let mut rows =
sqlx::query("SELECT file_id, file_name, delete_on_download from files WHERE file_id = $1")
.bind(id)
.fetch(db.as_ref());
let mut rows = sqlx::query(
"SELECT file_id, file_name, kind, delete_on_download from files WHERE file_id = $1",
)
.bind(id)
.fetch(db.as_ref());
let row: PgRow = rows
.try_next()
.await
@ -35,13 +36,15 @@ pub async fn download(
let file_id: String = row.get("file_id");
let file_name: String = row.get("file_name");
let file_kind: String = row.get("kind");
let delete_on_download: bool = row.get("delete_on_download");
let mut path = config.files_dir.clone();
path.push(&file_id);
let download = req.query_string().contains("dl");
let (content_type, mut content_disposition) = get_content_types(&path, &file_name);
let response = if content_type.type_() == mime::TEXT && !download {
let is_text = file_kind == FileKind::Text.to_string() || content_type.type_() == mime::TEXT;
let response = if is_text && !download {
let content = fs::read_to_string(path).await.map_err(|_| {
error::ErrorInternalServerError("this file should be here but could not be found")
})?;

Loading…
Cancel
Save