feat(lander): show filenames on index pages

ltm
Jef Roosens 2024-02-19 21:44:24 +01:00
parent e91631dd42
commit 24f7bba622
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 14 additions and 3 deletions

View File

@ -175,14 +175,19 @@ lnm_http_step_err lander_get_index(lnm_http_conn *conn) {
lsm_str_len(entry_key) - prefix_len); lsm_str_len(entry_key) - prefix_len);
break; break;
case lander_entry_type_file: case lander_entry_type_file:
ltm_instance_block_add_nested(&nested, c_ctx->instance, "file"); case lander_entry_type_paste:
ltm_instance_block_add_nested(&nested, c_ctx->instance,
t == lander_entry_type_file ? "file"
: "paste");
ltm_instance_block_add_var( ltm_instance_block_add_var(
nested, "full_key", ltm_instance_block_type_buf, nested, "full_key", ltm_instance_block_type_buf,
(void *)lsm_str_ptr(entry_key), lsm_str_len(entry_key)); (void *)lsm_str_ptr(entry_key), lsm_str_len(entry_key));
// Add the filename as the link name if known, or just the key otherwise
lsm_str *filename; lsm_str *filename;
if (lsm_entry_attr_get(&filename, handle, lander_attr_type_file_name)) { if (lsm_entry_attr_get(&filename, handle, lander_attr_type_file_name) ==
lsm_error_ok) {
ltm_instance_block_add_var( ltm_instance_block_add_var(
nested, "filename", ltm_instance_block_type_buf, nested, "filename", ltm_instance_block_type_buf,
(void *)lsm_str_ptr(filename), lsm_str_len(filename)); (void *)lsm_str_ptr(filename), lsm_str_len(filename));

View File

@ -24,7 +24,7 @@ const char *index_template =
"<!doctype html>\n" "<!doctype html>\n"
"<body>\n" "<body>\n"
"<h1>Index /{{ title_key }}</h1>\n" "<h1>Index /{{ title_key }}</h1>\n"
"<h2>Redirects</h2>" "<h2>Redirects</h2>\n"
"<ul>\n" "<ul>\n"
"{{ redirect start }}\n" "{{ redirect start }}\n"
"<li><a href=\"/{{ full_key }}\">{{ short_key }}</a></li>\n" "<li><a href=\"/{{ full_key }}\">{{ short_key }}</a></li>\n"
@ -36,6 +36,12 @@ const char *index_template =
"<li><a href=\"/{{ full_key }}\">{{ filename }}</a></li>\n" "<li><a href=\"/{{ full_key }}\">{{ filename }}</a></li>\n"
"{{ file end }}\n" "{{ file end }}\n"
"</ul>\n" "</ul>\n"
"<h2>Pastes</h2>\n"
"<ul>\n"
"{{ paste start }}\n"
"<li><a href=\"/{{ full_key }}\">{{ filename }}</a></li>\n"
"{{ paste end }}\n"
"</ul>\n"
"</body>\n"; "</body>\n";
lnm_http_loop *loop_init(lander_gctx *gctx, const char *api_key) { lnm_http_loop *loop_init(lander_gctx *gctx, const char *api_key) {