Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::{fs::File, io::Read};
use anyhow::Context;
use crate::{load::Loadable, resp::Response, util::slugify};
pub struct Misc {
pub url: String,
content_type: &'static str,
data: Vec<u8>,
}
impl Loadable for Misc {
fn load(path: &std::path::Path, slug_prefix: &str) -> anyhow::Result<Self> {
let file_name = path
.file_name()
.context("Could not get file name")?
.to_str()
.context("Could not convert filename into string")?
.to_owned();
let url = slugify(&format!("/{slug_prefix}/{file_name}"));
let mut data = vec![];
File::open(path)?.read_to_end(&mut data)?;
Ok(Self {
data,
content_type: "todo",
url,
})
}
}
impl Misc {
pub fn response(self) -> Response {
Response {
content_type: self.content_type,
data: self.data,
}
}
}