diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cc3031d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,40 @@ +name: Publish CD + +on: + push: + tags: + - '*' + workflow_dispatch: + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + + - name: Install stable toolchain 💿 + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - run: sudo apt-get -y update && sudo apt-get -y install libpcap-dev + + - uses: actions/setup-node@v3 + with: + node-version: 18 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - name: Install dependencies and build + run: | + pnpm -C view install + pnpm -C view build + + - name: Publish to crate 🎉 + run: cargo publish -p serverbee-web --token ${CRATES_TOKEN} + env: + CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cd6290..8f51c96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ ## `2.0.0` (2023-09-07) ### Features +#### Web - Dashboard for web - Config for web - Data report +#### Deploy +- i18n +- Option of download Pre-release + ### Refactor - Refactor the config struct - Refactor the local api diff --git a/Cargo.lock b/Cargo.lock index 9d90f9a..5537038 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -293,9 +293,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "0f2135563fb5c609d2b2b87c1e8ce7bc41b0b45430fa9661f457981503dd5bf0" dependencies = [ "memchr", ] @@ -324,6 +324,15 @@ dependencies = [ "libc", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anyhow" version = "1.0.68" @@ -353,6 +362,17 @@ dependencies = [ "syn 2.0.22", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "auto-launch" version = "0.4.0" @@ -452,6 +472,16 @@ dependencies = [ "alloc-stdlib", ] +[[package]] +name = "bstr" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c2f7349907b712260e64b0afe2f84692af14a454be26187d9df565c7f69266a" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "bumpalo" version = "3.11.1" @@ -536,6 +566,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim 0.8.0", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "clap" version = "4.0.32" @@ -547,7 +592,7 @@ dependencies = [ "clap_lex", "is-terminal", "once_cell", - "strsim", + "strsim 0.10.0", "termcolor", ] @@ -593,7 +638,7 @@ dependencies = [ "lazy_static", "libc", "unicode-width", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -856,6 +901,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.2.8" @@ -1073,6 +1124,36 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "globset" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + +[[package]] +name = "globwalk" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" +dependencies = [ + "bitflags", + "ignore", + "walkdir", +] + [[package]] name = "h2" version = "0.3.17" @@ -1085,7 +1166,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 1.9.2", "slab", "tokio", "tokio-util", @@ -1098,12 +1179,27 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" + [[package]] name = "heck" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.2.6" @@ -1243,6 +1339,23 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "ignore" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +dependencies = [ + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + [[package]] name = "indexmap" version = "1.9.2" @@ -1250,7 +1363,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown 0.14.0", ] [[package]] @@ -1297,7 +1420,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1312,10 +1435,19 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ - "hermit-abi", + "hermit-abi 0.2.6", "io-lifetimes", "rustix", - "windows-sys", + "windows-sys 0.42.0", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", ] [[package]] @@ -1454,9 +1586,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" [[package]] name = "memoffset" @@ -1507,7 +1639,7 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1547,6 +1679,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "normpath" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec60c60a693226186f5d6edf073232bfb6464ed97eb22cf3b01c1e8198fd97f5" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "ntapi" version = "0.4.0" @@ -1581,7 +1722,7 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi", + "hermit-abi 0.2.6", "libc", ] @@ -1702,7 +1843,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1878,9 +2019,21 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" dependencies = [ "aho-corasick", "memchr", @@ -1889,9 +2042,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "remove_dir_all" @@ -1994,6 +2147,81 @@ dependencies = [ "walkdir", ] +[[package]] +name = "rust-i18n" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "722f8b8849ad30f25c77c2b5822d3d13b6bde236b94c2187fc8ab4fb90d1efe6" +dependencies = [ + "anyhow", + "clap 2.34.0", + "globwalk", + "itertools", + "once_cell", + "quote", + "regex", + "rust-i18n-extract", + "rust-i18n-macro", + "rust-i18n-support", + "serde", + "serde_derive", + "toml", +] + +[[package]] +name = "rust-i18n-extract" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86c874262b7b84b4b8e2eb46a3a4ae3b2365ac3d136a431797283d7776261b7a" +dependencies = [ + "anyhow", + "ignore", + "proc-macro2", + "quote", + "regex", + "rust-i18n-support", + "serde", + "serde_json", + "serde_yaml 0.8.26", + "syn 2.0.22", + "toml", +] + +[[package]] +name = "rust-i18n-macro" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612fa73a13dd7b6d3bd76f564d9632195c3e6a2fd3b52ba9fc99b1800d16f18f" +dependencies = [ + "glob", + "once_cell", + "proc-macro2", + "quote", + "rust-i18n-support", + "serde", + "serde_json", + "serde_yaml 0.8.26", + "syn 2.0.22", +] + +[[package]] +name = "rust-i18n-support" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1f0c8ae29b0544e1f4e16e9e7f7db25a695c8bd64e4bc2f56be2b0ce12734ec" +dependencies = [ + "globwalk", + "lazy_static", + "normpath", + "once_cell", + "proc-macro2", + "regex", + "serde", + "serde_json", + "serde_yaml 0.8.26", + "toml", +] + [[package]] name = "rustc_version" version = "0.4.0" @@ -2014,7 +2242,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2059,7 +2287,7 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2154,6 +2382,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -2172,7 +2409,7 @@ version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" dependencies = [ - "indexmap", + "indexmap 1.9.2", "ryu", "serde", "yaml-rust", @@ -2184,7 +2421,7 @@ version = "0.9.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92b5b431e8907b50339b51223b97d102db8d987ced36f6e4d03621db9316c834" dependencies = [ - "indexmap", + "indexmap 1.9.2", "itoa", "ryu", "serde", @@ -2197,7 +2434,7 @@ version = "2.0.0" dependencies = [ "anyhow", "auto-launch", - "clap", + "clap 4.0.32", "futures-util", "indicatif", "inquire", @@ -2206,6 +2443,7 @@ dependencies = [ "port-killer", "port-selector", "reqwest", + "rust-i18n", "serde", "serde_json", "serde_yaml 0.9.16", @@ -2227,7 +2465,7 @@ dependencies = [ "async-trait", "awc", "bytestring", - "clap", + "clap 4.0.32", "ezsockets", "futures-util", "log", @@ -2346,6 +2584,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "strsim" version = "0.10.0" @@ -2426,6 +2670,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.38" @@ -2457,6 +2710,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "time" version = "0.1.45" @@ -2527,7 +2790,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2603,6 +2866,40 @@ dependencies = [ "tracing", ] +[[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.0.0", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower-service" version = "0.3.2" @@ -2770,6 +3067,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.4" @@ -2940,13 +3243,37 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.0", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm 0.42.0", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -2955,42 +3282,93 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_x86_64_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.10.1" diff --git a/README.md b/README.md index d1d7d70..1a4a0c5 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,13 @@ unzip serverbee-deploy-x86_64-unknown-linux-musl.zip 3. double-click to run serverbee-deploy.exe ## More settings +### Allow downloading of pre-release versions +> By default, only stable versions will be downloaded +> +> If you want to download pre-release versions, you can use the --pre-release parameter +```bash +./serverbee-deploy --pre-release +``` ### Interactive install ```bash diff --git a/README.zh-CN.md b/README.zh-CN.md index 8b79772..5b3ce8f 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -92,6 +92,13 @@ unzip serverbee-deploy-x86_64-unknown-linux-musl.zip 3. 双击启动 serverbee-deploy.exe ## 更多配置 +### 允许下载预发布版本 +> 默认情况下,只会下载稳定版本 +> +> 如果你想下载预发布版本,可以使用 `--pre-release` 参数 +```bash +./serverbee-deploy --pre-release +``` ### 交互式安装 ```bash diff --git a/deploy/Cargo.toml b/deploy/Cargo.toml index 42183d9..21e1a79 100644 --- a/deploy/Cargo.toml +++ b/deploy/Cargo.toml @@ -33,3 +33,5 @@ serde_json = "1.0" serde_yaml = "0.9.4" reqwest = { version = "0.11", features = ["json", "stream"], default-features = false } + +rust-i18n = "2" diff --git a/deploy/locales/app.yml b/deploy/locales/app.yml new file mode 100644 index 0000000..86c9483 --- /dev/null +++ b/deploy/locales/app.yml @@ -0,0 +1,109 @@ +_version: 2 +hello: + en: Hello world + zh: 你好世界 +messages.hello: + en: Hello, %{name} + zh: 你好,%{name} +latest_version: + en: Latest Version + zh: 最新版本 +port_question: + en: Please input port? (default 9527) + zh: 请输入端口号? (默认使用 9527) +install_confirm: + en: Press any key to continue the installation, to cancel the installation enter Ctrl+C + zh: 按任意键以继续安装, 取消安装请输入 Ctrl+C +start_install: + en: Confirmation complete, starting installation. + zh: 确认完毕, 开始安装 +auto_launch: + en: Auto-start on boot + zh: 开机自启 +port: + en: Port + zh: 端口号 +confirm_config: + en: Please confirm the following settings + zh: 请确认如下设置 +error_and_retry: + en: An error occurred, please retry + zh: 出现错误,请重试 +port_in_use: + en: Port %{port} is in use, please change port + zh: 端口 %{port} 已被占用,请更换端口 +port_invalid: + en: Port is invalid + zh: 端口号输入有误 +full_path: + en: Full file path + zh: 文件全路径 +download_and_unzip: + en: File %{path} downloaded successfully, unpacking now + zh: 文件 %{path} 下载成功, 正在解压 +unzip_success: + en: File unpacking completed + zh: 文件解压完毕 +skip_download: + en: File already exists, skipping download + zh: 文件已存在, 跳过下载 +install_finish: + en: Installation completed, press any key to exit... + zh: 安装结束, 按任意键退出... +yes: + en: Yes + zh: 是 +no: + en: No + zh: 否 +launch_question: + en: Do you want to auto-start on boot? + zh: 是否开机自启? +action_tips: + en: ↑↓ Move, Enter Confirm ✅, Input to filter + zh: ↑↓ 移动, 回车确定 ✅, 输入以筛选 +run_success: + en: serverbee-web started successfully + zh: serverbee-web 启动成功 +run_fail: + en: Running %{path} failed, please try to run manually + zh: 运行 %{path} 失败, 请尝试手动运行 +file_extracted: + en: 'File extracted to: %{path}' + zh: '文件解压到: %{path}' +file_extracted_with_size: + en: 'File extracted to: %{path} (%{size} bytes)' + zh: '文件解压到: %{path} (%{size} 字节)' +locale_question: + en: Please select language + zh: 请选择语言 +auto_launch_tips: + en: After installation is complete, please execute the following command to enable auto-start on boot + zh: 安装完成后, 请执行以下命令以开启开机自启 +deploy_full_path: + en: Replace with the full path of serverbee-deploy + zh: 替换为 serverbee-deploy 的全路径 +auto_launch_file_path: + en: Auto-start executable file + zh: 自启执行文件 +cancel_auto_launch: + en: Auto-start has been cancelled + zh: 已取消开机启动 +already_auto_launch: + en: Auto-start item already exists, no need to set again + zh: 开机启动项已存在, 无需重复设置 +failed_to_get_current_dir: + en: Failed to get the current directory, insufficient permissions, or not unpacked + zh: 获取当前目录失败, 权限不足或未解压 +failed_to_get_version_from_status: + en: 'Failed to get the latest version from status: %{error}, trying to get from github' + zh: '从 status 获取最新版本失败: %{error}, 尝试从 github 获取' +failed_to_get_version_from_github: + en: 'Failed to get the latest version from github: %{error}, trying to get from jsdelivr' + zh: '从 github 获取最新版本失败: %{error}, 尝试从 jsdelivr 获取' +failed_to_get_version_from_jsdelivr: + en: Failed to get the latest version from jsdelivr, the version in cargo.toml will be used + zh: 从 jsdelivr 获取最新版本失败, 将使用 cargo.toml 中的版本 +use_version_from_cargo_toml: + en: Using version from cargo.toml + zh: 使用 cargo.toml 中的版本 diff --git a/deploy/src/cli.rs b/deploy/src/cli.rs index d6a2840..fcaf39d 100644 --- a/deploy/src/cli.rs +++ b/deploy/src/cli.rs @@ -1,21 +1,30 @@ use clap::Parser; use serde::{Deserialize, Serialize}; -/// ServerBee 的后端配置项 +/// Backend configuration of ServerBee. +/// ServerBee 的后端配置项。 #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] pub struct Args { - /// 端口号, 默认 9527 + /// Port, default is 9527. + /// 端口号,默认 9527。 #[clap(short, long)] pub port: Option, - /// 是否开机自启, 默认自启 + /// Auto-start on boot? default Auto-start. + /// 是否开机自启,默认自启。 #[clap(short, long)] pub auto_launch: Option, - /// 交互式安装 + /// Interactive installation. + /// 交互式安装。 #[clap(short, long, default_value = "false")] pub interactive: bool, + + /// Allow downloading of pre-release versions. + /// 允许下载预发布版本。 + #[clap(long)] + pub pre_version: bool, } #[derive(Serialize, Deserialize, PartialEq, Debug)] diff --git a/deploy/src/config.rs b/deploy/src/config.rs index 7e551a9..4f5c89d 100644 --- a/deploy/src/config.rs +++ b/deploy/src/config.rs @@ -115,6 +115,14 @@ impl Config { // serde_yaml::to_writer(f, &web_config).unwrap(); } + pub fn get_locale(&self) -> String { + self.storage_config.get_locale() + } + + pub fn set_locale(&mut self, locale: String) { + self.storage_config.set_locale(locale); + } + #[cfg(target_arch = "x86_64")] pub fn get_filename(&self) -> String { if cfg!(target_os = "macos") { @@ -169,7 +177,8 @@ impl Config { pub fn set_auto_launch(&mut self, enable: bool) { let app_name = env!("CARGO_PKG_NAME"); info!( - "自启执行文件: {}", + "{}: {}", + t!("auto_launch_file_path"), env::current_exe().unwrap().to_str().unwrap() ); @@ -182,13 +191,13 @@ impl Config { if enable { if auto.is_enabled().expect("Couldn't check auto launch") { - info!("开机启动项已存在, 无需重复设置"); + info!("{}", t!("already_auto_launch")); } } else if auto.is_enabled().expect("Couldn't check auto launch") { auto.disable().expect("Couldn't disable auto launch"); - info!("取消开机启动成功"); + info!("{}", t!("cancel_auto_launch")); } else { - info!("已经取消开机启动"); + info!("{}", t!("cancel_auto_launch")); } self.storage_config.set_auto_launch(enable); @@ -200,7 +209,7 @@ impl Config { return parent.to_path_buf(); } } - env::current_dir().expect("获取当前目录失败, 权限不足或当前目录不存在") + env::current_dir().expect(t!("failed_to_get_current_dir").as_str()) } pub fn deploy_log_path() -> PathBuf { @@ -266,15 +275,15 @@ impl Config { Ok("".into()) } - pub async fn get_latest_version() -> Result { - match Config::get_latest_version_from_status(Some(false)).await { + pub async fn get_latest_version(pre_version: bool) -> Result { + match Config::get_latest_version_from_status(Some(pre_version)).await { Ok(version) => { if !version.is_empty() { return Ok(version); } } Err(e) => { - warn!("从 status 获取最新版本失败: {}, 尝试从 github 获取", e); + warn!("{}", t!("failed_to_get_version_from_status", error = e)); } } @@ -285,7 +294,7 @@ impl Config { } } Err(e) => { - warn!("从 github 获取最新版本失败: {}, 尝试从 jsdelivr 获取", e); + warn!("{}", t!("failed_to_get_version_from_github", error = e)); } } @@ -294,9 +303,13 @@ impl Config { return Ok(version); } } else { - warn!("从 jsdelivr 获取最新版本失败, 将使用 cargo.toml 中的版本"); + warn!("{}", t!("failed_to_get_version_from_jsdelivr")); } - warn!("使用 cargo.toml 中的版本: {}", env!("CARGO_PKG_VERSION")); + warn!( + "{}: {}", + t!("use_version_from_cargo_toml"), + env!("CARGO_PKG_VERSION") + ); Ok(env!("CARGO_PKG_VERSION").into()) } diff --git a/deploy/src/main.rs b/deploy/src/main.rs index f39cffb..90424e7 100644 --- a/deploy/src/main.rs +++ b/deploy/src/main.rs @@ -20,6 +20,11 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::{fs, io}; +#[macro_use] +extern crate rust_i18n; + +i18n!("locales"); + #[tokio::main] async fn main() -> Result<()> { let args = Args::parse(); @@ -29,6 +34,8 @@ async fn main() -> Result<()> { if config.get_interactive() || args.interactive { config.set_interactive(true); interactive_install(&mut config); + } else { + rust_i18n::set_locale(config.get_locale().as_str()); } Config::init_logging(); @@ -37,8 +44,8 @@ async fn main() -> Result<()> { config.set_port(Port::new(args.port.unwrap())); } - let latest_version = Config::get_latest_version().await?; - info!("最新版本: {}", latest_version); + let latest_version = Config::get_latest_version(args.pre_version).await?; + info!("{}: {}", t!("latest_version"), latest_version); config.set_version(latest_version); if !Path::new(config.web_bin_path().as_path().to_str().unwrap()).exists() { @@ -52,15 +59,18 @@ async fn main() -> Result<()> { config.download_bin().await?; - info!("文件 {} 下载成功, 正在解压", web_file_path.display()); + info!( + "{}", + t!("download_and_unzip", path = web_file_path.display()) + ); let tokio_file = tokio::fs::File::open(web_file_path).await?; let std_file = tokio_file.into_std().await; unzip(std_file, config.web_bin_dir()); - info!("文件解压完毕"); + info!("{}", t!("unzip_success")); } else { - info!("文件已存在, 跳过下载"); + info!("{}", t!("skip_download")); } config.set_auto_launch(args.auto_launch.unwrap_or_else(|| config.get_auto_launch())); @@ -78,20 +88,20 @@ async fn main() -> Result<()> { #[cfg(target_os = "linux")] if config.get_auto_launch() { use std::env::current_exe; - println!("安装完成之后,请执行如下命令,以便开机自启动"); + println!("{}", t!("auto_launch_tips")); println!("############################################"); match current_exe() { Ok(p) => println!("{}", daemon_content(p.display().to_string())), - Err(_) => println!("{}", daemon_content("serverbee-deploy的全路径".into())), + Err(_) => println!("{}", daemon_content(t!("deploy_full_path"))), } println!("systemctl enable serverbee-deploy.service"); println!("############################################"); } - println!("安装结束, 按任意键退出..."); + println!("{}", t!("install_finish")); Ok(()) } @@ -117,13 +127,16 @@ fn unzip(file: File, out_dir: PathBuf) { } if (*file.name()).ends_with('/') { - info!("文件提取到: \"{}\"", outpath.display()); + info!("{}", t!("file_extracted", path = outpath.display())); fs::create_dir_all(&outpath).unwrap(); } else { info!( - "文件提取到: \"{}\" ({} bytes)", - outpath.display(), - file.size() + "{}", + t!( + "file_extracted_with_size", + path = outpath.display(), + size = file.size() + ), ); if let Some(p) = outpath.parent() { if !p.exists() { @@ -148,32 +161,48 @@ fn unzip(file: File, out_dir: PathBuf) { #[cfg(windows)] fn start_process(bin_full_path: &str, port: u16) { - info!("文件全路径: {}", bin_full_path); + info!("{}: {}", t!("full_path"), bin_full_path); Command::new("powershell") .args(["/C", bin_full_path]) .args(["-p", port.to_string().as_str()]) .spawn() - .expect("运行 serverbee-web.exe 失败, 请尝试手动运行"); + .expect(t!("run_fail", path = "serverbee-web.exe").as_str()); - info!("serverbee-web 启动成功"); + info!("{}", t!("run_success")); } #[cfg(not(windows))] fn start_process(bin_full_path: &str, port: u16) { - info!("文件全路径: {}", bin_full_path); + info!("{}: {}", t!("full_path"), bin_full_path); Command::new(bin_full_path) .arg("-p") .arg(port.to_string()) .spawn() - .unwrap_or_else(|_| panic!("运行 {} 失败, 请尝试手动运行", bin_full_path)); + .unwrap_or_else(|_| panic!("{}", t!("run_fail", path = bin_full_path))); - info!("serverbee-web 启动成功"); + info!("{}", t!("run_success")); } fn interactive_install(config: &mut Config) { - let port_ans = Text::new("请输入端口号? (默认使用 9527)") + let locales_options = vec!["English", "中文"]; + + let locales_ans = Select::new(t!("locale_question").as_str(), locales_options.clone()) + .with_help_message(t!("action_tips").as_str()) + .prompt(); + + match locales_ans { + Ok(choice) => match choice { + "English" => config.set_locale("en".to_string()), + "中文" => config.set_locale("zh".to_string()), + _ => panic!("{}", t!("error_and_retry")), + }, + Err(_) => panic!("{}", t!("error_and_retry")), + } + rust_i18n::set_locale(config.get_locale().as_str()); + + let port_ans = Text::new(t!("port_question").as_str()) .with_validator(|s: &str| { let port; if let Ok(p) = s.parse::() { @@ -181,12 +210,12 @@ fn interactive_install(config: &mut Config) { } else if s.is_empty() { port = 9527 } else { - return Ok(Validation::Invalid(ErrorMessage::from("端口号输入有误"))); + return Ok(Validation::Invalid(ErrorMessage::from(t!("port_invalid")))); } if !is_free(port) { - return Ok(Validation::Invalid(ErrorMessage::from(format!( - "端口: {} 已被占用, 请更换其他端口", - port + return Ok(Validation::Invalid(ErrorMessage::from(t!( + "port_in_use", + port = port )))); } Ok(Validation::Valid) @@ -195,13 +224,13 @@ fn interactive_install(config: &mut Config) { match port_ans { Ok(port) => config.set_port(Port::new(port.parse::().unwrap_or(9527))), - Err(_) => panic!("出现错误,请重试"), + Err(_) => panic!("{}", t!("error_and_retry")), } - let auto_launch_options = vec!["是", "否"]; + let auto_launch_options = vec![t!("yes"), t!("no")]; - let auto_launch_ans = Select::new("是否开机自启", auto_launch_options.clone()) - .with_help_message("↑↓ 移动, 回车确定 ✅, 输入以筛选") + let auto_launch_ans = Select::new(t!("launch_question").as_str(), auto_launch_options.clone()) + .with_help_message(t!("action_tips").as_str()) .prompt(); match auto_launch_ans { @@ -212,29 +241,30 @@ fn interactive_install(config: &mut Config) { config.set_auto_launch(false) } } - Err(_) => panic!("出现错误,请重试"), + Err(_) => panic!("{}", t!("error_and_retry")), } println!("=============================="); - println!("请确认如下设置"); + println!("{}", t!("confirm_config")); println!(" "); - println!("端口号: {}", config.get_port()); + println!("{}: {}", t!("port"), config.get_port()); println!( - "开机自启: {}", + "{}: {}", + t!("auto_launch"), if config.get_auto_launch() { - auto_launch_options[0] + auto_launch_options[0].clone() } else { - auto_launch_options[1] + auto_launch_options[1].clone() } ); println!(" "); - println!("按任意键以继续安装, 取消安装请输入 Ctrl+C"); + println!("{}", t!("install_confirm")); stdin() .read_line(&mut String::new()) .expect("error: unable to read user input"); - println!("确认完毕, 开始安装"); + println!("{}", t!("start_install")); println!("=============================="); } diff --git a/deploy/src/storage_config.rs b/deploy/src/storage_config.rs index 8a43007..25fd20b 100644 --- a/deploy/src/storage_config.rs +++ b/deploy/src/storage_config.rs @@ -1,14 +1,15 @@ -use std::fs::{File, OpenOptions}; -use std::path::PathBuf; -use serde::{Deserialize, Serialize}; use crate::cli::Port; use crate::config::Config; +use serde::{Deserialize, Serialize}; +use std::fs::{File, OpenOptions}; +use std::path::PathBuf; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct StorageConfig { pub port: Option, pub is_auto_launch: Option, - interactive: Option + pub locale: Option, + interactive: Option, } impl StorageConfig { @@ -18,8 +19,9 @@ impl StorageConfig { } else { Self { port: None, + locale: None, is_auto_launch: None, - interactive: None + interactive: None, } } } @@ -31,6 +33,17 @@ impl StorageConfig { } } + pub fn set_locale(&mut self, locale: String) { + if self.locale.is_none() || self.locale.as_ref().unwrap() != &locale { + self.locale = Some(locale); + self.save_config(); + } + } + + pub fn get_locale(&self) -> String { + self.locale.clone().unwrap_or_else(|| "en".to_string()) + } + pub fn get_interactive(&self) -> Option { self.interactive } diff --git a/web/Cargo.toml b/web/Cargo.toml index 75ccfa6..6b1f961 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -2,6 +2,12 @@ name = "serverbee-web" version = "2.0.0" edition = "2021" +categories = ["web-programming::http-server", "visualization"] +keywords = ["serverbee", "web-server", "visualization", "monitor"] +homepage = "https://github.com/ZingerLittleBee/server_bee-backend" +repository = "https://github.com/ZingerLittleBee/server_bee-backend" +description = "Backend for iOS application named ServerBee" +readme = "../README.md" [features] subsystem = []