Skip to content

Commit

Permalink
Merge pull request #27 from KekOnTheWorld/main
Browse files Browse the repository at this point in the history
Added 404
  • Loading branch information
lbirkert authored May 9, 2022
2 parents 280e8ea + 3f07ade commit d6861c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/routes/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::{
util::files,
};

#[get("/{id}")]
// Should change if you have different id lengths
#[get("/{id:[a-zA-Z0-9-_]{7}}")]
pub async fn embed(
path: web::Path<(String,)>,
state: web::Data<Arc<UploadState>>,
Expand Down
7 changes: 6 additions & 1 deletion src/routes/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ pub async fn handle_all(
state: web::Data<Arc<UploadState>>,
) -> Result<impl Responder> {
let path = format!("{}{}", state.web_dir, path.into_inner().0);
NamedFile::open(path).map_err(|e| error::ErrorNotFound(format!("File not found {}", e)))
match NamedFile::open(path) {
Ok(file) => Ok(file),
Err(_) => NamedFile::open(format!("{}404.html", state.web_dir)).map_err(|e| error::ErrorNotFound(format!(
"File not found and 404.html doesn't exist: {}", e
))),
}
}

0 comments on commit d6861c9

Please sign in to comment.