Compare commits

...

10 Commits

Author SHA1 Message Date
Dmitry Belyaev 5da53f79e4
fix 500 template title
continuous-integration/drone/push Build is passing Details
2023-08-20 16:24:35 +03:00
Dmitry Belyaev f1900fc24a
add link to json
continuous-integration/drone/push Build is passing Details
2023-08-20 14:12:39 +03:00
Dmitry Belyaev a0853ed3de
static template context for errors
continuous-integration/drone/push Build is passing Details
2023-08-20 13:44:17 +03:00
Dmitry Belyaev cae6b0c97f
add json routes 2023-08-20 13:17:52 +03:00
Dmitry Belyaev 9c3a016c82
disable index on static/ file server 2023-08-20 12:11:09 +03:00
Dmitry Belyaev 28c01a7fc6
add 500 catcher 2023-08-20 12:10:11 +03:00
Dmitry Belyaev 05073604a9
improve 404 catcher 2023-08-20 11:52:39 +03:00
Dmitry Belyaev b394c7e0f8
update 404 template 2023-08-20 11:51:50 +03:00
Dmitry Belyaev d63bc7a758
fix rating field in answer template
continuous-integration/drone/push Build is passing Details
2023-08-18 22:26:30 +03:00
Dmitry Belyaev da962a9f7a
v0.2.0
continuous-integration/drone/push Build is passing Details
2023-08-18 11:14:36 +03:00
6 changed files with 248 additions and 135 deletions

224
Cargo.lock generated
View File

@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.0.2"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41"
checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a"
dependencies = [
"memchr",
]
@ -74,18 +74,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
name = "async-trait"
version = "0.1.72"
version = "0.1.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09"
checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
@ -148,9 +148,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.3.3"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
[[package]]
name = "block-buffer"
@ -228,9 +228,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.81"
version = "1.0.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c6b2562119bf28c3439f7f02db99faf0aa1a8cdfe5772a2ee155d32227239f0"
checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01"
dependencies = [
"jobserver",
"libc",
@ -401,11 +401,11 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35b50dba0afdca80b187392b24f2499a88c336d5a8493e4b4ccfb608708be56a"
dependencies = [
"bitflags 2.3.3",
"bitflags 2.4.0",
"proc-macro2",
"proc-macro2-diagnostics",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
@ -442,7 +442,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
@ -554,7 +554,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eeb4ed9e12f43b7fa0baae3f9cdda28352770132ef2e09a23760c29cae8bd47"
dependencies = [
"async-trait",
"rustix 0.38.6",
"rustix 0.38.8",
"tokio",
"windows-sys 0.48.0",
]
@ -624,7 +624,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
@ -794,9 +794,9 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
[[package]]
name = "httpdate"
version = "1.0.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "humansize"
@ -824,7 +824,7 @@ dependencies = [
"httpdate",
"itoa",
"pin-project-lite",
"socket2",
"socket2 0.4.9",
"tokio",
"tower-service",
"tracing",
@ -931,7 +931,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
dependencies = [
"hermit-abi",
"rustix 0.38.6",
"rustix 0.38.8",
"windows-sys 0.48.0",
]
@ -961,9 +961,9 @@ dependencies = [
[[package]]
name = "kqueue"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c8fc60ba15bf51257aa9807a48a61013db043fcf3a78cb0d916e8e396dcad98"
checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c"
dependencies = [
"kqueue-sys",
"libc",
@ -971,9 +971,9 @@ dependencies = [
[[package]]
name = "kqueue-sys"
version = "1.0.3"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587"
checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b"
dependencies = [
"bitflags 1.3.2",
"libc",
@ -1021,9 +1021,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.19"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "loom"
@ -1072,9 +1072,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mini-moka"
version = "0.10.1"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "452ebc1428a585e31e637b928b76355ef2fd72d765b2530d72fe475e514cd1eb"
checksum = "23e0b72e7c9042467008b10279fc732326bd605459ae03bda88825909dd19b56"
dependencies = [
"crossbeam-channel",
"crossbeam-utils",
@ -1223,7 +1223,7 @@ dependencies = [
"libc",
"redox_syscall",
"smallvec",
"windows-targets 0.48.1",
"windows-targets 0.48.3",
]
[[package]]
@ -1269,7 +1269,7 @@ checksum = "61a386cd715229d399604b50d1361683fe687066f42d56f54be995bc6868f71c"
dependencies = [
"inlinable_string",
"pear_codegen",
"yansi 1.0.0-rc",
"yansi 1.0.0-rc.1",
]
[[package]]
@ -1281,7 +1281,7 @@ dependencies = [
"proc-macro2",
"proc-macro2-diagnostics",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
@ -1320,7 +1320,7 @@ dependencies = [
"pest_meta",
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
@ -1390,14 +1390,14 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
name = "pin-project-lite"
version = "0.2.10"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57"
checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05"
[[package]]
name = "pin-utils"
@ -1434,9 +1434,9 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
"version_check",
"yansi 1.0.0-rc",
"yansi 1.0.0-rc.1",
]
[[package]]
@ -1452,9 +1452,10 @@ dependencies = [
[[package]]
name = "qchgk_web"
version = "0.1.1"
version = "0.2.0"
dependencies = [
"chgk_ledb_lib",
"lazy_static",
"mini-moka",
"rand",
"rocket",
@ -1463,9 +1464,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.32"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
@ -1511,33 +1512,33 @@ dependencies = [
[[package]]
name = "ref-cast"
version = "1.0.19"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61ef7e18e8841942ddb1cf845054f8008410030a3997875d9e49b7a363063df1"
checksum = "acde58d073e9c79da00f2b5b84eed919c8326832648a5b109b3fce1bb1175280"
dependencies = [
"ref-cast-impl",
]
[[package]]
name = "ref-cast-impl"
version = "1.0.19"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfaf0c85b766276c797f3791f5bc6d5bd116b41d53049af2789666b0c0bc9fa"
checksum = "7f7473c2cfcf90008193dd0e3e16599455cb601a9fce322b5bb55de799664925"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
name = "regex"
version = "1.9.1"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575"
checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata 0.3.4",
"regex-automata 0.3.6",
"regex-syntax 0.7.4",
]
@ -1552,9 +1553,9 @@ dependencies = [
[[package]]
name = "regex-automata"
version = "0.3.4"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294"
checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69"
dependencies = [
"aho-corasick",
"memchr",
@ -1624,7 +1625,7 @@ dependencies = [
"proc-macro2",
"quote",
"rocket_http",
"syn 2.0.28",
"syn 2.0.29",
"unicode-xid",
]
@ -1690,11 +1691,11 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.6"
version = "0.38.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ee020b1716f0a80e2ace9b03441a749e402e86712f15f16fe8a8f75afac732f"
checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f"
dependencies = [
"bitflags 2.3.3",
"bitflags 2.4.0",
"errno 0.3.2",
"libc",
"linux-raw-sys 0.4.5",
@ -1745,29 +1746,29 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.181"
version = "1.0.183"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d3e73c93c3240c0bda063c239298e633114c69a888c3e37ca8bb33f343e9890"
checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.181"
version = "1.0.183"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be02f6cb0cd3a5ec20bbcfbcbd749f57daddb1a0882dc2e46a6c236c90b977ed"
checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
name = "serde_json"
version = "1.0.104"
version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c"
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
dependencies = [
"itoa",
"ryu",
@ -1867,6 +1868,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "socket2"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877"
dependencies = [
"libc",
"windows-sys 0.48.0",
]
[[package]]
name = "spin"
version = "0.9.8"
@ -1927,9 +1938,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.28"
version = "2.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567"
checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a"
dependencies = [
"proc-macro2",
"quote",
@ -1944,14 +1955,14 @@ checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
[[package]]
name = "tempfile"
version = "3.7.0"
version = "3.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998"
checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651"
dependencies = [
"cfg-if",
"fastrand",
"redox_syscall",
"rustix 0.38.6",
"rustix 0.38.8",
"windows-sys 0.48.0",
]
@ -1980,22 +1991,22 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.44"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90"
checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.44"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96"
checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
@ -2037,11 +2048,10 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.29.1"
version = "1.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da"
checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9"
dependencies = [
"autocfg",
"backtrace",
"bytes",
"libc",
@ -2049,7 +2059,7 @@ dependencies = [
"num_cpus",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"socket2 0.5.3",
"tokio-macros",
"windows-sys 0.48.0",
]
@ -2062,7 +2072,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
@ -2150,7 +2160,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
]
[[package]]
@ -2370,7 +2380,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
"wasm-bindgen-shared",
]
@ -2392,7 +2402,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.29",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -2440,7 +2450,7 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets 0.48.1",
"windows-targets 0.48.3",
]
[[package]]
@ -2473,7 +2483,7 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.1",
"windows-targets 0.48.3",
]
[[package]]
@ -2493,17 +2503,17 @@ dependencies = [
[[package]]
name = "windows-targets"
version = "0.48.1"
version = "0.48.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f"
checksum = "27f51fb4c64f8b770a823c043c7fad036323e1c48f55287b7bbb7987b2fcdf3b"
dependencies = [
"windows_aarch64_gnullvm 0.48.0",
"windows_aarch64_msvc 0.48.0",
"windows_i686_gnu 0.48.0",
"windows_i686_msvc 0.48.0",
"windows_x86_64_gnu 0.48.0",
"windows_x86_64_gnullvm 0.48.0",
"windows_x86_64_msvc 0.48.0",
"windows_aarch64_gnullvm 0.48.3",
"windows_aarch64_msvc 0.48.3",
"windows_i686_gnu 0.48.3",
"windows_i686_msvc 0.48.3",
"windows_x86_64_gnu 0.48.3",
"windows_x86_64_gnullvm 0.48.3",
"windows_x86_64_msvc 0.48.3",
]
[[package]]
@ -2514,9 +2524,9 @@ checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.0"
version = "0.48.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
checksum = "fde1bb55ae4ce76a597a8566d82c57432bc69c039449d61572a7a353da28f68c"
[[package]]
name = "windows_aarch64_msvc"
@ -2526,9 +2536,9 @@ checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.0"
version = "0.48.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
checksum = "1513e8d48365a78adad7322fd6b5e4c4e99d92a69db8df2d435b25b1f1f286d4"
[[package]]
name = "windows_i686_gnu"
@ -2538,9 +2548,9 @@ checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_gnu"
version = "0.48.0"
version = "0.48.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
checksum = "60587c0265d2b842298f5858e1a5d79d146f9ee0c37be5782e92a6eb5e1d7a83"
[[package]]
name = "windows_i686_msvc"
@ -2550,9 +2560,9 @@ checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_i686_msvc"
version = "0.48.0"
version = "0.48.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
checksum = "224fe0e0ffff5d2ea6a29f82026c8f43870038a0ffc247aa95a52b47df381ac4"
[[package]]
name = "windows_x86_64_gnu"
@ -2562,9 +2572,9 @@ checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.0"
version = "0.48.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
checksum = "62fc52a0f50a088de499712cbc012df7ebd94e2d6eb948435449d76a6287e7ad"
[[package]]
name = "windows_x86_64_gnullvm"
@ -2574,9 +2584,9 @@ checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.0"
version = "0.48.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
checksum = "2093925509d91ea3d69bcd20238f4c2ecdb1a29d3c281d026a09705d0dd35f3d"
[[package]]
name = "windows_x86_64_msvc"
@ -2586,15 +2596,15 @@ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.0"
version = "0.48.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
checksum = "b6ade45bc8bf02ae2aa34a9d54ba660a1a58204da34ba793c00d83ca3730b5f1"
[[package]]
name = "winnow"
version = "0.5.4"
version = "0.5.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acaaa1190073b2b101e15083c38ee8ec891b5e05cbee516521e94ec008f61e64"
checksum = "d09770118a7eb1ccaf4a594a221334119a44a814fcb0d31c5b85e83e97227a97"
dependencies = [
"memchr",
]
@ -2607,9 +2617,9 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
[[package]]
name = "yansi"
version = "1.0.0-rc"
version = "1.0.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ee746ad3851dd3bc40e4a028ab3b00b99278d929e48957bcb2d111874a7e43e"
checksum = "1367295b8f788d371ce2dbc842c7b709c73ee1364d30351dd300ec2203b12377"
[[package]]
name = "zstd"

View File

@ -1,6 +1,6 @@
[package]
name = "qchgk_web"
version = "0.1.1"
version = "0.2.0"
authors = ["Dmitry <b4tm4n@mail.ru>"]
edition = "2021"
license = "MIT"
@ -15,6 +15,7 @@ rocket = { version = "=0.5.0-rc.3", features = ["json"] }
rocket_dyn_templates = { version = "=0.1.0-rc.3", features = ["tera"] }
chgk_ledb_lib = {git = "https://gitea.b4tman.ru/b4tman/chgk_ledb.git", rev="699478f85e", package="chgk_ledb_lib", features=["async"]}
mini-moka = "0.10.0"
lazy_static = "1.4.0"
[profile.release]
opt-level = 3

View File

@ -2,7 +2,11 @@
extern crate rocket;
use rocket::fs::FileServer;
use rocket::fs::Options;
use rocket::http::ContentType;
use rocket::request::Request;
use rocket::response::Redirect;
use rocket::response::{self, Responder, Response};
use rocket::State;
use rocket_dyn_templates::tera;
use rocket_dyn_templates::Template;
@ -10,6 +14,8 @@ use rocket_dyn_templates::Template;
use rand::distributions::Uniform;
use rand::Rng;
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::ops::Deref;
use std::sync::Arc;
@ -21,6 +27,10 @@ use std::time::Duration;
const DB_FILENAME: &str = "db.dat";
lazy_static! {
static ref EMPTY_MAP: HashMap<String, String> = HashMap::new();
}
trait ErrorEmpty {
type Output;
fn err_empty(self) -> Result<Self::Output, ()>;
@ -33,11 +43,38 @@ impl<T, E> ErrorEmpty for Result<T, E> {
}
}
#[derive(Debug, Responder)]
enum WebError {
#[response(status = 404)]
NotFound(Template),
#[response(status = 500)]
ServerError(Template),
}
impl WebError {
fn not_found() -> Self {
WebError::NotFound(Template::render("404", EMPTY_MAP.deref()))
}
fn server_error() -> Self {
WebError::ServerError(Template::render("500", EMPTY_MAP.deref()))
}
}
/// wrapper for terra:Value (json, context), to cache values by ref
/// implements Responder as json content type
#[derive(Clone)]
struct ArcTemplateData {
value: Arc<tera::Value>,
}
impl Deref for ArcTemplateData {
type Target = tera::Value;
fn deref(&self) -> &Self::Target {
self.value.deref()
}
}
impl ArcTemplateData {
fn new(value: tera::Value) -> ArcTemplateData {
ArcTemplateData {
@ -45,7 +82,15 @@ impl ArcTemplateData {
}
}
fn render(&self, name: &'static str) -> Template {
Template::render(name, self.value.deref())
Template::render(name, self.deref())
}
}
impl<'r> Responder<'r, 'static> for ArcTemplateData {
fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> {
Response::build_from(self.to_string().respond_to(req)?)
.header(ContentType::JSON)
.ok()
}
}
@ -80,14 +125,13 @@ async fn get_question(db: &DataBase, id: usize) -> Result<Question, ()> {
db.get(id - 1).await.err_empty()
}
async fn show_question_details(
template_name: &'static str,
async fn get_question_data(
data: &AppState,
cache: &TemplateCache,
id: usize,
) -> Template {
) -> Option<ArcTemplateData> {
if let Some(value) = cache.get(&id) {
return value.render(template_name);
return Some(value);
}
match get_question(&data.db, id).await {
@ -98,31 +142,49 @@ async fn show_question_details(
context["next"] = tera::to_value(next_id).expect("question id serialize");
}
let value = ArcTemplateData::new(context);
let result = value.render(template_name);
cache.insert(id, value);
result
}
Err(_) => {
use std::collections::HashMap;
let context: HashMap<String, String> = HashMap::new();
Template::render("404", context)
let data = ArcTemplateData::new(context);
cache.insert(id, data.clone());
Some(data)
}
Err(_) => None,
}
}
async fn show_question_details(
template_name: &'static str,
data: &AppState,
cache: &TemplateCache,
id: usize,
) -> Option<Template> {
get_question_data(data, cache, id)
.await
.map(|data| data.render(template_name))
}
#[get("/q/<id>/json")]
async fn json_question(
data: &State<AppState>,
cache: &State<TemplateCache>,
id: usize,
) -> Option<ArcTemplateData> {
get_question_data(data.inner(), cache.inner(), id).await
}
#[get("/q/<id>")]
async fn show_question(
data: &State<AppState>,
cache: &State<TemplateCache>,
id: usize,
) -> Template {
) -> Option<Template> {
show_question_details("question", data.inner(), cache.inner(), id).await
}
#[get("/q/<id>/a")]
async fn show_answer(data: &State<AppState>, cache: &State<TemplateCache>, id: usize) -> Template {
async fn show_answer(
data: &State<AppState>,
cache: &State<TemplateCache>,
id: usize,
) -> Option<Template> {
show_question_details("answer", data.inner(), cache.inner(), id).await
}
@ -136,6 +198,12 @@ fn answer0() -> Redirect {
Redirect::to("/")
}
#[get("/q/0/json")]
fn json0(data: &State<AppState>) -> Redirect {
let id = random_question_id(&data.database_distribution);
Redirect::temporary(format!("/q/{}/json", id))
}
#[get("/")]
fn index(data: &State<AppState>) -> Redirect {
let id = random_question_id(&data.database_distribution);
@ -143,10 +211,13 @@ fn index(data: &State<AppState>) -> Redirect {
}
#[catch(404)]
fn not_found(_req: &rocket::Request) -> Template {
use std::collections::HashMap;
let context: HashMap<String, String> = HashMap::new();
Template::render("404", context)
fn not_found(_req: &rocket::Request) -> WebError {
WebError::not_found()
}
#[catch(500)]
fn server_error(_req: &rocket::Request) -> WebError {
WebError::server_error()
}
#[launch]
@ -163,12 +234,20 @@ async fn rocket() -> _ {
rocket::build()
.manage(state)
.manage(cache)
.register("/", catchers![not_found])
.register("/", catchers![not_found, server_error])
.mount(
"/",
routes![index, show_question, show_answer, question0, answer0],
routes![
index,
json_question,
show_question,
show_answer,
question0,
answer0,
json0
],
)
.mount("/q", routes![index])
.mount("/q/static", FileServer::from("static/"))
.mount("/q/static", FileServer::new("static/", Options::None))
.attach(Template::fairing())
}

View File

@ -1,5 +1,13 @@
{% extends "base" %}
{% block title %}404{% endblock title %}
{% block nav %}
{% endblock nav %}
{% block content %}
<h1>404 - Could not find that page</h1>
<div class="content-block">
<div class="content-block-inner mt-4 px-4 py-2 fs-1 top-50 start-50 translate-middle">
<h1 class="display-4 d-flex justify-content-center text-center fw-bold">404</h1>
<br/>
<p>Нет такой страницы &#128532;</p>
</div>
</div>
{% endblock content %}

13
templates/500.html.tera Normal file
View File

@ -0,0 +1,13 @@
{% extends "base" %}
{% block title %}500{% endblock title %}
{% block nav %}
{% endblock nav %}
{% block content %}
<div class="content-block">
<div class="content-block-inner mt-4 px-4 py-2 fs-1 top-50 start-50 translate-middle">
<h1 class="display-4 d-flex justify-content-center text-center fw-bold">500</h1>
<br/>
<p>&#128558; Ой, кажется у нас тут что то сломалось...</p>
</div>
</div>
{% endblock content %}

View File

@ -42,7 +42,7 @@
<p><span>Тема: </span> {{ theme }}</p>
{% endif %}
{% if rating | length %}
<p><span>Рейтинг: </span> {{ author }}</p>
<p><span>Рейтинг: </span> {{ rating }}</p>
{% endif %}
{% if batch_info.description | length %}
<p><span>Чемпионат: </span> {{ batch_info.description }}</p>
@ -53,7 +53,9 @@
{% if id | length %}
<p><span>Номер: </span> {{ id }}</p>
{% endif %}
<br/>
<p class="text-muted"> Показать как <a href="/q/{{ num }}/json">json</a></p>
</div></details>
</div>
<br />
{% endblock content %}
{% endblock content %}