set public path, fix #439, add system stat route

This commit is contained in:
jb-alvarado 2023-11-07 13:45:43 +01:00
parent 22087d8cd4
commit c30438697d
13 changed files with 542 additions and 182 deletions

378
Cargo.lock generated
View File

@ -64,7 +64,7 @@ dependencies = [
"actix-service",
"actix-utils",
"ahash",
"base64 0.21.4",
"base64 0.21.5",
"bitflags 2.4.1",
"brotli",
"bytes",
@ -99,7 +99,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb"
dependencies = [
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -137,7 +137,7 @@ dependencies = [
"parse-size",
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -175,7 +175,7 @@ dependencies = [
"futures-core",
"futures-util",
"mio",
"socket2 0.5.4",
"socket2 0.5.5",
"tokio",
"tracing",
]
@ -236,7 +236,7 @@ dependencies = [
"serde_json",
"serde_urlencoded",
"smallvec",
"socket2 0.5.4",
"socket2 0.5.5",
"time",
"url",
]
@ -250,7 +250,7 @@ dependencies = [
"actix-router",
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -271,7 +271,7 @@ checksum = "1d613edf08a42ccc6864c941d30fe14e1b676a77d16f1dbadc1174d065a0a775"
dependencies = [
"actix-utils",
"actix-web",
"base64 0.21.4",
"base64 0.21.5",
"futures-core",
"futures-util",
"log",
@ -307,14 +307,15 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "ahash"
version = "0.8.3"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
dependencies = [
"cfg-if",
"getrandom",
"once_cell",
"version_check",
"zerocopy",
]
[[package]]
@ -504,9 +505,9 @@ dependencies = [
"log",
"parking",
"polling",
"rustix 0.37.26",
"rustix 0.37.27",
"slab",
"socket2 0.4.9",
"socket2 0.4.10",
"waker-fn",
]
@ -560,7 +561,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -620,9 +621,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
name = "base64"
version = "0.21.4"
version = "0.21.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2"
checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9"
[[package]]
name = "base64ct"
@ -692,9 +693,9 @@ dependencies = [
[[package]]
name = "brotli-decompressor"
version = "2.5.0"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da74e2b81409b1b743f8f0c62cc6254afefb8b8e50bbfe3735550f7aeefa3448"
checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f"
dependencies = [
"alloc-no-stdlib",
"alloc-stdlib",
@ -720,9 +721,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
[[package]]
name = "bytestring"
version = "1.3.0"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "238e4886760d98c4f899360c834fa93e62cf7f721ac3c2da375cbdf4b8679aae"
checksum = "74d80203ea6b29df88012294f62733de21cfeab47f17b41af3a38bc30a03ee72"
dependencies = [
"bytes",
]
@ -776,9 +777,9 @@ checksum = "cca491388666e04d7248af3f60f0c40cfb0991c72205595d7c396e3510207d1a"
[[package]]
name = "clap"
version = "4.4.6"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956"
checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b"
dependencies = [
"clap_builder",
"clap_derive",
@ -786,9 +787,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.4.6"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45"
checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663"
dependencies = [
"anstream",
"anstyle",
@ -798,21 +799,21 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.4.2"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
name = "clap_lex"
version = "0.5.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "colorchoice"
@ -870,9 +871,9 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "cpufeatures"
version = "0.2.9"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1"
checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0"
dependencies = [
"libc",
]
@ -888,9 +889,9 @@ dependencies = [
[[package]]
name = "crc-catalog"
version = "2.2.0"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484"
checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
[[package]]
name = "crc32fast"
@ -985,7 +986,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -996,7 +997,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5"
dependencies = [
"darling_core",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -1078,7 +1079,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbfb21b9878cf7a348dcb8559109aabc0ec40d69924bd706fa5149846c4fef75"
dependencies = [
"base64 0.21.4",
"base64 0.21.5",
"memchr",
]
@ -1158,7 +1159,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]]
name = "ffplayout"
version = "0.20.0-beta4"
version = "0.20.0-beta5"
dependencies = [
"chrono",
"clap",
@ -1180,7 +1181,7 @@ dependencies = [
[[package]]
name = "ffplayout-api"
version = "0.20.0-beta4"
version = "0.20.0-beta5"
dependencies = [
"actix-files",
"actix-multipart",
@ -1196,7 +1197,9 @@ dependencies = [
"ffplayout-lib",
"futures-util",
"jsonwebtoken",
"lazy_static",
"lexical-sort",
"local-ip-address",
"once_cell",
"path-clean",
"rand",
@ -1217,7 +1220,7 @@ dependencies = [
[[package]]
name = "ffplayout-lib"
version = "0.20.0-beta4"
version = "0.20.0-beta5"
dependencies = [
"chrono",
"crossbeam-channel",
@ -1334,9 +1337,9 @@ dependencies = [
[[package]]
name = "futures"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335"
dependencies = [
"futures-channel",
"futures-core",
@ -1349,9 +1352,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb"
dependencies = [
"futures-core",
"futures-sink",
@ -1359,15 +1362,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
[[package]]
name = "futures-executor"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc"
dependencies = [
"futures-core",
"futures-task",
@ -1387,9 +1390,9 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
[[package]]
name = "futures-lite"
@ -1408,32 +1411,32 @@ dependencies = [
[[package]]
name = "futures-macro"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
name = "futures-sink"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"
checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817"
[[package]]
name = "futures-task"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2"
[[package]]
name = "futures-util"
version = "0.3.28"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
dependencies = [
"futures-channel",
"futures-core",
@ -1641,7 +1644,7 @@ dependencies = [
"httpdate",
"itoa",
"pin-project-lite",
"socket2 0.4.9",
"socket2 0.4.10",
"tokio",
"tower-service",
"tracing",
@ -1650,9 +1653,9 @@ dependencies = [
[[package]]
name = "hyper-rustls"
version = "0.24.1"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97"
checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590"
dependencies = [
"futures-util",
"http",
@ -1723,9 +1726,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "2.0.2"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown 0.14.2",
@ -1773,9 +1776,9 @@ dependencies = [
[[package]]
name = "ipnet"
version = "2.8.0"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6"
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
[[package]]
name = "itertools"
@ -1803,9 +1806,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.64"
version = "0.3.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8"
dependencies = [
"wasm-bindgen",
]
@ -1816,9 +1819,9 @@ version = "8.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378"
dependencies = [
"base64 0.21.4",
"base64 0.21.5",
"pem",
"ring",
"ring 0.16.20",
"serde",
"serde_json",
"simple_asn1",
@ -1874,7 +1877,7 @@ version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76bd09637ae3ec7bd605b8e135e757980b3968430ff2b1a4a94fb7769e50166d"
dependencies = [
"base64 0.21.4",
"base64 0.21.5",
"email-encoding",
"email_address",
"fastrand 1.9.0",
@ -1886,7 +1889,7 @@ dependencies = [
"quoted_printable",
"rustls",
"rustls-pemfile",
"socket2 0.4.9",
"socket2 0.4.10",
"tokio",
"webpki-roots 0.23.1",
]
@ -1902,9 +1905,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.149"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "libm"
@ -1937,9 +1940,9 @@ checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f"
[[package]]
name = "local-channel"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a493488de5f18c8ffcba89eebb8532ffc562dc400490eb65b84893fae0b178"
checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8"
dependencies = [
"futures-core",
"futures-sink",
@ -1947,10 +1950,22 @@ dependencies = [
]
[[package]]
name = "local-waker"
version = "0.1.3"
name = "local-ip-address"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e34f76eb3611940e0e7d53a9aaa4e6a3151f69541a282fd0dad5571420c53ff1"
checksum = "66357e687a569abca487dc399a9c9ac19beb3f13991ed49f00c144e02cbd42ab"
dependencies = [
"libc",
"neli",
"thiserror",
"windows-sys",
]
[[package]]
name = "local-waker"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d873d7c67ce09b42110d801813efbc9364414e356be9935700d368351657487"
[[package]]
name = "lock_api"
@ -2029,9 +2044,9 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.8"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0"
dependencies = [
"libc",
"log",
@ -2039,6 +2054,31 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "neli"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1100229e06604150b3becd61a4965d5c70f3be1759544ea7274166f4be41ef43"
dependencies = [
"byteorder",
"libc",
"log",
"neli-proc-macros",
]
[[package]]
name = "neli-proc-macros"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c168194d373b1e134786274020dae7fc5513d565ea2ebb9bc9ff17ffb69106d4"
dependencies = [
"either",
"proc-macro2",
"quote",
"serde",
"syn 1.0.109",
]
[[package]]
name = "nom"
version = "7.1.3"
@ -2497,7 +2537,7 @@ version = "0.11.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b"
dependencies = [
"base64 0.21.4",
"base64 0.21.5",
"bytes",
"encoding_rs",
"futures-core",
@ -2541,11 +2581,25 @@ dependencies = [
"libc",
"once_cell",
"spin 0.5.2",
"untrusted",
"untrusted 0.7.1",
"web-sys",
"winapi",
]
[[package]]
name = "ring"
version = "0.17.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b"
dependencies = [
"cc",
"getrandom",
"libc",
"spin 0.9.8",
"untrusted 0.9.0",
"windows-sys",
]
[[package]]
name = "rpassword"
version = "7.2.0"
@ -2559,16 +2613,14 @@ dependencies = [
[[package]]
name = "rsa"
version = "0.9.2"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ab43bb47d23c1a631b4b680199a45255dce26fa9ab2fa902581f624ff13e6a8"
checksum = "86ef35bf3e7fe15a53c4ab08a998e42271eab13eb0db224126bc7bc4c4bad96d"
dependencies = [
"byteorder",
"const-oid",
"digest",
"num-bigint-dig",
"num-integer",
"num-iter",
"num-traits",
"pkcs1",
"pkcs8",
@ -2606,9 +2658,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.37.26"
version = "0.37.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84f3f8f960ed3b5a59055428714943298bf3fa2d4a1d53135084e0544829d995"
checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2"
dependencies = [
"bitflags 1.3.2",
"errno",
@ -2620,9 +2672,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.20"
version = "0.38.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0"
checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3"
dependencies = [
"bitflags 2.4.1",
"errno",
@ -2633,13 +2685,13 @@ dependencies = [
[[package]]
name = "rustls"
version = "0.21.7"
version = "0.21.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8"
checksum = "446e14c5cda4f3f30fe71863c34ec70f5ac79d6087097ad0bb433e1be5edf04c"
dependencies = [
"log",
"ring",
"rustls-webpki 0.101.6",
"ring 0.17.5",
"rustls-webpki 0.101.7",
"sct",
]
@ -2649,7 +2701,7 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2"
dependencies = [
"base64 0.21.4",
"base64 0.21.5",
]
[[package]]
@ -2658,18 +2710,18 @@ version = "0.100.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f6a5fc258f1c1276dfe3016516945546e2d5383911efc0fc4f1cdc5df3a4ae3"
dependencies = [
"ring",
"untrusted",
"ring 0.16.20",
"untrusted 0.7.1",
]
[[package]]
name = "rustls-webpki"
version = "0.101.6"
version = "0.101.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe"
checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765"
dependencies = [
"ring",
"untrusted",
"ring 0.17.5",
"untrusted 0.9.0",
]
[[package]]
@ -2705,12 +2757,12 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "sct"
version = "0.7.0"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4"
checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414"
dependencies = [
"ring",
"untrusted",
"ring 0.17.5",
"untrusted 0.9.0",
]
[[package]]
@ -2721,29 +2773,29 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.189"
version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537"
checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.189"
version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5"
checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
name = "serde_json"
version = "1.0.107"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -2773,11 +2825,11 @@ dependencies = [
[[package]]
name = "serde_yaml"
version = "0.9.25"
version = "0.9.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574"
checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c"
dependencies = [
"indexmap 2.0.2",
"indexmap 2.1.0",
"itoa",
"ryu",
"serde",
@ -2806,7 +2858,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -2903,9 +2955,9 @@ checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "socket2"
version = "0.4.9"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662"
checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d"
dependencies = [
"libc",
"winapi",
@ -2913,9 +2965,9 @@ dependencies = [
[[package]]
name = "socket2"
version = "0.5.4"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e"
checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
dependencies = [
"libc",
"windows-sys",
@ -2992,7 +3044,7 @@ dependencies = [
"futures-util",
"hashlink",
"hex",
"indexmap 2.0.2",
"indexmap 2.1.0",
"log",
"memchr",
"once_cell",
@ -3055,7 +3107,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "864b869fdf56263f4c95c45483191ea0af340f9f3e3e7b4d57a61c7c87a970db"
dependencies = [
"atoi",
"base64 0.21.4",
"base64 0.21.5",
"bitflags 2.4.1",
"byteorder",
"bytes",
@ -3097,7 +3149,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb7ae0e6a97fb3ba33b23ac2671a5ce6e3cabe003f451abd5a56e7951d975624"
dependencies = [
"atoi",
"base64 0.21.4",
"base64 0.21.5",
"bitflags 2.4.1",
"byteorder",
"crc",
@ -3198,9 +3250,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.38"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
dependencies = [
"proc-macro2",
"quote",
@ -3245,14 +3297,14 @@ dependencies = [
[[package]]
name = "tempfile"
version = "3.8.0"
version = "3.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
dependencies = [
"cfg-if",
"fastrand 2.0.1",
"redox_syscall 0.3.5",
"rustix 0.38.20",
"redox_syscall 0.4.1",
"rustix 0.38.21",
"windows-sys",
]
@ -3267,7 +3319,7 @@ dependencies = [
[[package]]
name = "tests"
version = "0.20.0-beta4"
version = "0.20.0-beta5"
dependencies = [
"chrono",
"crossbeam-channel",
@ -3307,7 +3359,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -3382,7 +3434,7 @@ dependencies = [
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2 0.5.4",
"socket2 0.5.5",
"tokio-macros",
"windows-sys",
]
@ -3395,7 +3447,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -3421,9 +3473,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.7.9"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d"
checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15"
dependencies = [
"bytes",
"futures-core",
@ -3459,7 +3511,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@ -3537,6 +3589,12 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "untrusted"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "url"
version = "2.4.1"
@ -3614,9 +3672,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@ -3624,24 +3682,24 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.37"
version = "0.4.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03"
checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02"
dependencies = [
"cfg-if",
"js-sys",
@ -3651,9 +3709,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -3661,28 +3719,28 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b"
[[package]]
name = "web-sys"
version = "0.3.64"
version = "0.3.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b"
checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -3825,6 +3883,26 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "zerocopy"
version = "0.7.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cd369a67c0edfef15010f980c3cbe45d7f651deac2cd67ce097cd801de16557"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
]
[[package]]
name = "zeroize"
version = "1.6.0"

View File

@ -4,7 +4,7 @@ default-members = ["ffplayout-api", "ffplayout-engine", "tests"]
resolver = "2"
[workspace.package]
version = "0.20.0-beta4"
version = "0.20.0-beta5"
license = "GPL-3.0"
repository = "https://github.com/ffplayout/ffplayout"
authors = ["Jonathan Baecker <jonbae77@gmail.com>"]

1
debian/postinst vendored
View File

@ -13,6 +13,7 @@ fi
if [ ! -d "/usr/share/ffplayout/db" ]; then
mkdir "/usr/share/ffplayout/db"
mkdir -p "/usr/share/ffplayout/public/live"
mkdir -p "/var/lib/ffplayout/playlists"
mkdir -p "/var/lib/ffplayout/tv-media"

View File

@ -23,7 +23,9 @@ derive_more = "0.99"
faccess = "0.2"
futures-util = { version = "0.3", default-features = false, features = ["std"] }
jsonwebtoken = "8"
lazy_static = "1.4"
lexical-sort = "0.3"
local-ip-address = "0.5"
once_cell = "1.18"
path-clean = "1.0"
rand = "0.8"

View File

@ -3,6 +3,7 @@ use std::path::Path;
use std::thread::sleep;
use std::time::Duration;
use local_ip_address::list_afinet_netifas;
use sysinfo::{CpuExt, DiskExt, NetworkExt, System, SystemExt};
pub fn byte_convert(num: f64) -> String {
@ -87,8 +88,24 @@ struct SystemStat {
}
fn main() {
let network_interfaces = list_afinet_netifas().unwrap();
let mut sys = System::new_all();
let mut interfaces = vec![];
for (name, ip) in network_interfaces.iter() {
if !ip.is_loopback() {
interfaces.push((name, ip))
}
}
if interfaces.len() > 1 {
interfaces = interfaces
.into_iter()
.filter(|i| i.1.is_ipv4())
.collect::<_>();
}
loop {
sys.refresh_all();
@ -132,7 +149,7 @@ fn main() {
let mut my_network = Network::default();
for (interface_name, data) in sys.networks() {
if interface_name == "wlp5s0" {
if !interfaces.is_empty() && interface_name == interfaces[0].0 {
my_network.name = interface_name.clone();
my_network.current_in = byte_convert(data.received() as f64);
my_network.total_in = byte_convert(data.total_received() as f64);

View File

@ -27,6 +27,7 @@ use argon2::{
Argon2, PasswordHasher, PasswordVerifier,
};
use chrono::{DateTime, Datelike, Duration, Local, NaiveDateTime, TimeZone, Utc};
use path_clean::PathClean;
use regex::Regex;
use serde::{Deserialize, Serialize};
use simplelog::*;
@ -46,7 +47,7 @@ use crate::utils::{
},
naive_date_time_from_str,
playlist::{delete_playlist, generate_playlist, read_playlist, write_playlist},
playout_config, read_log_file, read_playout_config, Role,
playout_config, public_path, read_log_file, read_playout_config, system, Role,
};
use crate::{
auth::{create_jwt, Claims},
@ -955,6 +956,35 @@ async fn get_file(
}))
}
/// **Get Public**
///
/// Can be used for HLS Playlist and other static files in public folder
///
/// ```BASH
/// curl -X GET http://127.0.0.1:8787/live/stream.m3u8
/// ```
#[get("/{public:((live|preview|public).*|.*(ts|m3u8))}")]
async fn get_public(public: web::Path<String>) -> Result<actix_files::NamedFile, ServiceError> {
let public_path = public_path();
let absolute_path = if public_path.is_absolute() {
public_path.to_path_buf()
} else {
env::current_dir()?.join(public_path)
}
.clean();
let path = absolute_path.join(public.as_str());
let file = actix_files::NamedFile::open(path)?;
Ok(file
.use_last_modified(true)
.set_content_disposition(ContentDisposition {
disposition: DispositionType::Attachment,
parameters: vec![],
}))
}
/// **Import playlist**
///
/// Import text/m3u file and convert it to a playlist
@ -1084,3 +1114,24 @@ async fn get_program(
Ok(web::Json(program))
}
/// ### System Statistics
///
/// Get statistics about CPU, Ram, Disk, etc. usage.
///
/// ```BASH
/// curl -X GET http://127.0.0.1:8787/api/system
/// -H 'Content-Type: application/json' -H 'Authorization: Bearer <TOKEN>'
/// ```
#[get("/system/{id}")]
#[has_any_role("Role::Admin", "Role::User", type = "Role")]
pub async fn get_system_stat(
pool: web::Data<Pool<Sqlite>>,
id: web::Path<i32>,
) -> Result<impl Responder, ServiceError> {
let (config, _) = playout_config(&pool.clone().into_inner(), &id).await?;
let stat = web::block(move || system::stat(config)).await?;
Ok(web::Json(stat))
}

View File

@ -74,16 +74,13 @@ async fn create_schema(conn: &Pool<Sqlite>) -> Result<SqliteQueryResult, sqlx::E
sqlx::query(query).execute(conn).await
}
pub async fn db_init(
domain: Option<String>,
db: &Option<String>,
) -> Result<&'static str, Box<dyn std::error::Error>> {
let db_path = db_path(db.clone())?;
pub async fn db_init(domain: Option<String>) -> Result<&'static str, Box<dyn std::error::Error>> {
let db_path = db_path()?;
if !Sqlite::database_exists(db_path).await.unwrap_or(false) {
Sqlite::create_database(db_path).await.unwrap();
let pool = db_pool(db).await?;
let pool = db_pool().await?;
match create_schema(&pool).await {
Ok(_) => info!("Database created Successfully"),
@ -125,7 +122,7 @@ pub async fn db_init(
('Scrolling Text', 'We have a very important announcement to make.', 'ifnot(ld(1),st(1,t));if(lt(t,ld(1)+1),w+4,w-w/12*mod(t-ld(1),12*(w+tw)/w))', '(h-line_h)*0.9',
'24', '4', '#ffffff', '1', '#000000@0x80', '4', '1.0', '1');";
let pool = db_pool(db).await?;
let pool = db_pool().await?;
sqlx::query(query)
.bind(secret)

View File

@ -5,8 +5,8 @@ pub mod models;
use crate::utils::db_path;
pub async fn db_pool(db: &Option<String>) -> Result<Pool<Sqlite>, sqlx::Error> {
let db_path = db_path(db.clone()).unwrap();
pub async fn db_pool() -> Result<Pool<Sqlite>, sqlx::Error> {
let db_path = db_path().unwrap();
let conn = SqlitePool::connect(db_path).await?;
Ok(conn)

View File

@ -1,4 +1,4 @@
use std::process::exit;
use std::{env, process::exit};
use actix_web::{
dev::ServiceRequest, middleware::Logger, web, App, Error, HttpMessage, HttpServer,
@ -13,6 +13,8 @@ use actix_files::Files;
use actix_web_static_files::ResourceFiles;
use clap::Parser;
use lazy_static::lazy_static;
use path_clean::PathClean;
use simplelog::*;
pub mod api;
@ -46,10 +48,12 @@ async fn validator(
}
}
lazy_static! {
static ref ARGS: Args = Args::parse();
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let args = Args::parse();
let mut config = PlayoutConfig::new(None);
config.mail.recipient = String::new();
config.logging.log_to_file = false;
@ -58,11 +62,11 @@ async fn main() -> std::io::Result<()> {
let logging = init_logging(&config, None, None);
CombinedLogger::init(logging).unwrap();
if let Err(c) = run_args(args.clone()).await {
if let Err(c) = run_args().await {
exit(c);
}
let pool = match db_pool(&args.db).await {
let pool = match db_pool().await {
Ok(p) => p,
Err(e) => {
error!("{e}");
@ -70,8 +74,8 @@ async fn main() -> std::io::Result<()> {
}
};
if let Some(conn) = args.listen {
if db_path(args.db).is_err() {
if let Some(conn) = &ARGS.listen {
if db_path().is_err() {
error!("Database is not initialized! Init DB first and add admin user.");
exit(1);
}
@ -129,10 +133,24 @@ async fn main() -> std::io::Result<()> {
.service(remove)
.service(save_file)
.service(import_playlist)
.service(get_program),
.service(get_program)
.service(get_system_stat),
)
.service(get_file);
if let Some(public) = &ARGS.public {
let absolute_path = if public.is_absolute() {
public.to_path_buf()
} else {
env::current_dir().unwrap_or_default().join(public)
}
.clean();
web_app = web_app.service(Files::new("/", absolute_path));
} else {
web_app = web_app.service(get_public);
}
#[cfg(not(debug_assertions))]
{
// in release mode embed frontend

View File

@ -1,3 +1,5 @@
use std::path::PathBuf;
use clap::Parser;
#[derive(Parser, Debug, Clone)]
@ -9,7 +11,10 @@ pub struct Args {
pub ask: bool,
#[clap(long, help = "path to database file")]
pub db: Option<String>,
pub db: Option<PathBuf>,
#[clap(long, help = "path to public files")]
pub public: Option<PathBuf>,
#[clap(short, long, help = "Listen on IP:PORT, like: 127.0.0.1:8787")]
pub listen: Option<String>,

View File

@ -4,7 +4,7 @@ use std::{
fmt,
fs::{self, File},
io::{stdin, stdout, Write},
path::Path,
path::{Path, PathBuf},
str::FromStr,
};
@ -17,19 +17,22 @@ use serde::{de, Deserialize, Deserializer, Serialize};
use simplelog::*;
use sqlx::{sqlite::SqliteRow, FromRow, Pool, Row, Sqlite};
use crate::ARGS;
pub mod args_parse;
pub mod channels;
pub mod control;
pub mod errors;
pub mod files;
pub mod playlist;
pub mod system;
use crate::db::{
db_pool,
handles::{db_init, insert_user, select_channel, select_global},
models::{Channel, User},
};
use crate::utils::{args_parse::Args, errors::ServiceError};
use crate::utils::errors::ServiceError;
use ffplayout_lib::utils::{time_to_sec, PlayoutConfig};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
@ -123,13 +126,12 @@ pub async fn init_config(conn: &Pool<Sqlite>) {
INSTANCE.set(config).unwrap();
}
pub fn db_path(db: Option<String>) -> Result<&'static str, Box<dyn std::error::Error>> {
if let Some(path) = db {
let path_buf = Path::new(&path);
let absolute_path = if path_buf.is_absolute() {
path_buf.to_path_buf()
pub fn db_path() -> Result<&'static str, Box<dyn std::error::Error>> {
if let Some(path) = ARGS.db.clone() {
let absolute_path = if path.is_absolute() {
path
} else {
env::current_dir()?.join(path_buf)
env::current_dir()?.join(path)
}
.clean();
@ -160,7 +162,19 @@ pub fn db_path(db: Option<String>) -> Result<&'static str, Box<dyn std::error::E
Ok(db_path)
}
pub async fn run_args(mut args: Args) -> Result<(), i32> {
pub fn public_path() -> PathBuf {
let path = PathBuf::from("/usr/share/ffplayout/public/");
if path.is_dir() {
return path;
}
PathBuf::from("./public/")
}
pub async fn run_args() -> Result<(), i32> {
let mut args = ARGS.clone();
if !args.init && args.listen.is_none() && !args.ask && args.username.is_none() {
error!("Wrong number of arguments! Run ffpapi --help for more information.");
@ -168,7 +182,7 @@ pub async fn run_args(mut args: Args) -> Result<(), i32> {
}
if args.init {
if let Err(e) = db_init(args.domain, &args.db).await {
if let Err(e) = db_init(args.domain).await {
panic!("{e}");
};
@ -232,7 +246,7 @@ pub async fn run_args(mut args: Args) -> Result<(), i32> {
token: None,
};
match db_pool(&args.db).await {
match db_pool().await {
Ok(conn) => {
if let Err(e) = insert_user(&conn, user).await {
error!("{e}");

View File

@ -0,0 +1,175 @@
use std::cmp;
use local_ip_address::list_afinet_netifas;
use serde::Serialize;
use sysinfo::{CpuExt, DiskExt, NetworkExt, System, SystemExt};
use ffplayout_lib::utils::PlayoutConfig;
pub fn byte_convert(num: f64) -> String {
let negative = if num.is_sign_positive() { "" } else { "-" };
let num = num.abs();
let units = ["B", "kiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
if num < 1_f64 {
return format!("{negative}{num} B");
}
let delimiter = 1024_f64;
let exponent = cmp::min(
(num.ln() / delimiter.ln()).floor() as i32,
(units.len() - 1) as i32,
);
let pretty_bytes = format!("{:.3}", num / delimiter.powi(exponent))
.parse::<f64>()
.unwrap()
* 1_f64;
let unit = units[exponent as usize];
format!("{negative}{pretty_bytes} {unit}")
}
#[derive(Debug, Serialize)]
pub struct Cpu {
pub cores: f32,
pub usage: f32,
}
#[derive(Debug, Default, Serialize)]
pub struct Storage {
pub path: String,
pub total: String,
pub used: String,
}
#[derive(Debug, Serialize)]
pub struct Load {
pub one: f64,
pub five: f64,
pub fifteen: f64,
}
#[derive(Debug, Serialize)]
pub struct Memory {
pub total: String,
pub used: String,
pub free: String,
}
#[derive(Debug, Default, Serialize)]
pub struct Network {
pub name: String,
pub current_in: String,
pub total_in: String,
pub current_out: String,
pub total_out: String,
}
#[derive(Debug, Serialize)]
pub struct MySystem {
pub name: Option<String>,
pub kernel: Option<String>,
pub version: Option<String>,
}
#[derive(Debug, Serialize)]
pub struct Swap {
pub total: String,
pub used: String,
pub free: String,
}
#[derive(Debug, Serialize)]
pub struct SystemStat {
pub cpu: Cpu,
pub load: Load,
pub memory: Memory,
pub network: Network,
pub storage: Storage,
pub swap: Swap,
pub system: MySystem,
}
pub fn stat(config: PlayoutConfig) -> SystemStat {
let network_interfaces = list_afinet_netifas().unwrap();
let mut sys = System::new_all();
let mut usage = 0.0;
let mut interfaces = vec![];
for (name, ip) in network_interfaces.iter() {
if !ip.is_loopback() {
interfaces.push((name, ip))
}
}
interfaces.dedup_by(|a, b| a.0 == b.0);
sys.refresh_all();
let cores = sys.cpus().len() as f32;
for cpu in sys.cpus() {
usage += cpu.cpu_usage();
}
let cpu = Cpu {
cores,
usage: usage * cores / 100.0,
};
let mut storage = Storage::default();
for disk in sys.disks() {
if disk.mount_point().to_string_lossy().len() > 1
&& config.storage.path.starts_with(disk.mount_point())
{
storage.path = disk.name().to_string_lossy().to_string();
storage.total = byte_convert(disk.total_space() as f64);
storage.used = byte_convert(disk.available_space() as f64);
}
}
let load_avg = sys.load_average();
let load = Load {
one: load_avg.one,
five: load_avg.five,
fifteen: load_avg.fifteen,
};
let memory = Memory {
total: byte_convert(sys.total_memory() as f64),
used: byte_convert(sys.used_memory() as f64),
free: byte_convert((sys.total_memory() - sys.used_memory()) as f64),
};
let mut network = Network::default();
for (interface_name, data) in sys.networks() {
if !interfaces.is_empty() && interface_name == interfaces[0].0 {
network.name = interface_name.clone();
network.current_in = byte_convert(data.received() as f64);
network.total_in = byte_convert(data.total_received() as f64);
network.current_out = byte_convert(data.transmitted() as f64);
network.total_out = byte_convert(data.total_transmitted() as f64);
}
}
let swap = Swap {
total: byte_convert(sys.total_swap() as f64),
used: byte_convert(sys.used_swap() as f64),
free: byte_convert((sys.total_swap() - sys.used_swap()) as f64),
};
let system = MySystem {
name: sys.name(),
kernel: sys.kernel_version(),
version: sys.os_version(),
};
SystemStat {
cpu,
storage,
load,
memory,
network,
system,
swap,
}
}

View File

@ -186,6 +186,8 @@ pub fn init_logging(
.set_thread_level(LevelFilter::Off)
.set_target_level(LevelFilter::Off)
.add_filter_ignore_str("hyper")
.add_filter_ignore_str("libc")
.add_filter_ignore_str("neli")
.add_filter_ignore_str("reqwest")
.add_filter_ignore_str("rpc")
.add_filter_ignore_str("rustls")