feat(log): add 404 page

This commit is contained in:
imlonghao 2022-01-27 20:19:43 +08:00
parent e56207fff1
commit 8a14506771
Failed to extract signature
2 changed files with 6 additions and 3 deletions

View file

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Format datetime in locale format [github#1](https://github.com/imlonghao/archlinuxcn-packages/pull/1)
- Support Sentry error tracking
- 404 page for log not found
## [0.2.3] - 2022-01-23

View file

@ -239,9 +239,11 @@ async fn get_pkg_log(
.await
.unwrap();
let logdir: String = rows[0].get("logdir");
let contents =
std::fs::read_to_string(format!("/home/lilydjwg/.lilac/log/{}/{}.log", logdir, name))
.unwrap();
let filename = format!("/home/lilydjwg/.lilac/log/{}/{}.log", logdir, name);
let contents = match std::fs::read_to_string(&filename) {
Ok(x) => x,
Err(_) => return HttpResponse::NotFound().body(format!("Log {} not exist", &filename)),
};
let converted = ansi_to_html::convert(&contents, true, false).unwrap();
let html = format!("{}<code>{}</code>", STYLE_HTML, converted);
HttpResponse::Ok()