Restore healthz
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
asonix 2023-03-09 21:57:38 -06:00
parent 32aaa1c464
commit 039c413745

View file

@ -163,9 +163,9 @@ impl State {
} else if s.is_empty() {
self.scope.clone()
} else if self.scope.is_empty() {
format!("/{}", s)
format!("/{s}")
} else {
format!("{}/{}", self.scope, s)
format!("{}/{s}", self.scope)
}
}
@ -174,37 +174,31 @@ impl State {
}
fn edit_collection_path(&self, id: Uuid, token: &ValidToken) -> String {
self.scoped(&format!("{}?token={}", id, token.token))
self.scoped(&format!("{id}?token={}", token.token))
}
fn update_collection_path(&self, id: Uuid, token: &ValidToken) -> String {
self.scoped(&format!("{}?token={}", id, token.token))
self.scoped(&format!("{id}?token={}", token.token))
}
fn delete_collection_path(&self, id: Uuid, token: &ValidToken, confirmed: bool) -> String {
if confirmed {
self.scoped(&format!(
"{}/delete?token={}&confirmed=true",
id, token.token
))
self.scoped(&format!("{id}/delete?token={}&confirmed=true", token.token))
} else {
self.scoped(&format!("{}/delete?token={}", id, token.token))
self.scoped(&format!("{id}/delete?token={}", token.token))
}
}
fn public_collection_path(&self, id: Uuid) -> String {
self.scoped(&format!("{}", id))
self.scoped(&format!("{id}"))
}
fn create_entry_path(&self, collection_id: Uuid, token: &ValidToken) -> String {
self.scoped(&format!("{}/entry?token={}", collection_id, token.token))
self.scoped(&format!("{collection_id}/entry?token={}", token.token))
}
fn update_entry_path(&self, collection_id: Uuid, id: Uuid, token: &ValidToken) -> String {
self.scoped(&format!(
"{}/entry/{}?token={}",
collection_id, id, token.token
))
self.scoped(&format!("{collection_id}/entry/{id}?token={}", token.token))
}
fn move_entry_path(
@ -215,8 +209,8 @@ impl State {
direction: Direction,
) -> String {
self.scoped(&format!(
"{}/entry/{}/move/{}?token={}",
collection_id, id, direction, token.token
"{collection_id}/entry/{id}/move/{direction}?token={}",
token.token
))
}
@ -229,25 +223,24 @@ impl State {
) -> String {
if confirmed {
self.scoped(&format!(
"{}/entry/{}/delete?token={}&confirmed=true",
collection_id, id, token.token
"{collection_id}/entry/{id}/delete?token={}&confirmed=true",
token.token
))
} else {
self.scoped(&format!(
"{}/entry/{}/delete?token={}",
collection_id, id, token.token
"{collection_id}/entry/{id}/delete?token={}",
token.token
))
}
}
fn statics_path(&self, file: &str) -> String {
self.scoped(&format!("static/{}", file))
self.scoped(&format!("static/{file}"))
}
fn thumbnail_path(&self, filename: &str, size: u16, extension: pict::Extension) -> String {
self.scoped(&format!(
"image/thumbnail.{}?src={}&size={}",
extension, filename, size
"image/thumbnail.{extension}?src={filename}&size={size}",
))
}
@ -256,9 +249,8 @@ impl State {
for size in connection::VALID_SIZES {
sizes.push(format!(
"{} {}w",
"{} {size}w",
self.thumbnail_path(filename, *size, extension),
size,
))
}
@ -266,7 +258,7 @@ impl State {
}
fn image_path(&self, filename: &str) -> String {
self.scoped(&format!("image/full/{}", filename))
self.scoped(&format!("image/full/{filename}"))
}
}
@ -285,6 +277,7 @@ pub fn configure(cfg: &mut web::ServiceConfig, state: State, client: Client) {
client,
)))
.app_data(web::Data::new(state))
.route("/healthz", web::get().to(healthz))
.service(web::resource("/static/{filename}").route(web::get().to(static_files)))
.service(web::resource("/404").route(web::get().to(not_found)))
.service(
@ -355,6 +348,11 @@ where
}
}
async fn healthz(state: web::Data<State>) -> Result<HttpResponse, StateError> {
state.store.check_health().await.stateful(&state)?;
Ok(HttpResponse::Ok().finish())
}
#[tracing::instrument(name = "Static files")]
async fn static_files(filename: web::Path<String>, state: web::Data<State>) -> HttpResponse {
let filename = filename.into_inner();
@ -680,7 +678,7 @@ async fn upload(
}
}
Err(e) => {
tracing::warn!("{}", e);
tracing::warn!("{e}");
let _ = store::DeleteEntry {
entry_path: &entry_path2,
}
@ -777,7 +775,13 @@ async fn view_collection(
rendered(
|cursor| {
self::templates::view_collection_html(cursor, path.collection, &collection, &entries, &state)
self::templates::view_collection_html(
cursor,
path.collection,
&collection,
&entries,
&state,
)
},
HttpResponse::Ok(),
)
@ -976,7 +980,7 @@ fn to_svg_string(qr: &qrcodegen::QrCode, border: i32) -> String {
.checked_add(border.checked_mul(2).unwrap())
.unwrap();
result += &format!(
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 {0} {0}\" stroke=\"none\">\n", dimension);
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 {dimension} {dimension}\" stroke=\"none\">\n");
result += "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
result += "\t<path d=\"";
for y in 0..qr.size() {