diff options
author | cel 🌸 <cel@blos.sm> | 2023-12-12 14:14:30 +0000 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-12-12 14:14:30 +0000 |
commit | 370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0 (patch) | |
tree | 665163bc58c8e94320b843b1983376d9a67f99bf /src/routes/static.rs | |
parent | 5dc4774ed3380762b4d7aadc86193af6073c456a (diff) | |
download | pinussy-370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0.tar.gz pinussy-370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0.tar.bz2 pinussy-370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0.zip |
initial refactor
Diffstat (limited to '')
-rw-r--r-- | src/routes/static.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/routes/static.rs b/src/routes/static.rs new file mode 100644 index 0000000..cabc6f8 --- /dev/null +++ b/src/routes/static.rs @@ -0,0 +1,22 @@ +use std::time::{Duration, SystemTime}; + +use actix_web::{http::header, web, HttpResponse}; + +use crate::templates::statics::StaticFile; + +static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60); + +pub async fn file(path: web::Path<String>) -> HttpResponse { + let name = &path.into_inner(); + if let Some(data) = StaticFile::get(name) { + let far_expires = SystemTime::now() + FAR; + HttpResponse::Ok() + .insert_header(header::Expires(far_expires.into())) + .insert_header(header::ContentType(data.mime.clone())) + .body(data.content) + } else { + HttpResponse::NotFound() + .reason("No such static file.") + .finish() + } +} |