add base path

This commit is contained in:
Florian Stecker 2024-03-06 23:12:35 -05:00
parent e87a7fba2c
commit 8e497ed487

View File

@ -13,6 +13,8 @@ pub struct TableResult<'a> {
pub last_key: Key, pub last_key: Key,
} }
const HTTP_PATH: &str = "/btrfs";
pub fn render_table(table: TableResult) -> Markup { pub fn render_table(table: TableResult) -> Markup {
let header: String = if let Some(desc) = table.tree_desc { let header: String = if let Some(desc) = table.tree_desc {
@ -23,19 +25,19 @@ pub fn render_table(table: TableResult) -> Markup {
let key_input_value = table.key_id.map_or(String::new(), |x| format!("{:X}", x)); let key_input_value = table.key_id.map_or(String::new(), |x| format!("{:X}", x));
let first_key_url = format!("/tree/{}", let first_key_url = format!("{HTTP_PATH}/tree/{}",
table.tree_id); table.tree_id);
let prev_key_url = format!("/tree/{}/to/{:016X}-{:02X}-{:016X}", let prev_key_url = format!("{HTTP_PATH}/tree/{}/to/{:016X}-{:02X}-{:016X}",
table.tree_id, table.tree_id,
table.first_key.key_id, table.first_key.key_id,
u8::from(table.first_key.key_type), u8::from(table.first_key.key_type),
table.first_key.key_offset); table.first_key.key_offset);
let next_key_url = format!("/tree/{}/from/{:016X}-{:02X}-{:016X}", let next_key_url = format!("{HTTP_PATH}/tree/{}/from/{:016X}-{:02X}-{:016X}",
table.tree_id, table.tree_id,
table.last_key.key_id, table.last_key.key_id,
u8::from(table.last_key.key_type), u8::from(table.last_key.key_type),
table.first_key.key_offset); table.first_key.key_offset);
let last_key_url = format!("/tree/{}/to/{:016X}-{:02X}-{:016X}", let last_key_url = format!("{HTTP_PATH}/tree/{}/to/{:016X}-{:02X}-{:016X}",
table.tree_id, table.tree_id,
u64::wrapping_sub(0,1), u64::wrapping_sub(0,1),
u8::wrapping_sub(0,1), u8::wrapping_sub(0,1),
@ -108,12 +110,12 @@ pub fn render_table(table: TableResult) -> Markup {
} }
@if table.tree_id != 1 { @if table.tree_id != 1 {
a href="/tree/1" { a href={(HTTP_PATH) "/tree/1"} {
"go back to root tree" "go back to root tree"
} }
} }
form method="get" action={"/tree/" (table.tree_id)} { form method="get" action={(HTTP_PATH) "/tree/" (table.tree_id)} {
input type="text" name="key" value=(key_input_value); input type="text" name="key" value=(key_input_value);
input type="submit" value="Search"; input type="submit" value="Search";
} }
@ -147,7 +149,7 @@ fn row_id_desc(key: Key, tree_id: u64) -> (Markup, Markup, Markup) {
let x = format!("{:X}", key.key_id); let x = format!("{:X}", key.key_id);
let y = format!("{:?} ({:02X})", key.key_type, u8::from(key.key_type)); let y = format!("{:?} ({:02X})", key.key_type, u8::from(key.key_type));
let z = if key.key_type == ItemType::RootRef || key.key_type == ItemType::Ref { let z = if key.key_type == ItemType::RootRef || key.key_type == ItemType::Ref {
format!("<a href=\"/tree/{}/{:X}\">{:X}</a>", tree_id, key.key_offset, key.key_offset) format!("<a href=\"{HTTP_PATH}/tree/{}/{:X}\">{:X}</a>", tree_id, key.key_offset, key.key_offset)
} else { } else {
format!("{:X}", key.key_offset) format!("{:X}", key.key_offset)
}; };
@ -157,7 +159,7 @@ fn row_id_desc(key: Key, tree_id: u64) -> (Markup, Markup, Markup) {
fn item_value_string(tree_id: u64, item: &Item) -> Markup { fn item_value_string(tree_id: u64, item: &Item) -> Markup {
match &item.value { match &item.value {
Value::Root(_) => { Value::Root(_) => {
html! { a href={"/tree/" (item.key.key_id)} { "go to tree " (item.key.key_id) } } html! { a href={(HTTP_PATH) "/tree/" (item.key.key_id)} { "go to tree " (item.key.key_id) } }
}, },
Value::Dir(dir_item) | Value::DirIndex(dir_item) => { Value::Dir(dir_item) | Value::DirIndex(dir_item) => {
let name = format!("{:?}", &dir_item.name); let name = format!("{:?}", &dir_item.name);
@ -166,12 +168,12 @@ fn item_value_string(tree_id: u64, item: &Item) -> Markup {
(name) (name)
" @ " " @ "
@if dir_item.location.key_type == ItemType::Root { @if dir_item.location.key_type == ItemType::Root {
a href=(format!("/tree/{id}")) { a href=(format!("{HTTP_PATH}/tree/{id}")) {
"subvolume " "subvolume "
(Hex(id)) (Hex(id))
} }
} @else { } @else {
a href=(format!("/tree/{tree_id}/{id:x}")) { a href=(format!("{HTTP_PATH}/tree/{tree_id}/{id:x}")) {
(Hex(id)) (Hex(id))
} }
} }