mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-09 17:13:02 +03:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb1f3cddea | ||
|
|
05dbcfb2df | ||
|
|
76e967fa59 | ||
|
|
140a360e37 | ||
|
|
604cbb7412 | ||
|
|
c6541b1c36 | ||
|
|
b6729a3d64 | ||
|
|
4f1a35de5d | ||
|
|
2ffdcdf106 | ||
|
|
1e0cdafbcf | ||
|
|
0a03941e05 | ||
|
|
07a7322748 |
20
CHANGELOG.md
20
CHANGELOG.md
@@ -2,6 +2,26 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [0.25.0] - 2022-07-06
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- Ui supports creating folder ([#91](https://github.com/sigoden/dufs/issues/91))
|
||||||
|
- Ui supports move folder/file to new path ([#92](https://github.com/sigoden/dufs/issues/92))
|
||||||
|
- Check permission on move/copy destination ([#93](https://github.com/sigoden/dufs/issues/93))
|
||||||
|
- Add completions ([#97](https://github.com/sigoden/dufs/issues/97))
|
||||||
|
- Limit the number of concurrent uploads ([#98](https://github.com/sigoden/dufs/issues/98))
|
||||||
|
|
||||||
|
## [0.24.0] - 2022-07-02
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Unexpect stack overflow when searching a lot ([#87](https://github.com/sigoden/dufs/issues/87))
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- Allow search with --render-try-index ([#88](https://github.com/sigoden/dufs/issues/88))
|
||||||
|
|
||||||
## [0.23.1] - 2022-06-30
|
## [0.23.1] - 2022-06-30
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|||||||
255
Cargo.lock
generated
255
Cargo.lock
generated
@@ -54,52 +54,17 @@ dependencies = [
|
|||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-channel"
|
|
||||||
version = "1.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319"
|
|
||||||
dependencies = [
|
|
||||||
"concurrent-queue",
|
|
||||||
"event-listener",
|
|
||||||
"futures-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-compression"
|
name = "async-compression"
|
||||||
version = "0.3.14"
|
version = "0.3.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "345fd392ab01f746c717b1357165b76f0b67a60192007b234058c9045fdcf695"
|
checksum = "345fd392ab01f746c717b1357165b76f0b67a60192007b234058c9045fdcf695"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bzip2",
|
|
||||||
"flate2",
|
"flate2",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"memchr",
|
"memchr",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tokio",
|
"tokio",
|
||||||
"xz2",
|
|
||||||
"zstd",
|
|
||||||
"zstd-safe",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-fs"
|
|
||||||
version = "1.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8b3ca4f8ff117c37c278a2f7415ce9be55560b846b5bc4412aaa5d29c1c3dae2"
|
|
||||||
dependencies = [
|
|
||||||
"async-lock",
|
|
||||||
"blocking",
|
|
||||||
"futures-lite",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-lock"
|
|
||||||
version = "2.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e97a171d191782fba31bb902b14ad94e24a68145032b7eedf871ab0bc0d077b6"
|
|
||||||
dependencies = [
|
|
||||||
"event-listener",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -123,12 +88,6 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-task"
|
|
||||||
version = "4.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-trait"
|
name = "async-trait"
|
||||||
version = "0.1.56"
|
version = "0.1.56"
|
||||||
@@ -140,28 +99,20 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-walkdir"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "826d88d73e87e7504b635b6e427561faa6a65f4a2f59e75efcbfa51a0876bb90"
|
|
||||||
dependencies = [
|
|
||||||
"async-fs",
|
|
||||||
"futures-lite",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async_io_utilities"
|
name = "async_io_utilities"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
source = "git+https://github.com/Majored/rs-async-io-utilities#1aa191aa5ff651526e0ac08691b1932724350229"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0248112abfeab682c97306bc1e180ee957260107a55a437cedf9a3acca92135e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async_zip"
|
name = "async_zip"
|
||||||
version = "0.0.7"
|
version = "0.0.8"
|
||||||
source = "git+https://github.com/sigoden/rs-async-zip?branch=patch01#3bd0e3ff5151c1fca6eea0de2c4d122eb1ce1f5c"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76c7255e8cf3719aaed04f4cb181f3a79ae53bd45c0aba1866b8969ac888ed80"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-compression",
|
"async-compression",
|
||||||
"async_io_utilities",
|
"async_io_utilities",
|
||||||
@@ -171,12 +122,6 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "atomic-waker"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@@ -228,20 +173,6 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "blocking"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc"
|
|
||||||
dependencies = [
|
|
||||||
"async-channel",
|
|
||||||
"async-task",
|
|
||||||
"atomic-waker",
|
|
||||||
"fastrand",
|
|
||||||
"futures-lite",
|
|
||||||
"once_cell",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bstr"
|
name = "bstr"
|
||||||
version = "0.2.17"
|
version = "0.2.17"
|
||||||
@@ -265,41 +196,11 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
|
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bzip2"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6afcd980b5f3a45017c57e57a2fcccbb351cc43a356ce117ef760ef8052b89b0"
|
|
||||||
dependencies = [
|
|
||||||
"bzip2-sys",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bzip2-sys"
|
|
||||||
version = "0.1.11+1.0.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
"pkg-config",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cache-padded"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.73"
|
version = "1.0.73"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||||
dependencies = [
|
|
||||||
"jobserver",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
@@ -333,6 +234,15 @@ dependencies = [
|
|||||||
"textwrap",
|
"textwrap",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_complete"
|
||||||
|
version = "3.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ead064480dfc4880a10764488415a97fdd36a4cf1bb022d372f02e8faf8386e1"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_lex"
|
name = "clap_lex"
|
||||||
version = "0.2.4"
|
version = "0.2.4"
|
||||||
@@ -342,15 +252,6 @@ dependencies = [
|
|||||||
"os_str_bytes",
|
"os_str_bytes",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "concurrent-queue"
|
|
||||||
version = "1.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3"
|
|
||||||
dependencies = [
|
|
||||||
"cache-padded",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
@@ -397,9 +298,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8"
|
checksum = "5999502d32b9c48d492abe66392408144895020ec4709e549e840799f3bb74c0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"generic-array",
|
"generic-array",
|
||||||
"typenum",
|
"typenum",
|
||||||
@@ -478,16 +379,16 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dufs"
|
name = "dufs"
|
||||||
version = "0.23.1"
|
version = "0.25.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"assert_fs",
|
"assert_fs",
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"async-walkdir",
|
|
||||||
"async_zip",
|
"async_zip",
|
||||||
"base64",
|
"base64",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
"clap_complete",
|
||||||
"diqwest",
|
"diqwest",
|
||||||
"futures",
|
"futures",
|
||||||
"headers",
|
"headers",
|
||||||
@@ -516,6 +417,7 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
"walkdir",
|
||||||
"xml-rs",
|
"xml-rs",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -534,12 +436,6 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "event-listener"
|
|
||||||
version = "2.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "1.7.0"
|
version = "1.7.0"
|
||||||
@@ -657,21 +553,6 @@ version = "0.3.21"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
|
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-lite"
|
|
||||||
version = "1.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48"
|
|
||||||
dependencies = [
|
|
||||||
"fastrand",
|
|
||||||
"futures-core",
|
|
||||||
"futures-io",
|
|
||||||
"memchr",
|
|
||||||
"parking",
|
|
||||||
"pin-project-lite",
|
|
||||||
"waker-fn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-macro"
|
name = "futures-macro"
|
||||||
version = "0.3.21"
|
version = "0.3.21"
|
||||||
@@ -1017,15 +898,6 @@ version = "1.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
|
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jobserver"
|
|
||||||
version = "0.1.24"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.58"
|
version = "0.3.58"
|
||||||
@@ -1066,17 +938,6 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lzma-sys"
|
|
||||||
version = "0.1.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e06754c4acf47d49c727d5665ca9fb828851cda315ed3bd51edd148ef78a8772"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
"pkg-config",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mac"
|
name = "mac"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@@ -1236,9 +1097,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.12.0"
|
version = "1.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
|
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "opaque-debug"
|
name = "opaque-debug"
|
||||||
@@ -1306,12 +1167,6 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "parking"
|
|
||||||
version = "2.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
@@ -1586,9 +1441,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.5.6"
|
version = "1.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1"
|
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -1603,9 +1458,9 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.6.26"
|
version = "0.6.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
|
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "remove_dir_all"
|
name = "remove_dir_all"
|
||||||
@@ -1806,24 +1661,24 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "1.0.11"
|
version = "1.0.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d92beeab217753479be2f74e54187a6aed4c125ff0703a866c3147a02f0c6dd"
|
checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.137"
|
version = "1.0.138"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
|
checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.137"
|
version = "1.0.138"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
|
checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -2188,9 +2043,9 @@ checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-normalization"
|
name = "unicode-normalization"
|
||||||
version = "0.1.20"
|
version = "0.1.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "81dee68f85cab8cf68dec42158baf3a79a1cdc065a8b103025965d6ccb7f6cbd"
|
checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"tinyvec",
|
"tinyvec",
|
||||||
]
|
]
|
||||||
@@ -2256,12 +2111,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "waker-fn"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "walkdir"
|
name = "walkdir"
|
||||||
version = "2.3.2"
|
version = "2.3.2"
|
||||||
@@ -2496,41 +2345,3 @@ dependencies = [
|
|||||||
"markup5ever",
|
"markup5ever",
|
||||||
"time",
|
"time",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "xz2"
|
|
||||||
version = "0.1.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
|
|
||||||
dependencies = [
|
|
||||||
"lzma-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zstd"
|
|
||||||
version = "0.11.2+zstd.1.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4"
|
|
||||||
dependencies = [
|
|
||||||
"zstd-safe",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zstd-safe"
|
|
||||||
version = "5.0.2+zstd.1.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"zstd-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zstd-sys"
|
|
||||||
version = "2.0.1+zstd.1.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9fd07cbbc53846d9145dbffdf6dd09a7a0aa52be46741825f5c97bdd4f73f12b"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dufs"
|
name = "dufs"
|
||||||
version = "0.23.1"
|
version = "0.25.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["sigoden <sigoden@gmail.com>"]
|
authors = ["sigoden <sigoden@gmail.com>"]
|
||||||
description = "Dufs is a distinctive utility file server"
|
description = "Dufs is a distinctive utility file server"
|
||||||
@@ -12,6 +12,7 @@ keywords = ["static", "file", "server", "webdav", "cli"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "3", default-features = false, features = ["std", "wrap_help"] }
|
clap = { version = "3", default-features = false, features = ["std", "wrap_help"] }
|
||||||
|
clap_complete = "3"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "io-util", "signal"]}
|
tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "io-util", "signal"]}
|
||||||
tokio-util = { version = "0.7", features = ["io-util"] }
|
tokio-util = { version = "0.7", features = ["io-util"] }
|
||||||
@@ -21,8 +22,7 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
async_zip = { git = "https://github.com/sigoden/rs-async-zip", branch = "patch01" }
|
async_zip = { version = "0.0.8", default-features = false, features = ["deflate"] }
|
||||||
async-walkdir = "0.2"
|
|
||||||
headers = "0.3"
|
headers = "0.3"
|
||||||
mime_guess = "2.0"
|
mime_guess = "2.0"
|
||||||
if-addrs = "0.7"
|
if-addrs = "0.7"
|
||||||
@@ -37,6 +37,7 @@ xml-rs = "0.8"
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
socket2 = "0.4"
|
socket2 = "0.4"
|
||||||
async-stream = "0.3"
|
async-stream = "0.3"
|
||||||
|
walkdir = "2.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["tls"]
|
default = ["tls"]
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
Dufs is a distinctive utility file server that supports static serving, uploading, searching, accessing control, webdav...
|
Dufs is a distinctive utility file server that supports static serving, uploading, searching, accessing control, webdav...
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -64,6 +64,7 @@ OPTIONS:
|
|||||||
--render-index Serve index.html when requesting a directory, returns 404 if not found index.html
|
--render-index Serve index.html when requesting a directory, returns 404 if not found index.html
|
||||||
--render-try-index Serve index.html when requesting a directory, returns directory listing if not found index.html
|
--render-try-index Serve index.html when requesting a directory, returns directory listing if not found index.html
|
||||||
--render-spa Serve SPA(Single Page Application)
|
--render-spa Serve SPA(Single Page Application)
|
||||||
|
--completions <shell> Print shell completion script for <shell> [possible values: bash, elvish, fish, powershell, zsh]
|
||||||
--tls-cert <path> Path to an SSL/TLS certificate to serve with HTTPS
|
--tls-cert <path> Path to an SSL/TLS certificate to serve with HTTPS
|
||||||
--tls-key <path> Path to the SSL/TLS certificate's private key
|
--tls-key <path> Path to the SSL/TLS certificate's private key
|
||||||
-h, --help Print help information
|
-h, --help Print help information
|
||||||
@@ -78,7 +79,7 @@ Serve current working directory
|
|||||||
dufs
|
dufs
|
||||||
```
|
```
|
||||||
|
|
||||||
Explicitly allow all operations including upload/delete
|
Explicitly allow all operations including download/upload/delete
|
||||||
|
|
||||||
```
|
```
|
||||||
dufs -A
|
dufs -A
|
||||||
@@ -90,13 +91,13 @@ Only allow upload operation
|
|||||||
dufs --allow-upload
|
dufs --allow-upload
|
||||||
```
|
```
|
||||||
|
|
||||||
Serve a directory
|
Serve a specific directory
|
||||||
|
|
||||||
```
|
```
|
||||||
dufs Downloads
|
dufs Downloads
|
||||||
```
|
```
|
||||||
|
|
||||||
Serve a single file
|
Serve a specific file
|
||||||
|
|
||||||
```
|
```
|
||||||
dufs linux-distro.iso
|
dufs linux-distro.iso
|
||||||
@@ -108,7 +109,7 @@ Serve index.html when requesting a directory
|
|||||||
dufs --render-index
|
dufs --render-index
|
||||||
```
|
```
|
||||||
|
|
||||||
Serve SPA(Single Page Application)
|
Serve single-page application like react
|
||||||
|
|
||||||
```
|
```
|
||||||
dufs --render-spa
|
dufs --render-spa
|
||||||
|
|||||||
@@ -59,6 +59,15 @@ body {
|
|||||||
height: 1.1rem;
|
height: 1.1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toolbox .control {
|
||||||
|
cursor: pointer;
|
||||||
|
padding-left: 0.25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-file input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.searchbar {
|
.searchbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: nowrap;
|
flex-wrap: nowrap;
|
||||||
@@ -90,15 +99,6 @@ body {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-control {
|
|
||||||
cursor: pointer;
|
|
||||||
padding-left: 0.25em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.upload-control input {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.upload-status span {
|
.upload-status span {
|
||||||
width: 70px;
|
width: 70px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@@ -132,7 +132,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.paths-table .cell-actions {
|
.paths-table .cell-actions {
|
||||||
width: 60px;
|
width: 75px;
|
||||||
display: flex;
|
display: flex;
|
||||||
padding-left: 0.6em;
|
padding-left: 0.6em;
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.action-btn {
|
.action-btn {
|
||||||
padding-left: 0.4em;
|
padding-right: 0.3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.uploaders-table {
|
.uploaders-table {
|
||||||
|
|||||||
@@ -15,12 +15,18 @@
|
|||||||
<svg width="16" height="16" viewBox="0 0 16 16"><path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/><path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/></svg>
|
<svg width="16" height="16" viewBox="0 0 16 16"><path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/><path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/></svg>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="upload-control hidden" title="Upload files">
|
<div class="control upload-file hidden" title="Upload files">
|
||||||
<label for="file">
|
<label for="file">
|
||||||
<svg width="16" height="16" viewBox="0 0 16 16"><path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/><path d="M7.646 1.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 2.707V11.5a.5.5 0 0 1-1 0V2.707L5.354 4.854a.5.5 0 1 1-.708-.708l3-3z"/></svg>
|
<svg width="16" height="16" viewBox="0 0 16 16"><path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/><path d="M7.646 1.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 2.707V11.5a.5.5 0 0 1-1 0V2.707L5.354 4.854a.5.5 0 1 1-.708-.708l3-3z"/></svg>
|
||||||
</label>
|
</label>
|
||||||
<input type="file" id="file" name="file" multiple>
|
<input type="file" id="file" name="file" multiple>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control new-folder hidden" title="New folder">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 16 16">
|
||||||
|
<path d="m.5 3 .04.87a1.99 1.99 0 0 0-.342 1.311l.637 7A2 2 0 0 0 2.826 14H9v-1H2.826a1 1 0 0 1-.995-.91l-.637-7A1 1 0 0 1 2.19 4h11.62a1 1 0 0 1 .996 1.09L14.54 8h1.005l.256-2.819A2 2 0 0 0 13.81 3H9.828a2 2 0 0 1-1.414-.586l-.828-.828A2 2 0 0 0 6.172 1H2.5a2 2 0 0 0-2 2zm5.672-1a1 1 0 0 1 .707.293L7.586 3H2.19c-.24 0-.47.042-.683.12L1.5 2.98a1 1 0 0 1 1-.98h3.672z"/>
|
||||||
|
<path d="M13.5 10a.5.5 0 0 1 .5.5V12h1.5a.5.5 0 1 1 0 1H14v1.5a.5.5 0 1 1-1 0V13h-1.5a.5.5 0 0 1 0-1H13v-1.5a.5.5 0 0 1 .5-.5z"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form class="searchbar hidden">
|
<form class="searchbar hidden">
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
|
|||||||
127
assets/index.js
127
assets/index.js
@@ -29,6 +29,10 @@ let $uploadersTable;
|
|||||||
* @type Element
|
* @type Element
|
||||||
*/
|
*/
|
||||||
let $emptyFolder;
|
let $emptyFolder;
|
||||||
|
/**
|
||||||
|
* @type Element
|
||||||
|
*/
|
||||||
|
let $newFolder;
|
||||||
|
|
||||||
class Uploader {
|
class Uploader {
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +53,7 @@ class Uploader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
upload() {
|
upload() {
|
||||||
const { file, idx, name } = this;
|
const { idx, name } = this;
|
||||||
const url = getUrl(name);
|
const url = getUrl(name);
|
||||||
const encodedUrl = encodedStr(url);
|
const encodedUrl = encodedStr(url);
|
||||||
const encodedName = encodedStr(name);
|
const encodedName = encodedStr(name);
|
||||||
@@ -66,8 +70,15 @@ class Uploader {
|
|||||||
$uploadersTable.classList.remove("hidden");
|
$uploadersTable.classList.remove("hidden");
|
||||||
$emptyFolder.classList.add("hidden");
|
$emptyFolder.classList.add("hidden");
|
||||||
this.$uploadStatus = document.getElementById(`uploadStatus${idx}`);
|
this.$uploadStatus = document.getElementById(`uploadStatus${idx}`);
|
||||||
this.lastUptime = Date.now();
|
this.$uploadStatus.innerHTML = '-';
|
||||||
|
Uploader.queues.push(this);
|
||||||
|
Uploader.runQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
ajax() {
|
||||||
|
Uploader.runings += 1;
|
||||||
|
const url = getUrl(this.name);
|
||||||
|
this.lastUptime = Date.now();
|
||||||
const ajax = new XMLHttpRequest();
|
const ajax = new XMLHttpRequest();
|
||||||
ajax.upload.addEventListener("progress", e => this.progress(e), false);
|
ajax.upload.addEventListener("progress", e => this.progress(e), false);
|
||||||
ajax.addEventListener("readystatechange", () => {
|
ajax.addEventListener("readystatechange", () => {
|
||||||
@@ -82,13 +93,14 @@ class Uploader {
|
|||||||
ajax.addEventListener("error", () => this.fail(), false);
|
ajax.addEventListener("error", () => this.fail(), false);
|
||||||
ajax.addEventListener("abort", () => this.fail(), false);
|
ajax.addEventListener("abort", () => this.fail(), false);
|
||||||
ajax.open("PUT", url);
|
ajax.open("PUT", url);
|
||||||
ajax.send(file);
|
ajax.send(this.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
progress(event) {
|
progress(event) {
|
||||||
let now = Date.now();
|
const now = Date.now();
|
||||||
let speed = (event.loaded - this.uploaded) / (now - this.lastUptime) * 1000;
|
const speed = (event.loaded - this.uploaded) / (now - this.lastUptime) * 1000;
|
||||||
let [speedValue, speedUnit] = formatSize(speed);
|
const [speedValue, speedUnit] = formatSize(speed);
|
||||||
const speedText = `${speedValue}${speedUnit.toLowerCase()}/s`;
|
const speedText = `${speedValue}${speedUnit.toLowerCase()}/s`;
|
||||||
const progress = formatPercent((event.loaded / event.total) * 100);
|
const progress = formatPercent((event.loaded / event.total) * 100);
|
||||||
const duration = formatDuration((event.total - event.loaded) / speed)
|
const duration = formatDuration((event.total - event.loaded) / speed)
|
||||||
@@ -99,15 +111,34 @@ class Uploader {
|
|||||||
|
|
||||||
complete() {
|
complete() {
|
||||||
this.$uploadStatus.innerHTML = `✓`;
|
this.$uploadStatus.innerHTML = `✓`;
|
||||||
|
Uploader.runings -= 1;
|
||||||
|
Uploader.runQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
this.$uploadStatus.innerHTML = `✗`;
|
this.$uploadStatus.innerHTML = `✗`;
|
||||||
|
Uploader.runings -= 1;
|
||||||
|
Uploader.runQueue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Uploader.globalIdx = 0;
|
Uploader.globalIdx = 0;
|
||||||
|
|
||||||
|
Uploader.runings = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type Uploader[]
|
||||||
|
*/
|
||||||
|
Uploader.queues = [];
|
||||||
|
|
||||||
|
|
||||||
|
Uploader.runQueue = () => {
|
||||||
|
if (Uploader.runings > 2) return;
|
||||||
|
let uploader = Uploader.queues.shift();
|
||||||
|
if (!uploader) return;
|
||||||
|
uploader.ajax();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add breadcrumb
|
* Add breadcrumb
|
||||||
* @param {string} href
|
* @param {string} href
|
||||||
@@ -157,6 +188,7 @@ function addPath(file, index) {
|
|||||||
let encodedUrl = encodedStr(url);
|
let encodedUrl = encodedStr(url);
|
||||||
let actionDelete = "";
|
let actionDelete = "";
|
||||||
let actionDownload = "";
|
let actionDownload = "";
|
||||||
|
let actionMove = "";
|
||||||
if (file.path_type.endsWith("Dir")) {
|
if (file.path_type.endsWith("Dir")) {
|
||||||
url += "/";
|
url += "/";
|
||||||
encodedUrl += "/";
|
encodedUrl += "/";
|
||||||
@@ -175,14 +207,21 @@ function addPath(file, index) {
|
|||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
if (DATA.allow_delete) {
|
if (DATA.allow_delete) {
|
||||||
|
if (DATA.allow_upload) {
|
||||||
|
actionMove = `
|
||||||
|
<div onclick="movePath(${index})" class="action-btn" id="moveBtn${index}" title="Move to new path">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M1.5 1.5A.5.5 0 0 0 1 2v4.8a2.5 2.5 0 0 0 2.5 2.5h9.793l-3.347 3.346a.5.5 0 0 0 .708.708l4.2-4.2a.5.5 0 0 0 0-.708l-4-4a.5.5 0 0 0-.708.708L13.293 8.3H3.5A1.5 1.5 0 0 1 2 6.8V2a.5.5 0 0 0-.5-.5z"/></svg>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
actionDelete = `
|
actionDelete = `
|
||||||
<div onclick="deletePath(${index})" class="action-btn" id="deleteBtn${index}" title="Delete ${encodedName}">
|
<div onclick="deletePath(${index})" class="action-btn" id="deleteBtn${index}" title="Delete">
|
||||||
<svg width="16" height="16" fill="currentColor"viewBox="0 0 16 16"><path d="M6.854 7.146a.5.5 0 1 0-.708.708L7.293 9l-1.147 1.146a.5.5 0 0 0 .708.708L8 9.707l1.146 1.147a.5.5 0 0 0 .708-.708L8.707 9l1.147-1.146a.5.5 0 0 0-.708-.708L8 8.293 6.854 7.146z"/><path d="M14 14V4.5L9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2zM9.5 3A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.5v2z"/></svg>
|
<svg width="16" height="16" fill="currentColor"viewBox="0 0 16 16"><path d="M6.854 7.146a.5.5 0 1 0-.708.708L7.293 9l-1.147 1.146a.5.5 0 0 0 .708.708L8 9.707l1.146 1.147a.5.5 0 0 0 .708-.708L8.707 9l1.147-1.146a.5.5 0 0 0-.708-.708L8 8.293 6.854 7.146z"/><path d="M14 14V4.5L9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2zM9.5 3A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.5v2z"/></svg>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
let actionCell = `
|
let actionCell = `
|
||||||
<td class="cell-actions">
|
<td class="cell-actions">
|
||||||
${actionDownload}
|
${actionDownload}
|
||||||
|
${actionMove}
|
||||||
${actionDelete}
|
${actionDelete}
|
||||||
</td>`
|
</td>`
|
||||||
|
|
||||||
@@ -201,7 +240,7 @@ function addPath(file, index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete pathitem
|
* Delete path
|
||||||
* @param {number} index
|
* @param {number} index
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
@@ -231,6 +270,44 @@ async function deletePath(index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move path
|
||||||
|
* @param {number} index
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async function movePath(index) {
|
||||||
|
const file = DATA.paths[index];
|
||||||
|
if (!file) return;
|
||||||
|
|
||||||
|
const fileUrl = getUrl(file.name);
|
||||||
|
const fileUrlObj = new URL(fileUrl)
|
||||||
|
|
||||||
|
const prefix = DATA.uri_prefix.slice(0, -1);
|
||||||
|
|
||||||
|
const filePath = decodeURIComponent(fileUrlObj.pathname.slice(prefix.length));
|
||||||
|
|
||||||
|
const newPath = prompt("Enter new path", filePath)
|
||||||
|
if (!newPath || filePath === newPath) return;
|
||||||
|
const newFileUrl = fileUrlObj.origin + prefix + encodeURI(newPath);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(getUrl(file.name), {
|
||||||
|
method: "MOVE",
|
||||||
|
headers: {
|
||||||
|
"Destination": newFileUrl,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (res.status >= 200 && res.status < 300) {
|
||||||
|
location.href = newFileUrl.split("/").slice(0, -1).join("/")
|
||||||
|
} else {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
alert(`Cannot move \`${filePath}\` to \`${newPath}\`, ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function dropzone() {
|
function dropzone() {
|
||||||
["drag", "dragstart", "dragend", "dragover", "dragenter", "dragleave", "drop"].forEach(name => {
|
["drag", "dragstart", "dragend", "dragover", "dragenter", "dragleave", "drop"].forEach(name => {
|
||||||
document.addEventListener(name, e => {
|
document.addEventListener(name, e => {
|
||||||
@@ -255,6 +332,24 @@ function dropzone() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a folder
|
||||||
|
* @param {string} name
|
||||||
|
*/
|
||||||
|
async function createFolder(name) {
|
||||||
|
const url = getUrl(name);
|
||||||
|
try {
|
||||||
|
const res = await fetch(url, {
|
||||||
|
method: "MKCOL",
|
||||||
|
});
|
||||||
|
if (res.status >= 200 && res.status < 300) {
|
||||||
|
location.href = url;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
alert(`Cannot create folder \`${name}\`, ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function addFileEntries(entries, dirs) {
|
async function addFileEntries(entries, dirs) {
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
if (entry.isFile) {
|
if (entry.isFile) {
|
||||||
@@ -314,9 +409,9 @@ function formatSize(size) {
|
|||||||
|
|
||||||
function formatDuration(seconds) {
|
function formatDuration(seconds) {
|
||||||
seconds = Math.ceil(seconds);
|
seconds = Math.ceil(seconds);
|
||||||
let h = Math.floor(seconds / 3600);
|
const h = Math.floor(seconds / 3600);
|
||||||
let m = Math.floor((seconds - h * 3600) / 60);
|
const m = Math.floor((seconds - h * 3600) / 60);
|
||||||
let s = seconds - h * 3600 - m * 60
|
const s = seconds - h * 3600 - m * 60
|
||||||
return `${padZero(h, 2)}:${padZero(m, 2)}:${padZero(s, 2)}`;
|
return `${padZero(h, 2)}:${padZero(m, 2)}:${padZero(s, 2)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,6 +435,7 @@ function ready() {
|
|||||||
$pathsTableBody = document.querySelector(".paths-table tbody");
|
$pathsTableBody = document.querySelector(".paths-table tbody");
|
||||||
$uploadersTable = document.querySelector(".uploaders-table");
|
$uploadersTable = document.querySelector(".uploaders-table");
|
||||||
$emptyFolder = document.querySelector(".empty-folder");
|
$emptyFolder = document.querySelector(".empty-folder");
|
||||||
|
$newFolder = document.querySelector(".new-folder");
|
||||||
|
|
||||||
if (DATA.allow_search) {
|
if (DATA.allow_search) {
|
||||||
document.querySelector(".searchbar").classList.remove("hidden");
|
document.querySelector(".searchbar").classList.remove("hidden");
|
||||||
@@ -365,7 +461,14 @@ function ready() {
|
|||||||
}
|
}
|
||||||
if (DATA.allow_upload) {
|
if (DATA.allow_upload) {
|
||||||
dropzone();
|
dropzone();
|
||||||
document.querySelector(".upload-control").classList.remove("hidden");
|
if (DATA.allow_delete) {
|
||||||
|
$newFolder.classList.remove("hidden");
|
||||||
|
$newFolder.addEventListener("click", () => {
|
||||||
|
const name = prompt("Enter name of new folder");
|
||||||
|
if (name) createFolder(name);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
document.querySelector(".upload-file").classList.remove("hidden");
|
||||||
document.getElementById("file").addEventListener("change", e => {
|
document.getElementById("file").addEventListener("change", e => {
|
||||||
const files = e.target.files;
|
const files = e.target.files;
|
||||||
for (let file of files) {
|
for (let file of files) {
|
||||||
|
|||||||
16
src/args.rs
16
src/args.rs
@@ -1,4 +1,5 @@
|
|||||||
use clap::{AppSettings, Arg, ArgMatches, Command};
|
use clap::{value_parser, AppSettings, Arg, ArgMatches, Command};
|
||||||
|
use clap_complete::{generate, Generator, Shell};
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
use rustls::{Certificate, PrivateKey};
|
use rustls::{Certificate, PrivateKey};
|
||||||
use std::env;
|
use std::env;
|
||||||
@@ -11,7 +12,7 @@ use crate::auth::AuthMethod;
|
|||||||
use crate::tls::{load_certs, load_private_key};
|
use crate::tls::{load_certs, load_private_key};
|
||||||
use crate::BoxResult;
|
use crate::BoxResult;
|
||||||
|
|
||||||
fn app() -> Command<'static> {
|
pub fn build_cli() -> Command<'static> {
|
||||||
let app = Command::new(env!("CARGO_CRATE_NAME"))
|
let app = Command::new(env!("CARGO_CRATE_NAME"))
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
.author(env!("CARGO_PKG_AUTHORS"))
|
.author(env!("CARGO_PKG_AUTHORS"))
|
||||||
@@ -118,6 +119,13 @@ fn app() -> Command<'static> {
|
|||||||
Arg::new("render-spa")
|
Arg::new("render-spa")
|
||||||
.long("render-spa")
|
.long("render-spa")
|
||||||
.help("Serve SPA(Single Page Application)"),
|
.help("Serve SPA(Single Page Application)"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("completions")
|
||||||
|
.long("completions")
|
||||||
|
.value_name("shell")
|
||||||
|
.value_parser(value_parser!(Shell))
|
||||||
|
.help("Print shell completion script for <shell>"),
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
@@ -138,8 +146,8 @@ fn app() -> Command<'static> {
|
|||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn matches() -> ArgMatches {
|
pub fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
|
||||||
app().get_matches()
|
generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
24
src/main.rs
24
src/main.rs
@@ -10,14 +10,16 @@ mod utils;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
||||||
use crate::args::{matches, Args};
|
use crate::args::{build_cli, print_completions, Args};
|
||||||
use crate::server::{Request, Server};
|
use crate::server::{Request, Server};
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
use crate::tls::{TlsAcceptor, TlsStream};
|
use crate::tls::{TlsAcceptor, TlsStream};
|
||||||
|
|
||||||
use std::net::{IpAddr, SocketAddr, TcpListener as StdTcpListener};
|
use std::net::{IpAddr, SocketAddr, TcpListener as StdTcpListener};
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use clap_complete::Shell;
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
@@ -36,9 +38,17 @@ async fn main() {
|
|||||||
|
|
||||||
async fn run() -> BoxResult<()> {
|
async fn run() -> BoxResult<()> {
|
||||||
logger::init().map_err(|e| format!("Failed to init logger, {}", e))?;
|
logger::init().map_err(|e| format!("Failed to init logger, {}", e))?;
|
||||||
let args = Args::parse(matches())?;
|
let cmd = build_cli();
|
||||||
|
let matches = cmd.get_matches();
|
||||||
|
if let Some(generator) = matches.get_one::<Shell>("completions") {
|
||||||
|
let mut cmd = build_cli();
|
||||||
|
print_completions(*generator, &mut cmd);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let args = Args::parse(matches)?;
|
||||||
let args = Arc::new(args);
|
let args = Arc::new(args);
|
||||||
let handles = serve(args.clone())?;
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
|
let handles = serve(args.clone(), running.clone())?;
|
||||||
print_listening(args)?;
|
print_listening(args)?;
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
@@ -51,13 +61,17 @@ async fn run() -> BoxResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
_ = shutdown_signal() => {
|
_ = shutdown_signal() => {
|
||||||
|
running.store(false, Ordering::SeqCst);
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serve(args: Arc<Args>) -> BoxResult<Vec<JoinHandle<Result<(), hyper::Error>>>> {
|
fn serve(
|
||||||
let inner = Arc::new(Server::new(args.clone()));
|
args: Arc<Args>,
|
||||||
|
running: Arc<AtomicBool>,
|
||||||
|
) -> BoxResult<Vec<JoinHandle<Result<(), hyper::Error>>>> {
|
||||||
|
let inner = Arc::new(Server::new(args.clone(), running));
|
||||||
let mut handles = vec![];
|
let mut handles = vec![];
|
||||||
let port = args.port;
|
let port = args.port;
|
||||||
for ip in args.addrs.iter() {
|
for ip in args.addrs.iter() {
|
||||||
|
|||||||
206
src/server.rs
206
src/server.rs
@@ -1,13 +1,12 @@
|
|||||||
use crate::streamer::Streamer;
|
use crate::streamer::Streamer;
|
||||||
use crate::utils::{decode_uri, encode_uri, get_file_name, try_get_file_name};
|
use crate::utils::{decode_uri, encode_uri, get_file_name, try_get_file_name};
|
||||||
use crate::{Args, BoxResult};
|
use crate::{Args, BoxResult};
|
||||||
use async_walkdir::{Filtering, WalkDir};
|
use walkdir::WalkDir;
|
||||||
use xml::escape::escape_str_pcdata;
|
use xml::escape::escape_str_pcdata;
|
||||||
|
|
||||||
use async_zip::write::{EntryOptions, ZipFileWriter};
|
use async_zip::write::{EntryOptions, ZipFileWriter};
|
||||||
use async_zip::Compression;
|
use async_zip::Compression;
|
||||||
use chrono::{TimeZone, Utc};
|
use chrono::{TimeZone, Utc};
|
||||||
use futures::stream::StreamExt;
|
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use headers::{
|
use headers::{
|
||||||
AcceptRanges, AccessControlAllowCredentials, AccessControlAllowHeaders,
|
AcceptRanges, AccessControlAllowCredentials, AccessControlAllowHeaders,
|
||||||
@@ -24,6 +23,7 @@ use std::fs::Metadata;
|
|||||||
use std::io::SeekFrom;
|
use std::io::SeekFrom;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
@@ -45,13 +45,15 @@ const BUF_SIZE: usize = 65536;
|
|||||||
pub struct Server {
|
pub struct Server {
|
||||||
args: Arc<Args>,
|
args: Arc<Args>,
|
||||||
assets_prefix: String,
|
assets_prefix: String,
|
||||||
|
running: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
pub fn new(args: Arc<Args>) -> Self {
|
pub fn new(args: Arc<Args>, running: Arc<AtomicBool>) -> Self {
|
||||||
let assets_prefix = format!("{}__dufs_v{}_", args.uri_prefix, env!("CARGO_PKG_VERSION"));
|
let assets_prefix = format!("{}__dufs_v{}_", args.uri_prefix, env!("CARGO_PKG_VERSION"));
|
||||||
Self {
|
Self {
|
||||||
args,
|
args,
|
||||||
|
running,
|
||||||
assets_prefix,
|
assets_prefix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,9 +155,18 @@ impl Server {
|
|||||||
match method {
|
match method {
|
||||||
Method::GET | Method::HEAD => {
|
Method::GET | Method::HEAD => {
|
||||||
if is_dir {
|
if is_dir {
|
||||||
if render_try_index && query == "zip" {
|
if render_try_index {
|
||||||
self.handle_zip_dir(path, head_only, &mut res).await?;
|
if query == "zip" {
|
||||||
} else if render_index || render_spa || render_try_index {
|
self.handle_zip_dir(path, head_only, &mut res).await?;
|
||||||
|
} else if allow_search && query.starts_with("q=") {
|
||||||
|
let q = decode_uri(&query[2..]).unwrap_or_default();
|
||||||
|
self.handle_search_dir(path, &q, head_only, &mut res)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
|
self.handle_render_index(path, headers, head_only, &mut res)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
} else if render_index || render_spa {
|
||||||
self.handle_render_index(path, headers, head_only, &mut res)
|
self.handle_render_index(path, headers, head_only, &mut res)
|
||||||
.await?;
|
.await?;
|
||||||
} else if query == "zip" {
|
} else if query == "zip" {
|
||||||
@@ -228,7 +239,7 @@ impl Server {
|
|||||||
} else if is_miss {
|
} else if is_miss {
|
||||||
status_not_found(&mut res);
|
status_not_found(&mut res);
|
||||||
} else {
|
} else {
|
||||||
self.handle_copy(path, headers, &mut res).await?
|
self.handle_copy(path, &req, &mut res).await?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"MOVE" => {
|
"MOVE" => {
|
||||||
@@ -237,7 +248,7 @@ impl Server {
|
|||||||
} else if is_miss {
|
} else if is_miss {
|
||||||
status_not_found(&mut res);
|
status_not_found(&mut res);
|
||||||
} else {
|
} else {
|
||||||
self.handle_move(path, headers, &mut res).await?
|
self.handle_move(path, &req, &mut res).await?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"LOCK" => {
|
"LOCK" => {
|
||||||
@@ -331,34 +342,40 @@ impl Server {
|
|||||||
res: &mut Response,
|
res: &mut Response,
|
||||||
) -> BoxResult<()> {
|
) -> BoxResult<()> {
|
||||||
let mut paths: Vec<PathItem> = vec![];
|
let mut paths: Vec<PathItem> = vec![];
|
||||||
|
let path_buf = path.to_path_buf();
|
||||||
let hidden = self.args.hidden.to_string();
|
let hidden = self.args.hidden.to_string();
|
||||||
let search = search.to_string();
|
let running = self.running.clone();
|
||||||
let mut walkdir = WalkDir::new(path).filter(move |entry| {
|
let search = search.to_lowercase();
|
||||||
let hidden_cloned = hidden.clone();
|
let search_paths = tokio::task::spawn_blocking(move || {
|
||||||
let search_cloned = search.clone();
|
let mut it = WalkDir::new(&path_buf).into_iter();
|
||||||
async move {
|
let mut paths: Vec<PathBuf> = vec![];
|
||||||
|
while let Some(Ok(entry)) = it.next() {
|
||||||
|
if !running.load(Ordering::SeqCst) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let entry_path = entry.path();
|
let entry_path = entry.path();
|
||||||
let base_name = get_file_name(&entry_path);
|
let base_name = get_file_name(entry_path);
|
||||||
if is_hidden(&hidden_cloned, base_name) {
|
let file_type = entry.file_type();
|
||||||
return Filtering::IgnoreDir;
|
if is_hidden(&hidden, base_name) {
|
||||||
|
if file_type.is_dir() {
|
||||||
|
it.skip_current_dir();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if !base_name
|
if !base_name.to_lowercase().contains(&search) {
|
||||||
.to_lowercase()
|
continue;
|
||||||
.contains(&search_cloned.to_lowercase())
|
|
||||||
{
|
|
||||||
return Filtering::Ignore;
|
|
||||||
}
|
}
|
||||||
if fs::symlink_metadata(entry.path()).await.is_err() {
|
if entry.path().symlink_metadata().is_err() {
|
||||||
return Filtering::Ignore;
|
continue;
|
||||||
}
|
}
|
||||||
Filtering::Continue
|
paths.push(entry_path.to_path_buf());
|
||||||
}
|
}
|
||||||
});
|
paths
|
||||||
while let Some(entry) = walkdir.next().await {
|
})
|
||||||
if let Ok(entry) = entry {
|
.await?;
|
||||||
if let Ok(Some(item)) = self.to_pathitem(entry.path(), path.to_path_buf()).await {
|
for search_path in search_paths.into_iter() {
|
||||||
paths.push(item);
|
if let Ok(Some(item)) = self.to_pathitem(search_path, path.to_path_buf()).await {
|
||||||
}
|
paths.push(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.send_index(path, paths, true, head_only, res)
|
self.send_index(path, paths, true, head_only, res)
|
||||||
@@ -387,8 +404,9 @@ impl Server {
|
|||||||
}
|
}
|
||||||
let path = path.to_owned();
|
let path = path.to_owned();
|
||||||
let hidden = self.args.hidden.clone();
|
let hidden = self.args.hidden.clone();
|
||||||
|
let running = self.running.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Err(e) = zip_dir(&mut writer, &path, &hidden).await {
|
if let Err(e) = zip_dir(&mut writer, &path, &hidden, running).await {
|
||||||
error!("Failed to zip {}, {}", path.display(), e);
|
error!("Failed to zip {}, {}", path.display(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -625,16 +643,10 @@ impl Server {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_copy(
|
async fn handle_copy(&self, path: &Path, req: &Request, res: &mut Response) -> BoxResult<()> {
|
||||||
&self,
|
let dest = match self.extract_dest(req, res) {
|
||||||
path: &Path,
|
|
||||||
headers: &HeaderMap<HeaderValue>,
|
|
||||||
res: &mut Response,
|
|
||||||
) -> BoxResult<()> {
|
|
||||||
let dest = match self.extract_dest(headers) {
|
|
||||||
Some(dest) => dest,
|
Some(dest) => dest,
|
||||||
None => {
|
None => {
|
||||||
*res.status_mut() = StatusCode::BAD_REQUEST;
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -653,16 +665,10 @@ impl Server {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_move(
|
async fn handle_move(&self, path: &Path, req: &Request, res: &mut Response) -> BoxResult<()> {
|
||||||
&self,
|
let dest = match self.extract_dest(req, res) {
|
||||||
path: &Path,
|
|
||||||
headers: &HeaderMap<HeaderValue>,
|
|
||||||
res: &mut Response,
|
|
||||||
) -> BoxResult<()> {
|
|
||||||
let dest = match self.extract_dest(headers) {
|
|
||||||
Some(dest) => dest,
|
Some(dest) => dest,
|
||||||
None => {
|
None => {
|
||||||
*res.status_mut() = StatusCode::BAD_REQUEST;
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -781,10 +787,43 @@ DATA = {}
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_dest(&self, headers: &HeaderMap<HeaderValue>) -> Option<PathBuf> {
|
fn extract_dest(&self, req: &Request, res: &mut Response) -> Option<PathBuf> {
|
||||||
|
let headers = req.headers();
|
||||||
|
let dest_path = match self.extract_destination_header(headers) {
|
||||||
|
Some(dest) => dest,
|
||||||
|
None => {
|
||||||
|
*res.status_mut() = StatusCode::BAD_REQUEST;
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let authorization = headers.get(AUTHORIZATION);
|
||||||
|
let guard_type = self.args.auth.guard(
|
||||||
|
&dest_path,
|
||||||
|
req.method(),
|
||||||
|
authorization,
|
||||||
|
self.args.auth_method.clone(),
|
||||||
|
);
|
||||||
|
if guard_type.is_reject() {
|
||||||
|
*res.status_mut() = StatusCode::FORBIDDEN;
|
||||||
|
*res.body_mut() = Body::from("Forbidden");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let dest = match self.extract_path(&dest_path) {
|
||||||
|
Some(dest) => dest,
|
||||||
|
None => {
|
||||||
|
*res.status_mut() = StatusCode::BAD_REQUEST;
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(dest)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_destination_header(&self, headers: &HeaderMap<HeaderValue>) -> Option<String> {
|
||||||
let dest = headers.get("Destination")?.to_str().ok()?;
|
let dest = headers.get("Destination")?.to_str().ok()?;
|
||||||
let uri: Uri = dest.parse().ok()?;
|
let uri: Uri = dest.parse().ok()?;
|
||||||
self.extract_path(uri.path())
|
Some(uri.path().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_path(&self, path: &str) -> Option<PathBuf> {
|
fn extract_path(&self, path: &str) -> Option<PathBuf> {
|
||||||
@@ -992,41 +1031,54 @@ fn res_multistatus(res: &mut Response, content: &str) {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn zip_dir<W: AsyncWrite + Unpin>(writer: &mut W, dir: &Path, hidden: &str) -> BoxResult<()> {
|
async fn zip_dir<W: AsyncWrite + Unpin>(
|
||||||
|
writer: &mut W,
|
||||||
|
dir: &Path,
|
||||||
|
hidden: &str,
|
||||||
|
running: Arc<AtomicBool>,
|
||||||
|
) -> BoxResult<()> {
|
||||||
let mut writer = ZipFileWriter::new(writer);
|
let mut writer = ZipFileWriter::new(writer);
|
||||||
|
let hidden = Arc::new(hidden.to_string());
|
||||||
let hidden = hidden.to_string();
|
let hidden = hidden.to_string();
|
||||||
let mut walkdir = WalkDir::new(dir).filter(move |entry| {
|
let dir_path_buf = dir.to_path_buf();
|
||||||
let hidden = hidden.clone();
|
let zip_paths = tokio::task::spawn_blocking(move || {
|
||||||
async move {
|
let mut it = WalkDir::new(&dir_path_buf).into_iter();
|
||||||
|
let mut paths: Vec<PathBuf> = vec![];
|
||||||
|
while let Some(Ok(entry)) = it.next() {
|
||||||
|
if !running.load(Ordering::SeqCst) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let entry_path = entry.path();
|
let entry_path = entry.path();
|
||||||
let base_name = get_file_name(&entry_path);
|
let base_name = get_file_name(entry_path);
|
||||||
|
let file_type = entry.file_type();
|
||||||
if is_hidden(&hidden, base_name) {
|
if is_hidden(&hidden, base_name) {
|
||||||
return Filtering::IgnoreDir;
|
if file_type.is_dir() {
|
||||||
|
it.skip_current_dir();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
let meta = match fs::symlink_metadata(entry.path()).await {
|
if entry.path().symlink_metadata().is_err() {
|
||||||
Ok(meta) => meta,
|
continue;
|
||||||
Err(_) => return Filtering::Ignore,
|
|
||||||
};
|
|
||||||
if !meta.is_file() {
|
|
||||||
return Filtering::Ignore;
|
|
||||||
}
|
}
|
||||||
Filtering::Continue
|
if !file_type.is_file() {
|
||||||
}
|
continue;
|
||||||
});
|
}
|
||||||
while let Some(entry) = walkdir.next().await {
|
paths.push(entry_path.to_path_buf());
|
||||||
if let Ok(entry) = entry {
|
|
||||||
let entry_path = entry.path();
|
|
||||||
let filename = match entry_path.strip_prefix(dir).ok().and_then(|v| v.to_str()) {
|
|
||||||
Some(v) => v,
|
|
||||||
None => continue,
|
|
||||||
};
|
|
||||||
let entry_options = EntryOptions::new(filename.to_owned(), Compression::Deflate)
|
|
||||||
.unix_permissions(0o644);
|
|
||||||
let mut file = File::open(&entry_path).await?;
|
|
||||||
let mut file_writer = writer.write_entry_stream(entry_options).await?;
|
|
||||||
io::copy(&mut file, &mut file_writer).await?;
|
|
||||||
file_writer.close().await?;
|
|
||||||
}
|
}
|
||||||
|
paths
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
for zip_path in zip_paths.into_iter() {
|
||||||
|
let filename = match zip_path.strip_prefix(dir).ok().and_then(|v| v.to_str()) {
|
||||||
|
Some(v) => v,
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
let entry_options =
|
||||||
|
EntryOptions::new(filename.to_owned(), Compression::Deflate).unix_permissions(0o644);
|
||||||
|
let mut file = File::open(&zip_path).await?;
|
||||||
|
let mut file_writer = writer.write_entry_stream(entry_options).await?;
|
||||||
|
io::copy(&mut file, &mut file_writer).await?;
|
||||||
|
file_writer.close().await?;
|
||||||
}
|
}
|
||||||
writer.close().await?;
|
writer.close().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//! Run file server with different args
|
||||||
|
|
||||||
mod fixtures;
|
mod fixtures;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
|||||||
@@ -95,3 +95,29 @@ fn auth_basic(
|
|||||||
assert_eq!(resp.status(), 201);
|
assert_eq!(resp.status(), 201);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
fn auth_webdav_move(
|
||||||
|
#[with(&["--auth", "/@user:pass@*", "--auth", "/dira@user3:pass3", "-A"])] server: TestServer,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let origin_url = format!("{}dira/test.html", server.url());
|
||||||
|
let new_url = format!("{}test2.html", server.url());
|
||||||
|
let resp = fetch!(b"MOVE", &origin_url)
|
||||||
|
.header("Destination", &new_url)
|
||||||
|
.send_with_digest_auth("user3", "pass3")?;
|
||||||
|
assert_eq!(resp.status(), 403);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
fn auth_webdav_copy(
|
||||||
|
#[with(&["--auth", "/@user:pass@*", "--auth", "/dira@user3:pass3", "-A"])] server: TestServer,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let origin_url = format!("{}dira/test.html", server.url());
|
||||||
|
let new_url = format!("{}test2.html", server.url());
|
||||||
|
let resp = fetch!(b"COPY", &origin_url)
|
||||||
|
.header("Destination", &new_url)
|
||||||
|
.send_with_digest_auth("user3", "pass3")?;
|
||||||
|
assert_eq!(resp.status(), 403);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
32
tests/cli.rs
Normal file
32
tests/cli.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
//! Run cli with different args, not starting a server
|
||||||
|
|
||||||
|
mod fixtures;
|
||||||
|
|
||||||
|
use assert_cmd::prelude::*;
|
||||||
|
use clap::ValueEnum;
|
||||||
|
use clap_complete::Shell;
|
||||||
|
use fixtures::Error;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
/// Show help and exit.
|
||||||
|
fn help_shows() -> Result<(), Error> {
|
||||||
|
Command::cargo_bin("dufs")?.arg("-h").assert().success();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
/// Print completions and exit.
|
||||||
|
fn print_completions() -> Result<(), Error> {
|
||||||
|
// let shell_enums = EnumValueParser::<Shell>::new();
|
||||||
|
for shell in Shell::value_variants() {
|
||||||
|
Command::cargo_bin("dufs")?
|
||||||
|
.arg("--completions")
|
||||||
|
.arg(shell.to_string())
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -50,6 +50,18 @@ fn render_try_index3(#[with(&["--render-try-index"])] server: TestServer) -> Res
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[case(server(&["--render-try-index"] as &[&str]), false)]
|
||||||
|
#[case(server(&["--render-try-index", "--allow-search"] as &[&str]), true)]
|
||||||
|
fn render_try_index4(#[case] server: TestServer, #[case] searched: bool) -> Result<(), Error> {
|
||||||
|
let resp = reqwest::blocking::get(format!("{}{}?q={}", server.url(), DIR_NO_INDEX, "😀.bin"))?;
|
||||||
|
assert_eq!(resp.status(), 200);
|
||||||
|
let paths = utils::retrive_index_paths(&resp.text()?);
|
||||||
|
assert!(!paths.is_empty());
|
||||||
|
assert_eq!(paths.iter().all(|v| v.contains("😀.bin")), searched);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn render_spa(#[with(&["--render-spa"])] server: TestServer) -> Result<(), Error> {
|
fn render_spa(#[with(&["--render-spa"])] server: TestServer) -> Result<(), Error> {
|
||||||
let resp = reqwest::blocking::get(server.url())?;
|
let resp = reqwest::blocking::get(server.url())?;
|
||||||
|
|||||||
Reference in New Issue
Block a user