26 Commits

Author SHA1 Message Date
d4714cd8f5 Release 1.1.0 2022-11-13 17:27:25 +08:00
91f9993315 update deps 2022-11-13 17:02:39 +08:00
fc809f9bc9 v1.0.5 2022-07-28 15:09:02 +08:00
479f6006a6 update deps 2022-07-28 15:06:33 +08:00
c15c09f07c add readme support 2022-07-28 01:39:51 +08:00
17c6053ed2 Release 1.0.4 2022-07-19 23:06:15 +08:00
4ccea5edf2 remove unused dependencies 2022-07-19 23:02:04 +08:00
8251624981 Replace tera with askama, split the code 2022-07-19 22:58:03 +08:00
46b7c6379f Delete chrono, use time crate instead, update dependencies 2022-07-19 00:42:08 +08:00
39bcd56608 update deps 2022-07-02 11:23:25 +08:00
f82e85aa66 update deps 2022-06-18 12:44:00 +08:00
c98ef43525 Fixed the problem that log cannot be displayed in doc mode 2022-06-07 17:59:04 +08:00
f1921d184d update README 2022-06-07 12:15:36 +08:00
d1d849d93b update deps and reduce binary size 2022-06-07 11:35:06 +08:00
0217f3f1f6 Release 1.0.0 2022-06-07 11:06:42 +08:00
c575147891 update deps 2022-06-07 10:25:45 +08:00
9d81ee2291 Merge pull request #2 from Tim-Paik/dependabot/cargo/regex-1.5.5
Bump regex from 1.5.4 to 1.5.5
2022-06-07 10:10:03 +08:00
d6f7ec2380 Merge pull request #1 from Tim-Paik/dependabot/cargo/crossbeam-utils-0.8.8
Bump crossbeam-utils from 0.8.6 to 0.8.8
2022-06-07 10:08:52 +08:00
b4c980db32 Bump regex from 1.5.4 to 1.5.5
Bumps [regex](https://github.com/rust-lang/regex) from 1.5.4 to 1.5.5.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.5.4...1.5.5)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-06 22:02:34 +00:00
3953820138 Bump crossbeam-utils from 0.8.6 to 0.8.8
Bumps [crossbeam-utils](https://github.com/crossbeam-rs/crossbeam) from 0.8.6 to 0.8.8.
- [Release notes](https://github.com/crossbeam-rs/crossbeam/releases)
- [Changelog](https://github.com/crossbeam-rs/crossbeam/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crossbeam-rs/crossbeam/compare/crossbeam-utils-0.8.6...crossbeam-utils-0.8.8)

---
updated-dependencies:
- dependency-name: crossbeam-utils
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-06 21:10:58 +00:00
92a69aa058 bug fixs 2022-06-06 18:23:20 +08:00
fa3ca96fb7 bug fixs 2022-06-06 14:27:56 +08:00
edc7fad925 add aarch64 support 2022-06-06 13:19:34 +08:00
fd3c93a8d4 add update deps 2022-06-06 13:01:22 +08:00
2c1cdc5720 v1.0.0-rc.8 Update clap to 3.0.0, ready to release 2022-01-02 22:12:19 +08:00
02b6c26874 v1.0.0-rc.7 Update clap dependency, rewrite deprecated code, now has better color output 2021-10-24 21:46:08 +08:00
9 changed files with 1230 additions and 1926 deletions

View File

@ -1,2 +1,5 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"

View File

@ -18,8 +18,12 @@ jobs:
strategy:
matrix:
include:
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
@ -30,6 +34,7 @@ jobs:
- uses: taiki-e/upload-rust-binary-action@v1
with:
bin: srv
archive: $bin-$tag-$target
target: ${{ matrix.target }}
tar: unix
zip: windows

2158
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,27 +3,28 @@ authors = ["Tim_Paik <timpaikc@outlook.com>"]
description = "simple http server written in rust"
edition = "2018"
name = "srv"
version = "1.0.0-rc"
version = "1.1.0"
[dependencies]
actix-files = "0.5"
actix-http = "2.2"
actix-web = {version = "3.3", features = ["rustls"]}
actix-web-httpauth = "0.5"
chrono = "0.4"
clap = {version = "3.0.0-beta.4", features = ["wrap_help", "color"]}
actix-files = "0.6"
actix-web = { version = "4.1", features = ["rustls"] }
actix-web-httpauth = "0.8"
askama = "0.11"
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"
lazy_static = "1.4"
log = "0.4"
mime_guess = "2"
regex = "1.5"
rustls = "0.18"
serde = "1"
sha2 = "0.9"
tera = "1"
mime_guess = "2.0"
rustls = "0.20"
rustls-pemfile = "1.0"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
time = { version = "0.3", features = ["formatting", "parsing"] }
toml = "0.5"
urlencoding = "2.1"
[profile.release]
lto = true
opt-level = "z"
strip = true

View File

@ -7,9 +7,8 @@ This is a simple HTTP Server for use in a development environment, inspired by [
### 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
- [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-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
@ -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.
```shell
wget https://github.com/Tim-Paik/srv/releases/download/v1.0.0-rc.6/srv-x86_64-unknown-linux-musl.tar.gz
tar -xzvf 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-v1.0.1-x86_64-unknown-linux-musl.tar.gz
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
@ -78,7 +77,6 @@ You Need:
git clone git@github.com:Tim-Paik/srv.git
cd srv
cargo build --release
strip target/release/srv
```
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...
## Contributing
All contributions are welcome and I will reply as soon as I see it :)
## License
```text

120
src/filetype.rs Normal file
View 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()
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{# 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
# file, You can obtain one at https://mozilla.org/MPL/2.0/. #}
# 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/. -#}
<!DOCTYPE html>
<html lang="en">
@ -12,9 +12,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark">
<title>{{ title }}</title>
<!--[if lt IE 9
]><script src="https://cdn.jsdelivr.net/npm/html5shiv/dist/html5shiv.min.js"></script
><![endif]-->
<!--[if lt IE 9]><script>
/**
* @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>
html,
body,
@ -142,7 +145,7 @@
#meta,
#listing {
color: #cacaca;
background: #000000;
background: #0d1117;
}
#header nav span a {
@ -151,7 +154,7 @@
#header {
padding: 1.5rem 5% 1rem;
background-color: #0e0e0e;
background-color: #161b22;
}
#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" />
</defs>
</svg>
{% set paths_length = paths | length -%}
<header id="header">
<h1>
<nav>
@ -228,7 +230,7 @@
</span>
{% for path in paths -%}
<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>
</span>
{% endfor -%}
@ -237,10 +239,8 @@
</header>
<main>
<div id="meta">
{% set dir_length = dirs | length -%}
{% set file_length = files | length -%}
<span><b>{{ dir_length }}</b> directories</span>
<span><b>{{ file_length }}</b> files</span>
<span><b>{{ dirs.len() }}</b> directories</span>
<span><b>{{ files.len() }}</b> files</span>
</div>
<div id="listing">
<table>
@ -298,15 +298,7 @@
<span>{{ file.name }}</span></a>
</td>
<td data-order="-1">
{{ 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") }}
{{ file.size|filesizeformat }}
</td>
<td class="hideable">
<time class="date" datetime="{{ file.modified }}">{{ file.modified }}</time>
@ -317,10 +309,30 @@
<tr></tr>
</tbody>
</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>
{% endif -%}
</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>
<script>
(function () {