mirror of
https://github.com/YGGverse/nexy.git
synced 2026-03-31 17:25:27 +00:00
implement argument option to append trailing slash to files match pattern(s), update crate version
This commit is contained in:
parent
ff323e58c7
commit
dc44d38761
5 changed files with 106 additions and 80 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nexy"
|
name = "nexy"
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
@ -13,4 +13,5 @@ repository = "https://github.com/YGGverse/nexy"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
chrono = "^0.4.20"
|
chrono = "^0.4.20"
|
||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
|
regex = "1.11"
|
||||||
urlencoding = "2.1"
|
urlencoding = "2.1"
|
||||||
69
README.md
69
README.md
|
|
@ -36,125 +36,128 @@ nexy -p /path/to/public_dir
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
-a, --access-log <ACCESS_LOG>
|
-a, --access-log <ACCESS_LOG>
|
||||||
Absolute path to the access log file
|
Absolute path to the access log file
|
||||||
|
|
||||||
-b, --bind <BIND>
|
-b, --bind <BIND>
|
||||||
Bind server(s) `host:port` to listen incoming connections
|
Bind server(s) `host:port` to listen incoming connections
|
||||||
|
|
||||||
* use `[host]:port` notation for IPv6
|
* use `[host]:port` notation for IPv6
|
||||||
|
|
||||||
[default: 127.0.0.1:1900 [::1]:1900]
|
[default: 127.0.0.1:1900 [::1]:1900]
|
||||||
|
|
||||||
-d, --debug
|
-d, --debug
|
||||||
Print debug information
|
Print debug information
|
||||||
|
|
||||||
-p, --public <PUBLIC>
|
-p, --public <PUBLIC>
|
||||||
Absolute path to the public files directory
|
Absolute path to the public files directory
|
||||||
|
|
||||||
--show-hidden
|
--show-hidden
|
||||||
Show hidden entries (in the directory listing)
|
Show hidden entries (in the directory listing)
|
||||||
|
|
||||||
* Important: this option does not prevent access to hidden files!
|
* Important: this option does not prevent access to hidden files!
|
||||||
|
|
||||||
--template-access-denied <TEMPLATE_ACCESS_DENIED>
|
--template-access-denied <TEMPLATE_ACCESS_DENIED>
|
||||||
Absolute path to the `Access denied` template file
|
Absolute path to the `Access denied` template file
|
||||||
|
|
||||||
* this template file can be in binary format (e.g. image)
|
* this template file can be in binary format (e.g. image)
|
||||||
|
|
||||||
--template-internal-server-error <TEMPLATE_INTERNAL_SERVER_ERROR>
|
--template-internal-server-error <TEMPLATE_INTERNAL_SERVER_ERROR>
|
||||||
Absolute path to the `Internal server error` template file
|
Absolute path to the `Internal server error` template file
|
||||||
|
|
||||||
* this template file can be in binary format (e.g. image)
|
* this template file can be in binary format (e.g. image)
|
||||||
|
|
||||||
--template-not-found <TEMPLATE_NOT_FOUND>
|
--template-not-found <TEMPLATE_NOT_FOUND>
|
||||||
Absolute path to the `Not found` template file
|
Absolute path to the `Not found` template file
|
||||||
|
|
||||||
* this template file can be in binary format (e.g. image)
|
* this template file can be in binary format (e.g. image)
|
||||||
|
|
||||||
--template-welcome <TEMPLATE_WELCOME>
|
--template-welcome <TEMPLATE_WELCOME>
|
||||||
Absolute path to the `Welcome` template file. Unlike `template-index`, this applies only to the `public` location
|
Absolute path to the `Welcome` template file. Unlike `template-index`, this applies only to the `public` location
|
||||||
|
|
||||||
* this template file expects pattern and cannot be in binary format
|
* this template file expects pattern and cannot be in binary format
|
||||||
|
|
||||||
**Patterns** * `{list}` - entries list for the `public` directory * `{hosts}` - unique visitors count * `{hits}` - requests count
|
**Patterns** * `{list}` - entries list for the `public` directory * `{hosts}` - unique visitors count * `{hits}` - requests count
|
||||||
|
|
||||||
--template-index <TEMPLATE_INDEX>
|
--template-index <TEMPLATE_INDEX>
|
||||||
Absolute path to the `Index` template file for each directory
|
Absolute path to the `Index` template file for each directory
|
||||||
|
|
||||||
* this template file expects pattern and cannot be in binary format
|
* this template file expects pattern and cannot be in binary format
|
||||||
|
|
||||||
**Patterns** * `{list}` - entries list for the current directory * `{hosts}` - unique visitors count * `{hits}` - requests count
|
**Patterns** * `{list}` - entries list for the current directory * `{hosts}` - unique visitors count * `{hits}` - requests count
|
||||||
|
|
||||||
--list-dir-show-count
|
--list-dir-show-count
|
||||||
Show files count in dir (as the alternative text for navigation links)
|
Show files count in dir (as the alternative text for navigation links)
|
||||||
|
|
||||||
--list-dir-show-accessed
|
--list-dir-show-accessed
|
||||||
Show directory accessed time
|
Show directory accessed time
|
||||||
|
|
||||||
--list-dir-show-created
|
--list-dir-show-created
|
||||||
Show directory created time
|
Show directory created time
|
||||||
|
|
||||||
--list-dir-show-modified
|
--list-dir-show-modified
|
||||||
Show directory modified time
|
Show directory modified time
|
||||||
|
|
||||||
--list-dir-sort-by-accessed
|
--list-dir-sort-by-accessed
|
||||||
Sort dirs by time accessed (name by default)
|
Sort dirs by time accessed (name by default)
|
||||||
|
|
||||||
--list-dir-sort-by-created
|
--list-dir-sort-by-created
|
||||||
Sort dirs by time created (name by default)
|
Sort dirs by time created (name by default)
|
||||||
|
|
||||||
--list-dir-sort-by-modified
|
--list-dir-sort-by-modified
|
||||||
Sort dirs by time modified (name by default)
|
Sort dirs by time modified (name by default)
|
||||||
|
|
||||||
--list-dir-sort-by-count
|
--list-dir-sort-by-count
|
||||||
Sort dirs by count (name by default)
|
Sort dirs by count (name by default)
|
||||||
|
|
||||||
--list-dir-reverse
|
--list-dir-reverse
|
||||||
Sort directories in list DESC (ASC by default)
|
Sort directories in list DESC (ASC by default)
|
||||||
|
|
||||||
--list-file-show-size
|
--list-file-show-size
|
||||||
Show file size in list (as the alternative text for navigation links)
|
Show file size in list (as the alternative text for navigation links)
|
||||||
|
|
||||||
--list-file-show-accessed
|
--list-file-show-accessed
|
||||||
Show file accessed time
|
Show file accessed time
|
||||||
|
|
||||||
--list-file-show-created
|
--list-file-show-created
|
||||||
Show file created time
|
Show file created time
|
||||||
|
|
||||||
--list-file-show-modified
|
--list-file-show-modified
|
||||||
Show file modified time
|
Show file modified time
|
||||||
|
|
||||||
--list-file-sort-by-accessed
|
--list-file-sort-by-accessed
|
||||||
Sort files by time accessed (name by default)
|
Sort files by time accessed (name by default)
|
||||||
|
|
||||||
--list-file-sort-by-created
|
--list-file-sort-by-created
|
||||||
Sort files by time created (name by default)
|
Sort files by time created (name by default)
|
||||||
|
|
||||||
--list-file-sort-by-modified
|
--list-file-sort-by-modified
|
||||||
Sort files by time modified (name by default)
|
Sort files by time modified (name by default)
|
||||||
|
|
||||||
--list-file-sort-by-size
|
--list-file-sort-by-size
|
||||||
Sort files by size (name by default)
|
Sort files by size (name by default)
|
||||||
|
|
||||||
--list-file-reverse
|
--list-file-reverse
|
||||||
Sort files in list DESC (ASC by default)
|
Sort files in list DESC (ASC by default)
|
||||||
|
|
||||||
--list-time-format <LIST_TIME_FORMAT>
|
--list-file-slash <LIST_FILE_SLASH>
|
||||||
|
Append trailing slash to files match regex pattern(s)
|
||||||
|
|
||||||
|
--list-time-format <LIST_TIME_FORMAT>
|
||||||
Time format for listing items
|
Time format for listing items
|
||||||
|
|
||||||
* use escape notation for `%` e.g. `"%%Y-%%m-%%d %%H:%%M:%%S"`
|
* use escape notation for `%` e.g. `"%%Y-%%m-%%d %%H:%%M:%%S"`
|
||||||
|
|
||||||
[default: "%Y/%m/%d"]
|
[default: %Y/%m/%d]
|
||||||
|
|
||||||
-r, --read-chunk <READ_CHUNK>
|
-r, --read-chunk <READ_CHUNK>
|
||||||
Optimize memory usage on reading large files or stream
|
Optimize memory usage on reading large files or stream
|
||||||
|
|
||||||
[default: 1024]
|
[default: 1024]
|
||||||
|
|
||||||
-h, --help
|
-h, --help
|
||||||
Print help (see a summary with '-h')
|
Print help (see a summary with '-h')
|
||||||
|
|
||||||
-V, --version
|
-V, --version
|
||||||
Print version
|
Print version
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,10 @@ pub struct Config {
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub list_file_reverse: bool,
|
pub list_file_reverse: bool,
|
||||||
|
|
||||||
|
/// Append trailing slash to files match regex pattern(s)
|
||||||
|
#[arg(long)]
|
||||||
|
pub list_file_slash: Vec<String>,
|
||||||
|
|
||||||
/// Time format for listing items
|
/// Time format for listing items
|
||||||
///
|
///
|
||||||
/// * use escape notation for `%` e.g. `"%%Y-%%m-%%d %%H:%%M:%%S"`
|
/// * use escape notation for `%` e.g. `"%%Y-%%m-%%d %%H:%%M:%%S"`
|
||||||
|
|
|
||||||
|
|
@ -240,9 +240,17 @@ impl Public {
|
||||||
if fc.alt.is_size {
|
if fc.alt.is_size {
|
||||||
a.push(b(file.meta.size()))
|
a.push(b(file.meta.size()))
|
||||||
}
|
}
|
||||||
|
if !l.ends_with('/') {
|
||||||
|
for p in &fc.append_slash {
|
||||||
|
if p.is_match(&l) {
|
||||||
|
l.push('/');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if !a.is_empty() {
|
if !a.is_empty() {
|
||||||
l.push(' ');
|
l.push(' ');
|
||||||
l.push_str(&a.join(", "));
|
l.push_str(&a.join(", "))
|
||||||
}
|
}
|
||||||
l
|
l
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
//! valid listing configuration from the plain `clap` arguments list.
|
//! valid listing configuration from the plain `clap` arguments list.
|
||||||
//! This feature is evolving, and it may require refactoring in the future.
|
//! This feature is evolving, and it may require refactoring in the future.
|
||||||
|
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
pub struct Time {
|
pub struct Time {
|
||||||
pub is_accessed: bool,
|
pub is_accessed: bool,
|
||||||
pub is_created: bool,
|
pub is_created: bool,
|
||||||
|
|
@ -35,6 +37,7 @@ pub struct Dir {
|
||||||
}
|
}
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub alt: FileAlt,
|
pub alt: FileAlt,
|
||||||
|
pub append_slash: Vec<Regex>,
|
||||||
pub is_reverse: bool,
|
pub is_reverse: bool,
|
||||||
pub sort: FileSort,
|
pub sort: FileSort,
|
||||||
}
|
}
|
||||||
|
|
@ -103,6 +106,13 @@ impl ListConfig {
|
||||||
is_size: config.list_file_show_size,
|
is_size: config.list_file_show_size,
|
||||||
},
|
},
|
||||||
is_reverse: config.list_file_reverse,
|
is_reverse: config.list_file_reverse,
|
||||||
|
append_slash: {
|
||||||
|
let mut p = Vec::with_capacity(config.list_file_slash.len());
|
||||||
|
for pattern in &config.list_file_slash {
|
||||||
|
p.push(Regex::new(pattern)?)
|
||||||
|
}
|
||||||
|
p
|
||||||
|
},
|
||||||
sort: FileSort {
|
sort: FileSort {
|
||||||
time: Time {
|
time: Time {
|
||||||
is_accessed: config.list_file_sort_by_accessed,
|
is_accessed: config.list_file_sort_by_accessed,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue