diff --git a/Cargo.lock b/Cargo.lock index 1b2c0e3..6632a01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,12 +14,66 @@ dependencies = [ ] [[package]] -name = "aho-corasick" -version = "0.7.20" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "memchr", + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", ] [[package]] @@ -49,7 +103,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.38", ] [[package]] @@ -121,6 +175,12 @@ dependencies = [ "syn 1.0.104", ] +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + [[package]] name = "bitflags" version = "1.3.2" @@ -129,24 +189,35 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "breeze" -version = "0.1.4" +version = "0.1.5" dependencies = [ "archived", "async-recursion", "axum", "bytes", + "clap", "futures", "hyper", - "log", - "pretty_env_logger", "rand", + "serde", + "serde_with", "tokio", "tokio-stream", "tokio-util", + "toml", "tower", + "tracing", + "tracing-subscriber", "walkdir", + "xxhash-rust", ] +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + [[package]] name = "bytes" version = "1.3.0" @@ -155,9 +226,12 @@ checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -166,39 +240,121 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "env_logger" -version = "0.10.0" +name = "chrono" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets", ] [[package]] -name = "errno" -version = "0.2.8" +name = "clap" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ - "errno-dragonfly", - "libc", - "winapi", + "clap_builder", + "clap_derive", ] [[package]] -name = "errno-dragonfly" -version = "0.1.2" +name = "clap_builder" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ - "cc", - "libc", + "anstream", + "anstyle", + "clap_lex", + "strsim", ] +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.38", +] + +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "deranged" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +dependencies = [ + "powerfmt", + "serde", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "fnv" version = "1.0.7" @@ -270,7 +426,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.38", ] [[package]] @@ -326,7 +482,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 1.9.2", "slab", "tokio", "tokio-util", @@ -342,6 +498,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" + [[package]] name = "heck" version = "0.4.0" @@ -358,13 +520,10 @@ dependencies = [ ] [[package]] -name = "hermit-abi" -version = "0.2.6" +name = "hex" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "http" @@ -406,12 +565,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "0.14.23" @@ -436,6 +589,35 @@ dependencies = [ "want", ] +[[package]] +name = "iana-time-zone" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "indexmap" version = "1.9.2" @@ -443,29 +625,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", + "serde", ] [[package]] -name = "io-lifetimes" -version = "1.0.4" +name = "indexmap" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "is-terminal" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" -dependencies = [ - "hermit-abi 0.2.6", - "io-lifetimes", - "rustix", - "windows-sys", + "equivalent", + "hashbrown 0.14.1", + "serde", ] [[package]] @@ -474,18 +646,27 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +[[package]] +name = "js-sys" +version = "0.3.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" -[[package]] -name = "linux-raw-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" - [[package]] name = "lock_api" version = "0.4.9" @@ -532,7 +713,26 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.42.0", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", ] [[package]] @@ -541,7 +741,7 @@ version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi", "libc", ] @@ -551,6 +751,12 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking_lot" version = "0.12.1" @@ -571,7 +777,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -612,27 +818,23 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "pretty_env_logger" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c" -dependencies = [ - "env_logger", - "log", -] - [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -685,37 +887,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "regex" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" - -[[package]] -name = "rustix" -version = "0.36.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys", - "windows-sys", -] - [[package]] name = "rustversion" version = "1.0.9" @@ -745,9 +916,23 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.148" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] [[package]] name = "serde_json" @@ -769,6 +954,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" @@ -781,6 +975,44 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.2", + "indexmap 2.0.2", + "serde", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -815,6 +1047,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "1.0.104" @@ -828,9 +1066,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.22" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -844,12 +1082,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" [[package]] -name = "termcolor" -version = "1.1.3" +name = "thread_local" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ - "winapi-util", + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +dependencies = [ + "deranged", + "itoa", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +dependencies = [ + "time-core", ] [[package]] @@ -905,13 +1173,47 @@ dependencies = [ "futures-io", "futures-sink", "futures-util", - "hashbrown", + "hashbrown 0.12.3", "pin-project-lite", "slab", "tokio", "tracing", ] +[[package]] +name = "toml" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +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.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.0.2", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -968,9 +1270,21 @@ dependencies = [ "cfg-if", "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "tracing-core" version = "0.1.30" @@ -978,6 +1292,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", ] [[package]] @@ -992,6 +1332,18 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version_check" version = "0.9.4" @@ -1025,6 +1377,60 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.38", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" + [[package]] name = "winapi" version = "0.3.9" @@ -1056,19 +1462,52 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" 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]] @@ -1077,38 +1516,95 @@ 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.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" +dependencies = [ + "memchr", +] + +[[package]] +name = "xxhash-rust" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9828b178da53440fa9c766a3d2f73f7cf5d0ac1fe3980c1e5018d899fd19e07b" diff --git a/Cargo.toml b/Cargo.toml index 1004c6a..6f4985e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "breeze" -version = "0.1.4" +version = "0.1.5" edition = "2021" [dependencies] @@ -15,6 +15,11 @@ rand = "0.8.5" async-recursion = "1.0.0" walkdir = "2" futures = "0.3" -log = "0.4" -pretty_env_logger = "0.5.0" +tracing = "0.1" +tracing-subscriber = "0.3" archived = { path = "./archived" } +xxhash-rust = { version = "0.8.7", features = ["xxh3"] } +serde = { version = "1.0.189", features = ["derive"] } +toml = "0.8.2" +clap = { version = "4.4.6", features = ["derive"] } +serde_with = "3.4.0" diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..2b087ce --- /dev/null +++ b/src/config.rs @@ -0,0 +1,55 @@ +use std::{path::PathBuf, time::Duration}; + +use serde::Deserialize; +use serde_with::{serde_as, DisplayFromStr, DurationSeconds}; +use tracing_subscriber::filter::LevelFilter; + +#[derive(Deserialize)] +pub struct Config { + pub engine: EngineConfig, + pub cache: CacheConfig, + pub logger: LoggerConfig, +} + +#[derive(Deserialize)] +pub struct EngineConfig { + /// The url that the instance of breeze is meant to be accessed from. + /// + /// ex: https://picture.wtf would generate links like https://picture.wtf/p/abcdef.png + pub base_url: String, + + /// Location on disk the uploads are to be saved to + pub save_path: PathBuf, + + /// Authentication key for new uploads, will be required if this is specified. (optional) + pub upload_key: Option, +} + +#[serde_as] +#[derive(Deserialize)] +pub struct CacheConfig { + /// The maximum length in bytes that a file can be + /// before it skips cache (in seconds) + pub max_length: usize, + + /// The amount of time a file can last inside the cache (in seconds) + #[serde_as(as = "DurationSeconds")] + pub upload_lifetime: Duration, + + /// How often the cache is to be scanned for + /// expired entries (in seconds) + #[serde_as(as = "DurationSeconds")] + pub scan_freq: Duration, + + /// How much memory the cache is allowed to use (in bytes) + pub mem_capacity: usize, +} + +#[serde_as] +#[derive(Deserialize)] +pub struct LoggerConfig { + /// Minimum level a log must be for it to be shown. + /// This defaults to "warn" if not specified. + #[serde_as(as = "Option")] + pub level: Option, +} diff --git a/src/engine.rs b/src/engine.rs index b21a19c..69272cb 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -18,25 +18,40 @@ use tokio::{ }, }; use tokio_stream::StreamExt; +use tracing::{debug, error, info}; use walkdir::WalkDir; use crate::view::{ViewError, ViewSuccess}; +/// breeze engine! this is the core of everything pub struct Engine { - // state - cache: RwLock, // in-memory cache - pub upl_count: AtomicUsize, // cached count of uploaded files + // ------ STATE ------ // + /// The in-memory cache that cached uploads are stored in. + cache: RwLock, - // config - pub base_url: String, // base url for formatting upload urls - save_path: PathBuf, // where uploads are saved to disk - pub upload_key: String, // authorisation key for uploading new files + /// Cached count of uploaded files. + pub upl_count: AtomicUsize, - cache_max_length: usize, // if an upload is bigger than this size, it won't be cached + // ------ CONFIG ------ // + /// The base URL that the server will be accessed from. + /// It is only used for formatting returned upload URLs. + pub base_url: String, + + /// The path on disk that uploads are saved to. + save_path: PathBuf, + + /// The authorisation key required for uploading new files. + /// If it is empty, no key will be required. + pub upload_key: String, + + /// The maximum size for an upload to be stored in cache. + /// Anything bigger skips cache and is read/written to + /// directly from disk. + cache_max_length: usize, } impl Engine { - // create a new engine + /// Creates a new instance of the breeze engine. pub fn new( base_url: String, save_path: PathBuf, @@ -62,26 +77,29 @@ impl Engine { } } + /// Returns if an upload would be able to be cached + #[inline(always)] fn will_use_cache(&self, length: usize) -> bool { length <= self.cache_max_length } - // checks in cache or disk for an upload using a pathbuf + /// Check if an upload exists in cache or on disk pub async fn upload_exists(&self, path: &Path) -> bool { let cache = self.cache.read().await; - // check if upload is in cache + // extract file name, since that's what cache uses let name = path .file_name() .and_then(OsStr::to_str) .unwrap_or_default() .to_string(); + // check in cache if cache.contains_key(&name) { return true; } - // check if upload is on disk + // check on disk if path.exists() { return true; } @@ -89,7 +107,10 @@ impl Engine { return false; } - // generate a new save path for an upload + /// Generate a new save path for an upload. + /// + /// This will call itself recursively if it picks + /// a name that's already used. (it is rare) #[async_recursion::async_recursion] pub async fn gen_path(&self, original_path: &PathBuf) -> PathBuf { // generate a 6-character alphanumeric string @@ -119,7 +140,8 @@ impl Engine { } } - // process an upload. this is called by the new route + /// Process an upload. + /// This is called by the /new route. pub async fn process_upload( &self, path: PathBuf, @@ -193,25 +215,20 @@ impl Engine { self.upl_count.fetch_add(1, Ordering::Relaxed); } - // read an upload from cache, if it exists - // previously, this would lock the cache as writable to renew the upload's cache lifespan - // locking the cache as readable allows multiple concurrent readers, which allows me to handle multiple views concurrently + /// Read an upload from cache, if it exists. + /// + /// Previously, this would lock the cache as + /// writable to renew the upload's cache lifespan. + /// Locking the cache as readable allows multiple concurrent + /// readers though, which allows me to handle multiple views concurrently. async fn read_cached_upload(&self, name: &String) -> Option { let cache = self.cache.read().await; - if !cache.contains_key(name) { - return None; - } - // fetch upload data from cache - let data = cache - .get(name) - .expect("failed to read get upload data from cache") - .to_owned(); - - Some(data) + cache.get(name).map(ToOwned::to_owned) } + /// Reads an upload, from cache or on disk. pub async fn get_upload(&self, original_path: &Path) -> Result { // extract upload file name let name = original_path @@ -233,18 +250,24 @@ impl Engine { let cached_data = self.read_cached_upload(&name).await; if let Some(data) = cached_data { - info!("got upload from cache!!"); + info!("got upload from cache!"); Ok(ViewSuccess::FromCache(data)) } else { + // we already know the upload exists by now so this is okay let mut file = File::open(&path).await.unwrap(); // read upload length from disk - let length = file - .metadata() - .await - .expect("failed to read upload file metadata") - .len() as usize; + let metadata = file.metadata().await; + + if metadata.is_err() { + error!("failed to get upload file metadata!"); + return Err(ViewError::InternalServerError); + } + + let metadata = metadata.unwrap(); + + let length = metadata.len() as usize; debug!("read upload from disk, size = {}", length); diff --git a/src/index.rs b/src/index.rs index a6de3e3..5a1a9b8 100644 --- a/src/index.rs +++ b/src/index.rs @@ -2,20 +2,16 @@ use std::sync::{atomic::Ordering, Arc}; use axum::extract::State; -// show index status page with amount of uploaded files +/// Show index status page with amount of uploaded files pub async fn index(State(engine): State>) -> String { let count = engine.upl_count.load(Ordering::Relaxed); format!("minish's image host, currently hosting {} files", count) } -// robots.txt that tells web crawlers not to list uploads -const ROBOTS_TXT: &str = concat!( - "User-Agent: *\n", - "Disallow: /p/*\n", - "Allow: /\n" -); - pub async fn robots_txt() -> &'static str { + /// robots.txt that tells web crawlers not to list uploads + const ROBOTS_TXT: &str = concat!("User-Agent: *\n", "Disallow: /p/*\n", "Allow: /\n"); + ROBOTS_TXT -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 5f599cc..d7b8069 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,62 +1,63 @@ -use std::{env, path::PathBuf, sync::Arc, time::Duration}; +use std::{path::PathBuf, sync::Arc}; extern crate axum; -#[macro_use] -extern crate log; - +use clap::Parser; use engine::Engine; use axum::{ routing::{get, post}, Router, }; -use tokio::signal; +use tokio::{fs, signal}; +use tracing::{info, warn}; +use tracing_subscriber::filter::LevelFilter; +mod config; mod engine; mod index; mod new; mod view; +#[derive(Parser, Debug)] +struct Args { + /// The path to configuration file + config: Option, +} + #[tokio::main] async fn main() { - // initialise logger - pretty_env_logger::init(); + // read & parse args + let args = Args::parse(); - // read env vars - let base_url = env::var("BRZ_BASE_URL").expect("missing BRZ_BASE_URL! base url for upload urls (ex: http://127.0.0.1:8000 for http://127.0.0.1:8000/p/abcdef.png, http://picture.wtf for http://picture.wtf/p/abcdef.png)"); - let save_path = env::var("BRZ_SAVE_PATH").expect("missing BRZ_SAVE_PATH! this should be a path where uploads are saved to disk (ex: /srv/uploads, C:\\brzuploads)"); - let upload_key = env::var("BRZ_UPLOAD_KEY").unwrap_or_default(); - let cache_max_length = env::var("BRZ_CACHE_UPL_MAX_LENGTH").expect("missing BRZ_CACHE_UPL_MAX_LENGTH! this is the max length an upload can be in bytes before it won't be cached (ex: 80000000 for 80MB)"); - let cache_upl_lifetime = env::var("BRZ_CACHE_UPL_LIFETIME").expect("missing BRZ_CACHE_UPL_LIFETIME! this indicates how long an upload will stay in cache (ex: 1800 for 30 minutes, 60 for 1 minute)"); - let cache_scan_freq = env::var("BRZ_CACHE_SCAN_FREQ").expect("missing BRZ_CACHE_SCAN_FREQ! this is the frequency of full cache scans, which scan for and remove expired uploads (ex: 60 for 1 minute)"); - let cache_mem_capacity = env::var("BRZ_CACHE_MEM_CAPACITY").expect("missing BRZ_CACHE_MEM_CAPACITY! this is the amount of memory the cache will hold before dropping entries"); + // read & parse config + let config_str = fs::read_to_string(args.config.unwrap_or("./breeze.toml".into())) + .await + .expect("failed to read config file! make sure it exists and you have read permissions"); - // parse env vars - let save_path = PathBuf::from(save_path); - let cache_max_length = cache_max_length.parse::().expect("failed parsing BRZ_CACHE_UPL_MAX_LENGTH! it should be a positive number without any separators"); - let cache_upl_lifetime = Duration::from_secs(cache_upl_lifetime.parse::().expect("failed parsing BRZ_CACHE_UPL_LIFETIME! it should be a positive number without any separators")); - let cache_scan_freq = Duration::from_secs(cache_scan_freq.parse::().expect("failed parsing BRZ_CACHE_SCAN_FREQ! it should be a positive number without any separators")); - let cache_mem_capacity = cache_mem_capacity.parse::().expect("failed parsing BRZ_CACHE_MEM_CAPACITY! it should be a positive number without any separators"); + let c: config::Config = toml::from_str(&config_str).expect("invalid config! check that you have included all required options and structured it properly (no config options expecting a number getting a string, etc.)"); - if !save_path.exists() || !save_path.is_dir() { + tracing_subscriber::fmt() + .with_max_level(c.logger.level.unwrap_or(LevelFilter::WARN)) + .init(); + + if !c.engine.save_path.exists() || !c.engine.save_path.is_dir() { panic!("the save path does not exist or is not a directory! this is invalid"); } - if upload_key.is_empty() { - // i would prefer this to be a warning but the default log level hides those - error!("upload key (BRZ_UPLOAD_KEY) is empty! no key will be required for uploading new files"); + if c.engine.upload_key.is_none() { + warn!("engine upload_key is empty! no key will be required for uploading new files"); } // create engine let engine = Engine::new( - base_url, - save_path, - upload_key, - cache_max_length, - cache_upl_lifetime, - cache_scan_freq, - cache_mem_capacity, + c.engine.base_url, + c.engine.save_path, + c.engine.upload_key.unwrap_or_default(), + c.cache.max_length, + c.cache.upload_lifetime, + c.cache.scan_freq, + c.cache.mem_capacity, ); // build main router @@ -99,4 +100,4 @@ async fn shutdown_signal() { } info!("shutting down!"); -} \ No newline at end of file +} diff --git a/src/new.rs b/src/new.rs index b7d6f59..d1fba6a 100644 --- a/src/new.rs +++ b/src/new.rs @@ -6,17 +6,21 @@ use axum::{ }; use hyper::{header, HeaderMap, StatusCode}; +/// The request handler for the /new path. +/// This handles all new uploads. #[axum::debug_handler] pub async fn new( State(engine): State>, - headers: HeaderMap, Query(params): Query>, + headers: HeaderMap, stream: BodyStream, ) -> Result { let key = params.get("key"); + const EMPTY_STRING: &String = &String::new(); + // check upload key, if i need to - if !engine.upload_key.is_empty() && key.unwrap_or(&String::new()) != &engine.upload_key { + if !engine.upload_key.is_empty() && key.unwrap_or(EMPTY_STRING) != &engine.upload_key { return Err(StatusCode::FORBIDDEN); } diff --git a/src/view.rs b/src/view.rs index f4bc7d9..40e00d8 100644 --- a/src/view.rs +++ b/src/view.rs @@ -13,22 +13,43 @@ use bytes::Bytes; use hyper::{http::HeaderValue, StatusCode}; use tokio::{fs::File, runtime::Handle}; use tokio_util::io::ReaderStream; +use tracing::{error, debug, warn}; +/// Responses for a successful view operation pub enum ViewSuccess { + /// A file read from disk, suitable for larger files. + /// + /// The file provided will be streamed from disk and + /// back to the viewer. + /// + /// This is only ever used if a file exceeds the + /// cache's maximum file size. FromDisk(File), + + /// A file read from in-memory cache, best for smaller files. + /// + /// The file is taken from the cache in its entirety + /// and sent back to the viewer. + /// + /// If a file can be fit into cache, this will be + /// used even if it's read from disk. FromCache(Bytes), } +/// Responses for a failed view operation pub enum ViewError { - NotFound, // 404 - InternalServerError, // 500 + /// Will send status code 404 witha plaintext "not found" message. + NotFound, + + /// Will send status code 500 with a plaintext "internal server error" message. + InternalServerError, } impl IntoResponse for ViewSuccess { fn into_response(self) -> Response { match self { ViewSuccess::FromDisk(file) => { - // get handle to current runtime + // get handle to current tokio runtime // i use this to block on futures here (not async) let handle = Handle::current(); let _ = handle.enter(); @@ -88,24 +109,21 @@ impl IntoResponse for ViewSuccess { impl IntoResponse for ViewError { fn into_response(self) -> Response { match self { - ViewError::NotFound => { - // convert string into response, change status code - let mut res = "not found!".into_response(); - *res.status_mut() = StatusCode::NOT_FOUND; - - res - } - ViewError::InternalServerError => { - // convert string into response, change status code - let mut res = "internal server error!".into_response(); - *res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - - res - } + ViewError::NotFound => ( + StatusCode::NOT_FOUND, + "not found!" + ).into_response(), + + ViewError::InternalServerError => ( + StatusCode::INTERNAL_SERVER_ERROR, + "internal server error!" + ).into_response(), } } } +/// The request handler for /p/* path. +/// All file views are handled here. #[axum::debug_handler] pub async fn view( State(engine): State>,