mirror of
https://github.com/Tim-Paik/srv.git
synced 2024-10-13 00:29:43 +00:00
Compare commits
14 Commits
v1.0.0
...
d4714cd8f5
Author | SHA1 | Date | |
---|---|---|---|
d4714cd8f5
|
|||
91f9993315
|
|||
fc809f9bc9
|
|||
479f6006a6
|
|||
c15c09f07c
|
|||
17c6053ed2
|
|||
4ccea5edf2
|
|||
8251624981
|
|||
46b7c6379f
|
|||
39bcd56608
|
|||
f82e85aa66
|
|||
c98ef43525
|
|||
f1921d184d
|
|||
d1d849d93b
|
1269
Cargo.lock
generated
1269
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
16
Cargo.toml
@ -3,26 +3,28 @@ authors = ["Tim_Paik <timpaikc@outlook.com>"]
|
|||||||
description = "simple http server written in rust"
|
description = "simple http server written in rust"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
name = "srv"
|
name = "srv"
|
||||||
version = "1.0.0"
|
version = "1.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-files = "0.6"
|
actix-files = "0.6"
|
||||||
actix-web = {version = "4.0", features = ["rustls"]}
|
actix-web = { version = "4.1", features = ["rustls"] }
|
||||||
actix-web-httpauth = "0.6"
|
actix-web-httpauth = "0.8"
|
||||||
chrono = "0.4"
|
askama = "0.11"
|
||||||
clap = {version = "3.1", features = ["wrap_help", "color", "cargo"]}
|
askama_actix = "0.13"
|
||||||
|
clap = { version = "4.0", features = ["derive", "wrap_help", "color", "cargo"] }
|
||||||
|
comrak = { version = "0.14.0", default-features = false }
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
lazy_static = "1.4"
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
mime_guess = "2.0"
|
mime_guess = "2.0"
|
||||||
rustls = "0.20"
|
rustls = "0.20"
|
||||||
rustls-pemfile = "1.0"
|
rustls-pemfile = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
tera = "1.15"
|
time = { version = "0.3", features = ["formatting", "parsing"] }
|
||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
urlencoding = "2.1"
|
urlencoding = "2.1"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
opt-level = "z"
|
opt-level = "z"
|
||||||
|
strip = true
|
||||||
|
14
README.md
14
README.md
@ -7,9 +7,8 @@ This is a simple HTTP Server for use in a development environment, inspired by [
|
|||||||
|
|
||||||
### Built With
|
### Built With
|
||||||
|
|
||||||
- ~~[rocket](https://github.com/SergioBenitez/Rocket)~~ Framework used in previous versions
|
|
||||||
- [clap](https://github.com/clap-rs/clap) Provide command line parameter analysis
|
- [clap](https://github.com/clap-rs/clap) Provide command line parameter analysis
|
||||||
- [tera](https://github.com/Keats/tera) Provide template support
|
- [askama](https://github.com/djc/askama) Provide template support
|
||||||
- [actix-web](https://github.com/actix/actix-web) Main frame
|
- [actix-web](https://github.com/actix/actix-web) Main frame
|
||||||
- [actix-files](https://github.com/actix/actix-web/tree/master/actix-files) Provide static resources
|
- [actix-files](https://github.com/actix/actix-web/tree/master/actix-files) Provide static resources
|
||||||
- [actix-web-httpauth](https://github.com/actix/actix-extras/tree/master/actix-web-httpauth) Provide authentication
|
- [actix-web-httpauth](https://github.com/actix/actix-extras/tree/master/actix-web-httpauth) Provide authentication
|
||||||
@ -51,10 +50,10 @@ yay -S srv-bin
|
|||||||
Download the pre-compiled `srv-x86_64-unknown-linux-musl.tar.gz` on the [releases](https://github.com/Tim-Paik/srv/releases/latest), and copy the srv file in the compressed package to `/usr/bin` as a ROOT user with 755 permissions.
|
Download the pre-compiled `srv-x86_64-unknown-linux-musl.tar.gz` on the [releases](https://github.com/Tim-Paik/srv/releases/latest), and copy the srv file in the compressed package to `/usr/bin` as a ROOT user with 755 permissions.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
wget https://github.com/Tim-Paik/srv/releases/download/v1.0.0-rc.6/srv-x86_64-unknown-linux-musl.tar.gz
|
wget https://github.com/Tim-Paik/srv/releases/download/v1.0.1/srv-v1.0.1-x86_64-unknown-linux-musl.tar.gz
|
||||||
tar -xzvf srv-x86_64-unknown-linux-musl.tar.gz
|
tar -xzvf srv-v1.0.1-x86_64-unknown-linux-musl.tar.gz
|
||||||
install -Dm0755 -t /usr/bin/ srv
|
install -Dm0755 -t /usr/bin/ srv
|
||||||
rm srv srv-x86_64-unknown-linux-musl.tar.gz
|
rm srv srv-v1.0.1-x86_64-unknown-linux-musl.tar.gz
|
||||||
```
|
```
|
||||||
for reference only
|
for reference only
|
||||||
|
|
||||||
@ -78,7 +77,6 @@ You Need:
|
|||||||
git clone git@github.com:Tim-Paik/srv.git
|
git clone git@github.com:Tim-Paik/srv.git
|
||||||
cd srv
|
cd srv
|
||||||
cargo build --release
|
cargo build --release
|
||||||
strip target/release/srv
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you can find the compiled executable file named `srv` in the `target/release/` folder.
|
Then you can find the compiled executable file named `srv` in the `target/release/` folder.
|
||||||
@ -89,6 +87,10 @@ Execute `srv --help` to get all the usage methods
|
|||||||
|
|
||||||
Waiting to be added...
|
Waiting to be added...
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
All contributions are welcome and I will reply as soon as I see it :)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
120
src/filetype.rs
Normal file
120
src/filetype.rs
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
#[inline]
|
||||||
|
pub fn get_file_type(from: &std::path::Path) -> String {
|
||||||
|
match from.extension() {
|
||||||
|
Some(os_str) => match os_str.to_str().unwrap_or("") {
|
||||||
|
"7z" => "archive",
|
||||||
|
"bz" => "archive",
|
||||||
|
"bz2" => "archive",
|
||||||
|
"cab" => "archive",
|
||||||
|
"gz" => "archive",
|
||||||
|
"iso" => "archive",
|
||||||
|
"rar" => "archive",
|
||||||
|
"xz" => "archive",
|
||||||
|
"zip" => "archive",
|
||||||
|
"zst" => "archive",
|
||||||
|
"zstd" => "archive",
|
||||||
|
"doc" => "word",
|
||||||
|
"docx" => "word",
|
||||||
|
"ppt" => "powerpoint",
|
||||||
|
"pptx" => "powerpoint",
|
||||||
|
"xls" => "excel",
|
||||||
|
"xlsx" => "excel",
|
||||||
|
"heic" => "image",
|
||||||
|
"pdf" => "pdf",
|
||||||
|
// JavaScript / TypeScript
|
||||||
|
"js" => "code",
|
||||||
|
"cjs" => "code",
|
||||||
|
"mjs" => "code",
|
||||||
|
"jsx" => "code",
|
||||||
|
"ts" => "code",
|
||||||
|
"tsx" => "code",
|
||||||
|
"json" => "code",
|
||||||
|
"coffee" => "code",
|
||||||
|
// HTML / CSS
|
||||||
|
"html" => "code",
|
||||||
|
"htm" => "code",
|
||||||
|
"xml" => "code",
|
||||||
|
"xhtml" => "code",
|
||||||
|
"vue" => "code",
|
||||||
|
"ejs" => "code",
|
||||||
|
"template" => "code",
|
||||||
|
"tmpl" => "code",
|
||||||
|
"pug" => "code",
|
||||||
|
"art" => "code",
|
||||||
|
"hbs" => "code",
|
||||||
|
"css" => "code",
|
||||||
|
"scss" => "code",
|
||||||
|
"sass" => "code",
|
||||||
|
"less" => "code",
|
||||||
|
// Python
|
||||||
|
"py" => "code",
|
||||||
|
"pyc" => "code",
|
||||||
|
// JVM
|
||||||
|
"java" => "code",
|
||||||
|
"kt" => "code",
|
||||||
|
"kts" => "code",
|
||||||
|
"gradle" => "code",
|
||||||
|
"groovy" => "code",
|
||||||
|
"scala" => "code",
|
||||||
|
"jsp" => "code",
|
||||||
|
// Shell
|
||||||
|
"sh" => "code",
|
||||||
|
// Php
|
||||||
|
"php" => "code",
|
||||||
|
// C / C++
|
||||||
|
"c" => "code",
|
||||||
|
"cc" => "code",
|
||||||
|
"cpp" => "code",
|
||||||
|
"h" => "code",
|
||||||
|
"cmake" => "code",
|
||||||
|
// C#
|
||||||
|
"cs" => "code",
|
||||||
|
"xaml" => "code",
|
||||||
|
"sln" => "code",
|
||||||
|
"csproj" => "code",
|
||||||
|
// Golang
|
||||||
|
"go" => "code",
|
||||||
|
"mod" => "code",
|
||||||
|
"sum" => "code",
|
||||||
|
// Swift
|
||||||
|
"swift" => "code",
|
||||||
|
"plist" => "code",
|
||||||
|
"xib" => "code",
|
||||||
|
"xcconfig" => "code",
|
||||||
|
"entitlements" => "code",
|
||||||
|
"xcworkspacedata" => "code",
|
||||||
|
"pbxproj" => "code",
|
||||||
|
// Ruby
|
||||||
|
"rb" => "code",
|
||||||
|
// Rust
|
||||||
|
"rs" => "code",
|
||||||
|
// Objective-C
|
||||||
|
"m" => "code",
|
||||||
|
// Dart
|
||||||
|
"dart" => "code",
|
||||||
|
// Microsoft
|
||||||
|
"manifest" => "code",
|
||||||
|
"rc" => "code",
|
||||||
|
"cmd" => "code",
|
||||||
|
"bat" => "code",
|
||||||
|
"ps1" => "code",
|
||||||
|
// Config
|
||||||
|
"ini" => "code",
|
||||||
|
"yaml" => "code",
|
||||||
|
"toml" => "code",
|
||||||
|
"conf" => "code",
|
||||||
|
"properties" => "code",
|
||||||
|
"lock" => "alt",
|
||||||
|
_ => match mime_guess::from_path(from).first_or_octet_stream().type_() {
|
||||||
|
mime_guess::mime::AUDIO => "audio",
|
||||||
|
mime_guess::mime::IMAGE => "image",
|
||||||
|
mime_guess::mime::PDF => "pdf",
|
||||||
|
mime_guess::mime::VIDEO => "video",
|
||||||
|
mime_guess::mime::TEXT => "alt",
|
||||||
|
_ => "file",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
None => "file",
|
||||||
|
}
|
||||||
|
.to_string()
|
||||||
|
}
|
622
src/main.rs
622
src/main.rs
@ -2,158 +2,34 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#[macro_use]
|
mod filetype;
|
||||||
extern crate lazy_static;
|
|
||||||
|
|
||||||
use actix_files as fs;
|
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
dev::{self, Service, ServiceResponse},
|
dev::{Response, Service, ServiceRequest, ServiceResponse},
|
||||||
http, middleware, App, HttpResponse, HttpServer,
|
http, middleware, App, HttpRequest, HttpResponse, HttpServer,
|
||||||
};
|
};
|
||||||
use clap::Arg;
|
use actix_web_httpauth::{
|
||||||
|
extractors::{basic::BasicAuth, AuthenticationError},
|
||||||
|
headers::www_authenticate::basic::Basic,
|
||||||
|
middleware::HttpAuthentication,
|
||||||
|
};
|
||||||
|
use askama_actix::TemplateToResponse;
|
||||||
|
use clap::{arg, command, ArgAction};
|
||||||
use env_logger::fmt::Color;
|
use env_logger::fmt::Color;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
use std::{
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
env::{set_var, var},
|
env::{set_var, var},
|
||||||
fs::read_dir,
|
fs::{self, metadata, read_dir, read_to_string},
|
||||||
io::{BufReader, Error, ErrorKind, Read, Write},
|
io::{self, BufReader, Read, Write},
|
||||||
net::IpAddr,
|
net::IpAddr,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
process::{Command, Stdio},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
use time::OffsetDateTime;
|
||||||
lazy_static! {
|
|
||||||
pub static ref TEMPLATE: tera::Tera = {
|
|
||||||
let mut tera = tera::Tera::default();
|
|
||||||
tera.add_raw_template("index", include_str!("../templates/index.html.tera"))
|
|
||||||
.unwrap();
|
|
||||||
tera
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn get_file_type(from: &Path) -> String {
|
|
||||||
match from.extension() {
|
|
||||||
Some(os_str) => match os_str.to_str().unwrap_or("") {
|
|
||||||
"7z" => "archive",
|
|
||||||
"bz" => "archive",
|
|
||||||
"bz2" => "archive",
|
|
||||||
"cab" => "archive",
|
|
||||||
"gz" => "archive",
|
|
||||||
"iso" => "archive",
|
|
||||||
"rar" => "archive",
|
|
||||||
"xz" => "archive",
|
|
||||||
"zip" => "archive",
|
|
||||||
"zst" => "archive",
|
|
||||||
"zstd" => "archive",
|
|
||||||
"doc" => "word",
|
|
||||||
"docx" => "word",
|
|
||||||
"ppt" => "powerpoint",
|
|
||||||
"pptx" => "powerpoint",
|
|
||||||
"xls" => "excel",
|
|
||||||
"xlsx" => "excel",
|
|
||||||
"heic" => "image",
|
|
||||||
"pdf" => "pdf",
|
|
||||||
// JavaScript / TypeScript
|
|
||||||
"js" => "code",
|
|
||||||
"cjs" => "code",
|
|
||||||
"mjs" => "code",
|
|
||||||
"jsx" => "code",
|
|
||||||
"ts" => "code",
|
|
||||||
"tsx" => "code",
|
|
||||||
"json" => "code",
|
|
||||||
"coffee" => "code",
|
|
||||||
// HTML / CSS
|
|
||||||
"html" => "code",
|
|
||||||
"htm" => "code",
|
|
||||||
"xml" => "code",
|
|
||||||
"xhtml" => "code",
|
|
||||||
"vue" => "code",
|
|
||||||
"ejs" => "code",
|
|
||||||
"template" => "code",
|
|
||||||
"tmpl" => "code",
|
|
||||||
"pug" => "code",
|
|
||||||
"art" => "code",
|
|
||||||
"hbs" => "code",
|
|
||||||
"tera" => "code",
|
|
||||||
"css" => "code",
|
|
||||||
"scss" => "code",
|
|
||||||
"sass" => "code",
|
|
||||||
"less" => "code",
|
|
||||||
// Python
|
|
||||||
"py" => "code",
|
|
||||||
"pyc" => "code",
|
|
||||||
// JVM
|
|
||||||
"java" => "code",
|
|
||||||
"kt" => "code",
|
|
||||||
"kts" => "code",
|
|
||||||
"gradle" => "code",
|
|
||||||
"groovy" => "code",
|
|
||||||
"scala" => "code",
|
|
||||||
"jsp" => "code",
|
|
||||||
// Shell
|
|
||||||
"sh" => "code",
|
|
||||||
// Php
|
|
||||||
"php" => "code",
|
|
||||||
// C / C++
|
|
||||||
"c" => "code",
|
|
||||||
"cc" => "code",
|
|
||||||
"cpp" => "code",
|
|
||||||
"h" => "code",
|
|
||||||
"cmake" => "code",
|
|
||||||
// C#
|
|
||||||
"cs" => "code",
|
|
||||||
"xaml" => "code",
|
|
||||||
"sln" => "code",
|
|
||||||
"csproj" => "code",
|
|
||||||
// Golang
|
|
||||||
"go" => "code",
|
|
||||||
"mod" => "code",
|
|
||||||
"sum" => "code",
|
|
||||||
// Swift
|
|
||||||
"swift" => "code",
|
|
||||||
"plist" => "code",
|
|
||||||
"xib" => "code",
|
|
||||||
"xcconfig" => "code",
|
|
||||||
"entitlements" => "code",
|
|
||||||
"xcworkspacedata" => "code",
|
|
||||||
"pbxproj" => "code",
|
|
||||||
// Ruby
|
|
||||||
"rb" => "code",
|
|
||||||
// Rust
|
|
||||||
"rs" => "code",
|
|
||||||
// Objective-C
|
|
||||||
"m" => "code",
|
|
||||||
// Dart
|
|
||||||
"dart" => "code",
|
|
||||||
// Microsoft
|
|
||||||
"manifest" => "code",
|
|
||||||
"rc" => "code",
|
|
||||||
"cmd" => "code",
|
|
||||||
"bat" => "code",
|
|
||||||
"ps1" => "code",
|
|
||||||
// Config
|
|
||||||
"ini" => "code",
|
|
||||||
"yaml" => "code",
|
|
||||||
"toml" => "code",
|
|
||||||
"conf" => "code",
|
|
||||||
"properties" => "code",
|
|
||||||
"lock" => "alt",
|
|
||||||
_ => match mime_guess::from_path(from).first_or_octet_stream().type_() {
|
|
||||||
mime_guess::mime::AUDIO => "audio",
|
|
||||||
mime_guess::mime::IMAGE => "image",
|
|
||||||
mime_guess::mime::PDF => "pdf",
|
|
||||||
mime_guess::mime::VIDEO => "video",
|
|
||||||
mime_guess::mime::TEXT => "alt",
|
|
||||||
_ => "file",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
None => "file",
|
|
||||||
}
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Package {
|
struct Package {
|
||||||
@ -179,9 +55,12 @@ struct File {
|
|||||||
modified: String,
|
modified: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(askama_actix::Template)]
|
||||||
|
#[template(path = "index.html")]
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct IndexContext {
|
struct IndexContext {
|
||||||
title: String,
|
title: String,
|
||||||
|
readme: String,
|
||||||
paths: Vec<String>,
|
paths: Vec<String>,
|
||||||
dirs: Vec<Dir>,
|
dirs: Vec<Dir>,
|
||||||
files: Vec<File>,
|
files: Vec<File>,
|
||||||
@ -189,25 +68,26 @@ struct IndexContext {
|
|||||||
|
|
||||||
fn render_index(
|
fn render_index(
|
||||||
dir: &actix_files::Directory,
|
dir: &actix_files::Directory,
|
||||||
req: &actix_web::HttpRequest,
|
req: &HttpRequest,
|
||||||
) -> Result<ServiceResponse, std::io::Error> {
|
) -> Result<ServiceResponse, io::Error> {
|
||||||
let mut index = dir.path.clone();
|
let mut index = dir.path.clone();
|
||||||
index.push("index.html");
|
index.push("index.html");
|
||||||
if index.exists() && index.is_file() {
|
if index.exists() && index.is_file() {
|
||||||
let res = actix_files::NamedFile::open(index)?
|
let res = actix_files::NamedFile::open(index)?
|
||||||
.set_content_type(mime_guess::mime::TEXT_HTML_UTF_8)
|
.set_content_type(mime_guess::mime::TEXT_HTML_UTF_8)
|
||||||
.into_response(req);
|
.into_response(req);
|
||||||
return Ok(ServiceResponse::new(req.clone(), res));
|
return Ok(ServiceResponse::new(req.to_owned(), res));
|
||||||
}
|
}
|
||||||
if var("NOINDEX").unwrap_or_else(|_| "false".to_string()) == "true" {
|
if var("NOINDEX").unwrap_or_else(|_| "false".to_string()) == "true" {
|
||||||
return Ok(ServiceResponse::new(
|
return Ok(ServiceResponse::new(
|
||||||
req.clone(),
|
req.to_owned(),
|
||||||
HttpResponse::NotFound().body(""),
|
HttpResponse::NotFound().body(""),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let show_dot_files = var("DOTFILES").unwrap_or_else(|_| "false".to_string()) == "true";
|
let show_dot_files = var("DOTFILES").unwrap_or_else(|_| "false".to_string()) == "true";
|
||||||
let mut context = IndexContext {
|
let mut context = IndexContext {
|
||||||
title: "".to_string(),
|
title: "".to_string(),
|
||||||
|
readme: "".to_string(),
|
||||||
paths: vec![],
|
paths: vec![],
|
||||||
dirs: vec![],
|
dirs: vec![],
|
||||||
files: vec![],
|
files: vec![],
|
||||||
@ -216,11 +96,11 @@ fn render_index(
|
|||||||
if path.is_empty() {
|
if path.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let path =
|
let path = urlencoding::decode(path).unwrap_or(Cow::Borrowed("[Parse URL Error]"));
|
||||||
urlencoding::decode(path).unwrap_or(std::borrow::Cow::Borrowed("[Parse URL Error]"));
|
|
||||||
let path = path.into_owned();
|
let path = path.into_owned();
|
||||||
context.paths.push(path);
|
context.paths.push(path);
|
||||||
}
|
}
|
||||||
|
let mut readme_str = "".to_string();
|
||||||
match read_dir(&dir.path) {
|
match read_dir(&dir.path) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!(target: "read_dir", "[ERROR] Read dir error: {}", e.to_string());
|
error!(target: "read_dir", "[ERROR] Read dir error: {}", e.to_string());
|
||||||
@ -252,9 +132,11 @@ fn render_index(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let modified = match metadata.modified() {
|
let modified = match metadata.modified() {
|
||||||
Ok(time) => chrono::DateTime::<chrono::Local>::from(time)
|
Ok(time) => OffsetDateTime::from(time)
|
||||||
.format("%Y/%m/%d %H:%M:%S")
|
.format(time::macros::format_description!(
|
||||||
.to_string(),
|
"[year]/[month]/[day] [hour]:[minute]:[second]"
|
||||||
|
))
|
||||||
|
.unwrap_or_else(|_| "".to_string()),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!(target: "read_dir", "[ERROR] Read modified time error: {}", e.to_string());
|
error!(target: "read_dir", "[ERROR] Read modified time error: {}", e.to_string());
|
||||||
continue;
|
continue;
|
||||||
@ -264,35 +146,55 @@ fn render_index(
|
|||||||
context.dirs.push(Dir { name, modified });
|
context.dirs.push(Dir { name, modified });
|
||||||
} else if metadata.is_file() {
|
} else if metadata.is_file() {
|
||||||
let size = metadata.len();
|
let size = metadata.len();
|
||||||
let filetype = get_file_type(&path.path());
|
let filetype = filetype::get_file_type(&path.path());
|
||||||
context.files.push(File {
|
context.files.push(File {
|
||||||
name,
|
name,
|
||||||
size,
|
size,
|
||||||
filetype,
|
filetype,
|
||||||
modified,
|
modified,
|
||||||
});
|
});
|
||||||
|
if path.file_name().to_ascii_lowercase() == "readme.md" {
|
||||||
|
readme_str = read_to_string(path.path()).unwrap_or_else(|_| "".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if var("NOREADME").unwrap_or_else(|_| "false".to_string()) != "true" {
|
||||||
|
context.readme = comrak::markdown_to_html(
|
||||||
|
&readme_str,
|
||||||
|
&comrak::ComrakOptions {
|
||||||
|
extension: comrak::ComrakExtensionOptions {
|
||||||
|
strikethrough: true,
|
||||||
|
tagfilter: true,
|
||||||
|
table: true,
|
||||||
|
autolink: true,
|
||||||
|
tasklist: true,
|
||||||
|
superscript: true,
|
||||||
|
header_ids: None,
|
||||||
|
footnotes: true,
|
||||||
|
description_lists: true,
|
||||||
|
front_matter_delimiter: None,
|
||||||
|
},
|
||||||
|
parse: comrak::ComrakParseOptions {
|
||||||
|
smart: false,
|
||||||
|
default_info_string: None,
|
||||||
|
},
|
||||||
|
render: comrak::ComrakRenderOptions {
|
||||||
|
hardbreaks: false,
|
||||||
|
github_pre_lang: false,
|
||||||
|
width: 1000,
|
||||||
|
unsafe_: true,
|
||||||
|
escape: false,
|
||||||
|
list_style: comrak::ListStyleType::default(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
context.title = context.paths.last().unwrap_or(&"/".to_string()).to_string();
|
context.title = context.paths.last().unwrap_or(&"/".to_string()).to_string();
|
||||||
context.dirs.sort();
|
context.dirs.sort();
|
||||||
context.files.sort();
|
context.files.sort();
|
||||||
let content = tera::Context::from_serialize(&context);
|
Ok(ServiceResponse::new(req.to_owned(), context.to_response()))
|
||||||
let content = match content {
|
|
||||||
Ok(ctx) => ctx,
|
|
||||||
Err(e) => {
|
|
||||||
error!(target: "tera::Context::from_serialize", "[ERROR] Read modified time error: {}", e.to_string());
|
|
||||||
return Err(Error::new(ErrorKind::Other, e.to_string()));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let index = TEMPLATE
|
|
||||||
.render("index", &content)
|
|
||||||
.unwrap_or_else(|_| "TEMPLATE RENDER ERROR".to_string());
|
|
||||||
let res = HttpResponse::Ok()
|
|
||||||
.content_type("text/html; charset=utf-8")
|
|
||||||
.body(index);
|
|
||||||
Ok(ServiceResponse::new(req.clone(), res))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -314,44 +216,40 @@ fn hash(from: &str) -> String {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn validator(
|
async fn validator(
|
||||||
req: dev::ServiceRequest,
|
req: ServiceRequest,
|
||||||
auth: actix_web_httpauth::extractors::basic::BasicAuth,
|
auth: BasicAuth,
|
||||||
) -> Result<dev::ServiceRequest, actix_web::Error> {
|
) -> Result<ServiceRequest, (actix_web::Error, ServiceRequest)> {
|
||||||
if auth.user_id()
|
if auth.user_id()
|
||||||
== var("AUTH_USERNAME")
|
== var("AUTH_USERNAME")
|
||||||
.unwrap_or_else(|_| "".to_string())
|
.unwrap_or_else(|_| "".to_string())
|
||||||
.as_str()
|
.as_str()
|
||||||
&& hash(auth.password().unwrap_or(&std::borrow::Cow::from("")))
|
&& hash(auth.password().unwrap_or(&Cow::from("")))
|
||||||
== var("AUTH_PASSWORD")
|
== var("AUTH_PASSWORD")
|
||||||
.unwrap_or_else(|_| "".to_string())
|
.unwrap_or_else(|_| "".to_string())
|
||||||
.as_str()
|
.as_str()
|
||||||
{
|
{
|
||||||
return Ok(req);
|
return Ok(req);
|
||||||
}
|
}
|
||||||
let err = actix_web_httpauth::extractors::AuthenticationError::new(
|
let err = AuthenticationError::new(Basic::with_realm("Incorrect username or password"));
|
||||||
actix_web_httpauth::headers::www_authenticate::basic::Basic::with_realm(
|
Err((actix_web::Error::from(err), req))
|
||||||
"Incorrect username or password",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
Err(actix_web::Error::from(err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
let check_does_dir_exits = |path: &str| match std::fs::metadata(path) {
|
let check_does_dir_exits = |path: &str| match metadata(path) {
|
||||||
Ok(meta) => {
|
Ok(meta) => {
|
||||||
if meta.is_dir() {
|
if meta.is_dir() {
|
||||||
Ok(())
|
Ok(path.to_string())
|
||||||
} else {
|
} else {
|
||||||
Err("Parameter is not a directory".to_owned())
|
Err("Parameter is not a directory".to_owned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => Err(e.to_string()),
|
Err(e) => Err(e.to_string()),
|
||||||
};
|
};
|
||||||
let check_does_file_exits = |path: &str| match std::fs::metadata(path) {
|
let check_does_file_exits = |path: &str| match metadata(path) {
|
||||||
Ok(metadata) => {
|
Ok(metadata) => {
|
||||||
if metadata.is_file() {
|
if metadata.is_file() {
|
||||||
Ok(())
|
Ok(path.to_string())
|
||||||
} else {
|
} else {
|
||||||
Err("Parameter is not a file".to_owned())
|
Err("Parameter is not a file".to_owned())
|
||||||
}
|
}
|
||||||
@ -359,11 +257,11 @@ async fn main() -> std::io::Result<()> {
|
|||||||
Err(e) => Err(e.to_string()),
|
Err(e) => Err(e.to_string()),
|
||||||
};
|
};
|
||||||
let check_is_ip_addr = |s: &str| match IpAddr::from_str(s) {
|
let check_is_ip_addr = |s: &str| match IpAddr::from_str(s) {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(s.to_string()),
|
||||||
Err(e) => Err(e.to_string()),
|
Err(e) => Err(e.to_string()),
|
||||||
};
|
};
|
||||||
let check_is_port_num = |s: &str| match s.parse::<u16>() {
|
let check_is_port_num = |s: &str| match s.parse::<u16>() {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(s.to_string()),
|
||||||
Err(e) => Err(e.to_string()),
|
Err(e) => Err(e.to_string()),
|
||||||
};
|
};
|
||||||
let check_is_auth = |s: &str| {
|
let check_is_auth = |s: &str| {
|
||||||
@ -373,81 +271,90 @@ async fn main() -> std::io::Result<()> {
|
|||||||
} else if parts[0].is_empty() {
|
} else if parts[0].is_empty() {
|
||||||
Err("Username not found".to_owned())
|
Err("Username not found".to_owned())
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(s.to_string())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let matches = clap::command!()
|
let matches = command!()
|
||||||
.arg(Arg::new("noindex").long("noindex").help("Disable automatic index page generation"))
|
.arg(arg!(--noindex "Disable automatic index page generation").required(false))
|
||||||
.arg(Arg::new("nocache").long("nocache").help("Disable HTTP cache"))
|
.arg(arg!(--noreadme "Disable automatic readme rendering").required(false))
|
||||||
.arg(Arg::new("nocolor").long("nocolor").help("Disable cli colors"))
|
.arg(arg!(--nocache "Disable HTTP cache").required(false))
|
||||||
.arg(Arg::new("cors").long("cors").takes_value(true).min_values(0).max_values(1).help("Enable CORS [with custom value]"))
|
.arg(arg!(--nocolor "Disable cli colors").required(false))
|
||||||
.arg(Arg::new("spa").long("spa").help("Enable Single-Page Application mode (always serve /index.html when the file is not found)"))
|
.arg(arg!(--cors [hostname] "Enable CORS [with custom value]").required(false).action(ArgAction::Append))
|
||||||
.arg(Arg::new("dotfiles").short('d').long("dotfiles").help("Show dotfiles"))
|
.arg(arg!(--spa "Enable Single-Page Application mode (always serve /index.html when the file is not found)").required(false))
|
||||||
.arg(Arg::new("open").short('o').long("open").help("Open the page in the default browser"))
|
.arg(arg!(-d --dotfiles "Show dotfiles").required(false))
|
||||||
.arg(Arg::new("quiet").short('q').long("quiet").help("Disable access log output"))
|
.arg(arg!(-o --open "Open the page in the default browser").required(false))
|
||||||
.arg(Arg::new("quietall").long("quietall").help("Disable all output"))
|
.arg(arg!(-q --quiet "Disable access log output").required(false))
|
||||||
.arg(Arg::new("ROOT").default_value(".").validator(check_does_dir_exits).help("Root directory"))
|
.arg(arg!(--quietall "Disable all output").required(false))
|
||||||
.arg(Arg::new("address").short('a').long("address").default_value("0.0.0.0").takes_value(true).validator(check_is_ip_addr).help("IP address to serve on"))
|
.arg(arg!([root] "Root directory").default_value(".").value_parser(check_does_dir_exits))
|
||||||
.arg(Arg::new("port").short('p').long("port").default_value("8000").takes_value(true).validator(check_is_port_num).help("Port to serve on"))
|
.arg(arg!(-a --address <ipaddr> "IP address to serve on").default_value("0.0.0.0").value_parser(check_is_ip_addr))
|
||||||
.arg(Arg::new("auth").long("auth").takes_value(true).validator(check_is_auth).help("HTTP Auth (username:password)"))
|
.arg(arg!(-p --port <port> "Port to serve on").default_value("8000").value_parser(check_is_port_num))
|
||||||
.arg(Arg::new("cert").long("cert").takes_value(true).validator(check_does_file_exits).help("Path of TLS/SSL public key (certificate)"))
|
.arg(arg!(--auth <pattern> "HTTP Auth (username:password)").required(false).value_parser(check_is_auth))
|
||||||
.arg(Arg::new("key").long("key").takes_value(true).validator(check_does_file_exits).help("Path of TLS/SSL private key"))
|
.arg(arg!(--cert <path> "Path of TLS/SSL public key (certificate)").required(false).value_parser(check_does_file_exits))
|
||||||
|
.arg(arg!(--key <path> "Path of TLS/SSL private key").required(false).value_parser(check_does_file_exits))
|
||||||
.subcommand(clap::Command::new("doc")
|
.subcommand(clap::Command::new("doc")
|
||||||
.about("Open cargo doc via local server (Need cargo installation)")
|
.about("Open cargo doc via local server (Need cargo installation)")
|
||||||
.arg(Arg::new("nocolor").long("nocolor").help("Disable cli colors"))
|
.arg(arg!(--nocolor "Disable cli colors"))
|
||||||
.arg(Arg::new("noopen").long("noopen").help("Do not open the page in the default browser"))
|
.arg(arg!(--noopen "Do not open the page in the default browser"))
|
||||||
.arg(Arg::new("log").long("log").help("Enable access log output [default: disabled]"))
|
.arg(arg!(--log "Enable access log output [default: disabled]"))
|
||||||
.arg(Arg::new("quietall").long("quietall").help("Disable all output"))
|
.arg(arg!(--quietall "Disable all output"))
|
||||||
.arg(Arg::new("address").short('a').long("address").default_value("0.0.0.0").takes_value(true).validator(check_is_ip_addr).help("IP address to serve on"))
|
.arg(arg!(-a --address <ipaddr> "IP address to serve on").required(false).default_value("0.0.0.0").value_parser(check_is_ip_addr))
|
||||||
.arg(Arg::new("port").short('p').long("port").default_value("8000").takes_value(true).validator(check_is_port_num).help("Port to serve on"))
|
.arg(arg!(-p --port <port> "Port to serve on").required(false).default_value("8000").value_parser(check_is_port_num))
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
set_var(
|
set_var(
|
||||||
"ROOT",
|
"ROOT",
|
||||||
display_path(Path::new(matches.value_of("ROOT").unwrap_or("."))),
|
display_path(Path::new(
|
||||||
|
matches
|
||||||
|
.get_one::<String>("root")
|
||||||
|
.unwrap_or(&".".to_string()),
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
set_var("NOINDEX", matches.is_present("noindex").to_string());
|
set_var("NOINDEX", matches.get_flag("noindex").to_string());
|
||||||
set_var("SPA", matches.is_present("spa").to_string());
|
set_var("NOREADME", matches.get_flag("noreadme").to_string());
|
||||||
set_var("DOTFILES", matches.is_present("dotfiles").to_string());
|
set_var("SPA", matches.get_flag("spa").to_string());
|
||||||
set_var("NOCACHE", matches.is_present("nocache").to_string());
|
set_var("DOTFILES", matches.get_flag("dotfiles").to_string());
|
||||||
|
set_var("NOCACHE", matches.get_flag("nocache").to_string());
|
||||||
|
|
||||||
if matches.is_present("quiet") {
|
if matches.get_flag("quiet") {
|
||||||
set_var("RUST_LOG", "info,actix_web::middleware::logger=off");
|
set_var("RUST_LOG", "info,actix_web::middleware::logger=off");
|
||||||
}
|
}
|
||||||
if matches.is_present("quietall") {
|
if matches.get_flag("quietall") {
|
||||||
set_var("RUST_LOG", "off");
|
set_var("RUST_LOG", "off");
|
||||||
}
|
}
|
||||||
if matches.is_present("nocolor") {
|
if matches.get_flag("nocolor") {
|
||||||
set_var("RUST_LOG_STYLE", "never");
|
set_var("RUST_LOG_STYLE", "never");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(s) = matches.value_of("auth") {
|
if let Some(s) = matches.get_one::<String>("auth") {
|
||||||
set_var("ENABLE_AUTH", matches.is_present("auth").to_string());
|
set_var("ENABLE_AUTH", matches.get_flag("auth").to_string());
|
||||||
let parts = s.splitn(2, ':').collect::<Vec<&str>>();
|
let parts = s.splitn(2, ':').collect::<Vec<&str>>();
|
||||||
set_var("AUTH_USERNAME", parts[0]);
|
set_var("AUTH_USERNAME", parts[0]);
|
||||||
set_var("AUTH_PASSWORD", hash(parts[1]));
|
set_var("AUTH_PASSWORD", hash(parts[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.is_present("cors") {
|
if let Some(mut cors) = matches.get_many::<String>("cors") {
|
||||||
set_var("ENABLE_CORS", matches.is_present("cors").to_string());
|
set_var("ENABLE_CORS", "true");
|
||||||
match matches.value_of("cors") {
|
match cors.next() {
|
||||||
Some(str) => {
|
Some(value) => set_var("CORS", value),
|
||||||
set_var("CORS", str);
|
None => set_var("CORS", "*"),
|
||||||
}
|
|
||||||
None => {
|
|
||||||
set_var("CORS", "*");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let enable_tls = matches.is_present("cert") && matches.is_present("key");
|
let enable_tls =
|
||||||
|
matches.get_one::<String>("cert").is_some() && matches.get_one::<String>("key").is_some();
|
||||||
let ip = matches
|
let ip = matches
|
||||||
.value_of("address")
|
.get_one::<String>("address")
|
||||||
.unwrap_or("127.0.0.1")
|
.unwrap_or(&"127.0.0.1".to_string())
|
||||||
.to_string();
|
.to_string();
|
||||||
let addr = format!("{}:{}", ip, matches.value_of("port").unwrap_or("8000"));
|
let addr = format!(
|
||||||
|
"{}:{}",
|
||||||
|
ip,
|
||||||
|
matches
|
||||||
|
.get_one::<String>("port")
|
||||||
|
.unwrap_or(&"8000".to_string())
|
||||||
|
);
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}{}:{}",
|
"{}{}:{}",
|
||||||
if enable_tls {
|
if enable_tls {
|
||||||
@ -456,14 +363,16 @@ async fn main() -> std::io::Result<()> {
|
|||||||
"http://".to_string()
|
"http://".to_string()
|
||||||
},
|
},
|
||||||
if ip == "0.0.0.0" { "127.0.0.1" } else { &ip },
|
if ip == "0.0.0.0" { "127.0.0.1" } else { &ip },
|
||||||
matches.value_of("port").unwrap_or("8000")
|
matches
|
||||||
|
.get_one::<String>("port")
|
||||||
|
.unwrap_or(&"8000".to_string())
|
||||||
);
|
);
|
||||||
|
|
||||||
let open_in_browser = |url: &str| {
|
let open_in_browser = |url: &str| {
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") {
|
||||||
std::process::Command::new("explorer").arg(url).spawn().ok();
|
Command::new("explorer").arg(url).spawn().ok();
|
||||||
} else if cfg!(target_os = "macos") {
|
} else if cfg!(target_os = "macos") {
|
||||||
std::process::Command::new("open").arg(url).spawn().ok();
|
Command::new("open").arg(url).spawn().ok();
|
||||||
} else if cfg!(target_os = "linux")
|
} else if cfg!(target_os = "linux")
|
||||||
|| cfg!(target_os = "android")
|
|| cfg!(target_os = "android")
|
||||||
|| cfg!(target_os = "freebsd")
|
|| cfg!(target_os = "freebsd")
|
||||||
@ -471,16 +380,111 @@ async fn main() -> std::io::Result<()> {
|
|||||||
|| cfg!(target_os = "openbsd")
|
|| cfg!(target_os = "openbsd")
|
||||||
|| cfg!(target_os = "netbsd")
|
|| cfg!(target_os = "netbsd")
|
||||||
{
|
{
|
||||||
std::process::Command::new("xdg-open").arg(url).spawn().ok();
|
Command::new("xdg-open").arg(url).spawn().ok();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.is_present("open") {
|
if matches.get_flag("open") {
|
||||||
open_in_browser(&url);
|
open_in_browser(&url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(matches) = matches.subcommand_matches("doc") {
|
||||||
|
if !matches.get_flag("log") {
|
||||||
|
set_var("RUST_LOG", "info,actix_web::middleware::logger=off");
|
||||||
|
}
|
||||||
|
if matches.get_flag("quietall") {
|
||||||
|
set_var("RUST_LOG", "off");
|
||||||
|
}
|
||||||
|
if matches.get_flag("nocolor") {
|
||||||
|
set_var("RUST_LOG_STYLE", "never");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
|
||||||
|
.format(move |buf, record| {
|
||||||
|
let data = record.args().to_string();
|
||||||
|
let mut style = buf.style();
|
||||||
|
let blue = style.set_color(Color::Cyan);
|
||||||
|
let mut style = buf.style();
|
||||||
|
let red = style.set_color(Color::Red);
|
||||||
|
let mut style = buf.style();
|
||||||
|
let green = style.set_color(Color::Green);
|
||||||
|
if record.target() == "actix_web::middleware::logger" {
|
||||||
|
let data: Vec<&str> = data.splitn(5, '^').collect();
|
||||||
|
let time = blue.value(
|
||||||
|
OffsetDateTime::parse(data[0], &time::format_description::well_known::Rfc3339)
|
||||||
|
.unwrap_or(OffsetDateTime::UNIX_EPOCH)
|
||||||
|
.format(time::macros::format_description!(
|
||||||
|
"[year]/[month]/[day] [hour]:[minute]:[second]"
|
||||||
|
))
|
||||||
|
.unwrap_or_else(|_| "".to_string()),
|
||||||
|
);
|
||||||
|
let ipaddr = blue.value(data[1]);
|
||||||
|
let status_code = data[2].parse().unwrap_or(500);
|
||||||
|
let status_code = if status_code < 400 {
|
||||||
|
green.value(status_code)
|
||||||
|
} else {
|
||||||
|
red.value(status_code)
|
||||||
|
};
|
||||||
|
let process_time: Vec<&str> = data[3].splitn(2, '.').collect();
|
||||||
|
let process_time = process_time[0].to_string() + "ms";
|
||||||
|
let process_time = blue.value(if process_time.len() == 3 {
|
||||||
|
" ".to_string() + &process_time
|
||||||
|
} else if process_time.len() == 4 {
|
||||||
|
" ".to_string() + &process_time
|
||||||
|
} else {
|
||||||
|
process_time
|
||||||
|
});
|
||||||
|
let content = blue.value(
|
||||||
|
urlencoding::decode(data[4])
|
||||||
|
.unwrap_or(Cow::Borrowed("[Parse URL Error]"))
|
||||||
|
.into_owned(),
|
||||||
|
);
|
||||||
|
return writeln!(
|
||||||
|
buf,
|
||||||
|
"[{}] {} | {} | {} | {}",
|
||||||
|
time, ipaddr, status_code, process_time, content
|
||||||
|
);
|
||||||
|
} else if record.target() == "actix_server::builder" {
|
||||||
|
if data.starts_with("Starting ") && data.ends_with(" workers") {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
} else if record.target() == "actix_server::server" {
|
||||||
|
if data == "Actix runtime found; starting in Actix runtime" {
|
||||||
|
let data = format!(
|
||||||
|
"[INFO] Serving {} on {}",
|
||||||
|
var("ROOT").unwrap_or_else(|_| ".".to_string()),
|
||||||
|
var("LISTEN_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8000".to_string())
|
||||||
|
);
|
||||||
|
return writeln!(buf, "\r{}", green.value(data));
|
||||||
|
}
|
||||||
|
if data == "SIGINT received; starting forced shutdown" {
|
||||||
|
return writeln!(
|
||||||
|
buf,
|
||||||
|
"\r{}",
|
||||||
|
green.value("[INFO] SIGINT received; starting forced shutdown")
|
||||||
|
);
|
||||||
|
// Add '\r' to remove the input ^C
|
||||||
|
}
|
||||||
|
return Ok(());
|
||||||
|
} else if record.target() == "actix_server::worker"
|
||||||
|
|| record.target() == "actix_server::accept"
|
||||||
|
{
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
if data.starts_with("[ERROR]")
|
||||||
|
|| data.starts_with("TLS alert")
|
||||||
|
|| data.starts_with("Failed")
|
||||||
|
{
|
||||||
|
writeln!(buf, "\r{}", red.value(data))
|
||||||
|
} else {
|
||||||
|
writeln!(buf, "\r{}", green.value(data))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.init();
|
||||||
|
|
||||||
let addr = if let Some(matches) = matches.subcommand_matches("doc") {
|
let addr = if let Some(matches) = matches.subcommand_matches("doc") {
|
||||||
let mut cargo_toml = match std::fs::File::open("./Cargo.toml") {
|
let mut cargo_toml = match fs::File::open("./Cargo.toml") {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("[ERROR] {}", e.to_string());
|
error!("[ERROR] {}", e.to_string());
|
||||||
@ -504,17 +508,19 @@ async fn main() -> std::io::Result<()> {
|
|||||||
};
|
};
|
||||||
let crate_name = contents.package.name;
|
let crate_name = contents.package.name;
|
||||||
info!("[INFO] Generating document (may take a while)");
|
info!("[INFO] Generating document (may take a while)");
|
||||||
match std::process::Command::new("cargo").arg("doc").output() {
|
match Command::new("cargo")
|
||||||
Ok(output) => {
|
.arg("doc")
|
||||||
let output = std::str::from_utf8(&output.stderr).unwrap_or("");
|
.stdin(Stdio::inherit())
|
||||||
if output.starts_with("error: could not find `Cargo.toml` in") {
|
.stdout(Stdio::inherit())
|
||||||
error!("[ERROR] Cargo.toml Not Found");
|
.stderr(Stdio::inherit())
|
||||||
return Ok(());
|
.status()
|
||||||
} else if output.starts_with("error: ") {
|
{
|
||||||
error!(
|
Ok(status) => {
|
||||||
"[ERROR] {}",
|
if !status.success() {
|
||||||
output.strip_prefix("error: ").unwrap_or(output)
|
match status.code() {
|
||||||
);
|
Some(code) => error!("[ERROR] Cargo exited with status code: {code}"),
|
||||||
|
None => error!("[ERROR] Cargo terminated by signal"),
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -532,111 +538,32 @@ async fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
set_var("ROOT", display_path(path));
|
set_var("ROOT", display_path(path));
|
||||||
let ip = matches
|
let ip = matches
|
||||||
.value_of("address")
|
.get_one::<String>("address")
|
||||||
.unwrap_or("127.0.0.1")
|
.unwrap_or(&"127.0.0.1".to_string())
|
||||||
.to_string();
|
.to_string();
|
||||||
let addr = format!("{}:{}", ip, matches.value_of("port").unwrap_or("8000"));
|
let addr = format!(
|
||||||
|
"{}:{}",
|
||||||
|
ip,
|
||||||
|
matches
|
||||||
|
.get_one::<String>("port")
|
||||||
|
.unwrap_or(&"8000".to_string())
|
||||||
|
);
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"http://{}:{}/{}/index.html",
|
"http://{}:{}/{}/index.html",
|
||||||
if ip == "0.0.0.0" { "127.0.0.1" } else { &ip },
|
if ip == "0.0.0.0" { "127.0.0.1" } else { &ip },
|
||||||
matches.value_of("port").unwrap_or("8000"),
|
matches
|
||||||
|
.get_one::<String>("port")
|
||||||
|
.unwrap_or(&"8000".to_string()),
|
||||||
crate_name,
|
crate_name,
|
||||||
);
|
);
|
||||||
if !matches.is_present("noopen") {
|
if !matches.get_flag("noopen") {
|
||||||
open_in_browser(&url);
|
open_in_browser(&url);
|
||||||
}
|
}
|
||||||
if !matches.is_present("log") {
|
|
||||||
set_var("RUST_LOG", "info,actix_web::middleware::logger=off");
|
|
||||||
}
|
|
||||||
if matches.is_present("quietall") {
|
|
||||||
set_var("RUST_LOG", "off");
|
|
||||||
}
|
|
||||||
if matches.is_present("nocolor") {
|
|
||||||
set_var("RUST_LOG_STYLE", "never");
|
|
||||||
}
|
|
||||||
addr
|
addr
|
||||||
} else {
|
} else {
|
||||||
addr
|
addr
|
||||||
};
|
};
|
||||||
|
set_var("LISTEN_ADDRESS", addr);
|
||||||
let addr_copy = addr.clone();
|
|
||||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
|
|
||||||
.format(move |buf, record| {
|
|
||||||
let data = record.args().to_string();
|
|
||||||
let mut style = buf.style();
|
|
||||||
let blue = style.set_color(Color::Cyan);
|
|
||||||
let mut style = buf.style();
|
|
||||||
let red = style.set_color(Color::Red);
|
|
||||||
let mut style = buf.style();
|
|
||||||
let green = style.set_color(Color::Green);
|
|
||||||
if record.target() == "actix_web::middleware::logger" {
|
|
||||||
let data: Vec<&str> = data.splitn(5, '^').collect();
|
|
||||||
let time = blue.value(
|
|
||||||
data[0]
|
|
||||||
.parse::<chrono::DateTime<chrono::Utc>>()
|
|
||||||
.unwrap()
|
|
||||||
.format("%Y/%m/%d %H:%M:%S")
|
|
||||||
.to_string(),
|
|
||||||
);
|
|
||||||
let ipaddr = blue.value(data[1]);
|
|
||||||
let status_code = data[2].parse().unwrap_or(500);
|
|
||||||
let status_code = if status_code < 400 {
|
|
||||||
green.value(status_code)
|
|
||||||
} else {
|
|
||||||
red.value(status_code)
|
|
||||||
};
|
|
||||||
let process_time: Vec<&str> = data[3].splitn(2, '.').collect();
|
|
||||||
let process_time = process_time[0].to_string() + "ms";
|
|
||||||
let process_time = blue.value(if process_time.len() == 3 {
|
|
||||||
" ".to_string() + &process_time
|
|
||||||
} else if process_time.len() == 4 {
|
|
||||||
" ".to_string() + &process_time
|
|
||||||
} else {
|
|
||||||
process_time
|
|
||||||
});
|
|
||||||
let content = blue.value(
|
|
||||||
urlencoding::decode(data[4])
|
|
||||||
.unwrap_or(std::borrow::Cow::Borrowed("[Parse URL Error]"))
|
|
||||||
.into_owned(),
|
|
||||||
);
|
|
||||||
return writeln!(
|
|
||||||
buf,
|
|
||||||
"[{}] {} | {} | {} | {}",
|
|
||||||
time, ipaddr, status_code, process_time, content
|
|
||||||
);
|
|
||||||
} else if record.target() == "actix_server::builder" {
|
|
||||||
if data.starts_with("Starting ") && data.ends_with(" workers") {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
} else if record.target() == "actix_server::server" {
|
|
||||||
if data == "Actix runtime found; starting in Actix runtime" {
|
|
||||||
let data = format!(
|
|
||||||
"[INFO] Serving {} on {}",
|
|
||||||
var("ROOT").unwrap_or_else(|_| ".".to_string()),
|
|
||||||
addr_copy
|
|
||||||
);
|
|
||||||
return writeln!(buf, "\r{}", green.value(data));
|
|
||||||
}
|
|
||||||
if data == "SIGINT received; starting forced shutdown" {
|
|
||||||
return writeln!(buf, "\r{}", green.value("[INFO] SIGINT received; starting forced shutdown"));
|
|
||||||
// Add '\r' to remove the input ^C
|
|
||||||
}
|
|
||||||
return Ok(());
|
|
||||||
} else if record.target() == "actix_server::worker"
|
|
||||||
|| record.target() == "actix_server::accept"
|
|
||||||
{
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
if data.starts_with("[ERROR]")
|
|
||||||
|| data.starts_with("TLS alert")
|
|
||||||
|| data.starts_with("Failed")
|
|
||||||
{
|
|
||||||
writeln!(buf, "\r{}", red.value(data))
|
|
||||||
} else {
|
|
||||||
writeln!(buf, "\r{}", green.value(data))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.init();
|
|
||||||
|
|
||||||
let server = HttpServer::new(move || {
|
let server = HttpServer::new(move || {
|
||||||
let app = App::new()
|
let app = App::new()
|
||||||
@ -667,7 +594,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
if isdotfile
|
if isdotfile
|
||||||
&& var("DOTFILES").unwrap_or_else(|_| "false".to_string()) != "true"
|
&& var("DOTFILES").unwrap_or_else(|_| "false".to_string()) != "true"
|
||||||
{
|
{
|
||||||
return dev::Response::new(http::StatusCode::FORBIDDEN).into_body();
|
return Response::new(http::StatusCode::FORBIDDEN).into_body();
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
}))
|
}))
|
||||||
@ -676,15 +603,15 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
.wrap(middleware::Condition::new(
|
.wrap(middleware::Condition::new(
|
||||||
var("ENABLE_AUTH").unwrap_or_else(|_| "false".to_string()) == "true",
|
var("ENABLE_AUTH").unwrap_or_else(|_| "false".to_string()) == "true",
|
||||||
actix_web_httpauth::middleware::HttpAuthentication::basic(validator),
|
HttpAuthentication::basic(validator),
|
||||||
))
|
))
|
||||||
.wrap(middleware::Logger::new("%t^%a^%s^%D^%r"));
|
.wrap(middleware::Logger::new("%t^%a^%s^%D^%r"));
|
||||||
let files = fs::Files::new("/", var("ROOT").unwrap_or_else(|_| ".".to_string()))
|
let files = actix_files::Files::new("/", var("ROOT").unwrap_or_else(|_| ".".to_string()))
|
||||||
.use_hidden_files()
|
.use_hidden_files()
|
||||||
.prefer_utf8(true)
|
.prefer_utf8(true)
|
||||||
.show_files_listing()
|
.show_files_listing()
|
||||||
.files_listing_renderer(render_index)
|
.files_listing_renderer(render_index)
|
||||||
.default_handler(|req: dev::ServiceRequest| {
|
.default_handler(|req: ServiceRequest| {
|
||||||
let (http_req, _payload) = req.into_parts();
|
let (http_req, _payload) = req.into_parts();
|
||||||
async {
|
async {
|
||||||
let path = var("ROOT").unwrap_or_else(|_| ".".to_string());
|
let path = var("ROOT").unwrap_or_else(|_| ".".to_string());
|
||||||
@ -694,7 +621,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
&& path.is_file()
|
&& path.is_file()
|
||||||
&& var("SPA").unwrap_or_else(|_| "false".to_string()) == "true"
|
&& var("SPA").unwrap_or_else(|_| "false".to_string()) == "true"
|
||||||
{
|
{
|
||||||
let res = fs::NamedFile::open(path)?.into_response(&http_req);
|
let res = actix_files::NamedFile::open(path)?.into_response(&http_req);
|
||||||
return Ok(ServiceResponse::new(http_req, res));
|
return Ok(ServiceResponse::new(http_req, res));
|
||||||
}
|
}
|
||||||
Ok(ServiceResponse::new(
|
Ok(ServiceResponse::new(
|
||||||
@ -707,10 +634,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
});
|
});
|
||||||
let server = if enable_tls {
|
let server = if enable_tls {
|
||||||
let cert = &mut BufReader::new(
|
let cert = &mut BufReader::new(
|
||||||
std::fs::File::open(Path::new(matches.value_of("cert").unwrap())).unwrap(),
|
fs::File::open(Path::new(matches.get_one::<String>("cert").unwrap())).unwrap(),
|
||||||
);
|
);
|
||||||
let key = &mut BufReader::new(
|
let key = &mut BufReader::new(
|
||||||
std::fs::File::open(Path::new(matches.value_of("key").unwrap())).unwrap(),
|
fs::File::open(Path::new(matches.get_one::<String>("key").unwrap())).unwrap(),
|
||||||
);
|
);
|
||||||
let cert = rustls_pemfile::certs(cert)
|
let cert = rustls_pemfile::certs(cert)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -729,9 +656,12 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.with_no_client_auth()
|
.with_no_client_auth()
|
||||||
.with_single_cert(cert, key)
|
.with_single_cert(cert, key)
|
||||||
.expect("bad certificate/key");
|
.expect("bad certificate/key");
|
||||||
server.bind_rustls(addr, config)
|
server.bind_rustls(
|
||||||
|
var("LISTEN_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8000".to_string()),
|
||||||
|
config,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
server.bind(addr)
|
server.bind(var("LISTEN_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8000".to_string()))
|
||||||
};
|
};
|
||||||
server?.run().await
|
server?.run().await
|
||||||
}
|
}
|
||||||
|
1
templates/github-markdown.css.html
Normal file
1
templates/github-markdown.css.html
Normal file
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{# This Source Code Form is subject to the terms of the Mozilla Public
|
{# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/. #}
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/. -#}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
@ -12,9 +12,12 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="color-scheme" content="light dark">
|
<meta name="color-scheme" content="light dark">
|
||||||
<title>{{ title }}</title>
|
<title>{{ title }}</title>
|
||||||
<!--[if lt IE 9
|
<!--[if lt IE 9]><script>
|
||||||
]><script src="https://cdn.jsdelivr.net/npm/html5shiv/dist/html5shiv.min.js"></script
|
/**
|
||||||
><![endif]-->
|
* @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
|
||||||
|
*/
|
||||||
|
!function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x<style>"+b+"</style>",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.3-pre",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="<xyz></xyz>",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b),"object"==typeof module&&module.exports&&(module.exports=t)}("undefined"!=typeof window?window:this,document);
|
||||||
|
</script><![endif]-->
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
body,
|
body,
|
||||||
@ -142,7 +145,7 @@
|
|||||||
#meta,
|
#meta,
|
||||||
#listing {
|
#listing {
|
||||||
color: #cacaca;
|
color: #cacaca;
|
||||||
background: #000000;
|
background: #0d1117;
|
||||||
}
|
}
|
||||||
|
|
||||||
#header nav span a {
|
#header nav span a {
|
||||||
@ -151,7 +154,7 @@
|
|||||||
|
|
||||||
#header {
|
#header {
|
||||||
padding: 1.5rem 5% 1rem;
|
padding: 1.5rem 5% 1rem;
|
||||||
background-color: #0e0e0e;
|
background-color: #161b22;
|
||||||
}
|
}
|
||||||
|
|
||||||
#listing table {
|
#listing table {
|
||||||
@ -219,7 +222,6 @@
|
|||||||
d="M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm220.1-208c-5.7 0-10.6 4-11.7 9.5-20.6 97.7-20.4 95.4-21 103.5-.2-1.2-.4-2.6-.7-4.3-.8-5.1.3.2-23.6-99.5-1.3-5.4-6.1-9.2-11.7-9.2h-13.3c-5.5 0-10.3 3.8-11.7 9.1-24.4 99-24 96.2-24.8 103.7-.1-1.1-.2-2.5-.5-4.2-.7-5.2-14.1-73.3-19.1-99-1.1-5.6-6-9.7-11.8-9.7h-16.8c-7.8 0-13.5 7.3-11.7 14.8 8 32.6 26.7 109.5 33.2 136 1.3 5.4 6.1 9.1 11.7 9.1h25.2c5.5 0 10.3-3.7 11.6-9.1l17.9-71.4c1.5-6.2 2.5-12 3-17.3l2.9 17.3c.1.4 12.6 50.5 17.9 71.4 1.3 5.3 6.1 9.1 11.6 9.1h24.7c5.5 0 10.3-3.7 11.6-9.1 20.8-81.9 30.2-119 34.5-136 1.9-7.6-3.8-14.9-11.6-14.9h-15.8z" />
|
d="M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm220.1-208c-5.7 0-10.6 4-11.7 9.5-20.6 97.7-20.4 95.4-21 103.5-.2-1.2-.4-2.6-.7-4.3-.8-5.1.3.2-23.6-99.5-1.3-5.4-6.1-9.2-11.7-9.2h-13.3c-5.5 0-10.3 3.8-11.7 9.1-24.4 99-24 96.2-24.8 103.7-.1-1.1-.2-2.5-.5-4.2-.7-5.2-14.1-73.3-19.1-99-1.1-5.6-6-9.7-11.8-9.7h-16.8c-7.8 0-13.5 7.3-11.7 14.8 8 32.6 26.7 109.5 33.2 136 1.3 5.4 6.1 9.1 11.7 9.1h25.2c5.5 0 10.3-3.7 11.6-9.1l17.9-71.4c1.5-6.2 2.5-12 3-17.3l2.9 17.3c.1.4 12.6 50.5 17.9 71.4 1.3 5.3 6.1 9.1 11.6 9.1h24.7c5.5 0 10.3-3.7 11.6-9.1 20.8-81.9 30.2-119 34.5-136 1.9-7.6-3.8-14.9-11.6-14.9h-15.8z" />
|
||||||
</defs>
|
</defs>
|
||||||
</svg>
|
</svg>
|
||||||
{% set paths_length = paths | length -%}
|
|
||||||
<header id="header">
|
<header id="header">
|
||||||
<h1>
|
<h1>
|
||||||
<nav>
|
<nav>
|
||||||
@ -228,7 +230,7 @@
|
|||||||
</span>
|
</span>
|
||||||
{% for path in paths -%}
|
{% for path in paths -%}
|
||||||
<span>
|
<span>
|
||||||
<a href="./{% for i in range(end=paths | length - loop.index) %}../{% endfor %}">{{ path }} /
|
<a href="./{% for i in 0..(paths.len() - loop.index) %}../{% endfor %}">{{ path }} /
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
{% endfor -%}
|
{% endfor -%}
|
||||||
@ -237,10 +239,8 @@
|
|||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<div id="meta">
|
<div id="meta">
|
||||||
{% set dir_length = dirs | length -%}
|
<span><b>{{ dirs.len() }}</b> directories</span>
|
||||||
{% set file_length = files | length -%}
|
<span><b>{{ files.len() }}</b> files</span>
|
||||||
<span><b>{{ dir_length }}</b> directories</span>
|
|
||||||
<span><b>{{ file_length }}</b> files</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="listing">
|
<div id="listing">
|
||||||
<table>
|
<table>
|
||||||
@ -298,15 +298,7 @@
|
|||||||
<span>{{ file.name }}</span></a>
|
<span>{{ file.name }}</span></a>
|
||||||
</td>
|
</td>
|
||||||
<td data-order="-1">
|
<td data-order="-1">
|
||||||
{{ file.size | filesizeformat |
|
{{ file.size|filesizeformat }}
|
||||||
replace(from="KB", to="KiB") |
|
|
||||||
replace(from="MB", to="MiB") |
|
|
||||||
replace(from="GB", to="GiB") |
|
|
||||||
replace(from="TB", to="TiB") |
|
|
||||||
replace(from="PB", to="PiB") |
|
|
||||||
replace(from="EB", to="EiB") |
|
|
||||||
replace(from="ZB", to="ZiB") |
|
|
||||||
replace(from="YB", to="YiB") }}
|
|
||||||
</td>
|
</td>
|
||||||
<td class="hideable">
|
<td class="hideable">
|
||||||
<time class="date" datetime="{{ file.modified }}">{{ file.modified }}</time>
|
<time class="date" datetime="{{ file.modified }}">{{ file.modified }}</time>
|
||||||
@ -317,10 +309,30 @@
|
|||||||
<tr></tr>
|
<tr></tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% if dir_length + file_length == 0 -%}
|
{% if dirs.len() + files.len() == 0 -%}
|
||||||
<div style="text-align: center; margin: 1rem; color: #cccccc;">Nothing here</div>
|
<div style="text-align: center; margin: 1rem; color: #cccccc;">Nothing here</div>
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
</div>
|
</div>
|
||||||
|
{% if readme != "".to_string() -%}
|
||||||
|
<div id="readme">
|
||||||
|
{{ readme|safe }}
|
||||||
|
</div>
|
||||||
|
{% include "github-markdown.css.html" %}
|
||||||
|
<style>
|
||||||
|
#readme {
|
||||||
|
min-width: 200px;
|
||||||
|
max-width: 980px;
|
||||||
|
margin: 10px auto;
|
||||||
|
padding: 45px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 767px) {
|
||||||
|
#readme {
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endif -%}
|
||||||
</main>
|
</main>
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
Reference in New Issue
Block a user