Compare commits
8 Commits
cd117840bb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 26e0532600 | |||
| 1be97537c5 | |||
| f6ae33d143 | |||
| 0f5cfe71ce | |||
| 829762e7ec | |||
| 48be258c6a | |||
| cc24affb28 | |||
| 5b5c74b3fa |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -13,5 +13,4 @@ devenv.local.yaml
|
|||||||
# Added by cargo
|
# Added by cargo
|
||||||
|
|
||||||
/target
|
/target
|
||||||
/.session
|
.session
|
||||||
/frontend/.session
|
|
||||||
|
|||||||
379
Cargo.lock
generated
379
Cargo.lock
generated
@@ -2,6 +2,12 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atomic-waker"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.5.1"
|
version = "1.5.1"
|
||||||
@@ -9,11 +15,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backend"
|
name = "axum"
|
||||||
version = "0.1.0"
|
version = "0.8.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"curl",
|
"axum-core",
|
||||||
"scraper",
|
"bytes",
|
||||||
|
"form_urlencoded",
|
||||||
|
"futures-util",
|
||||||
|
"http",
|
||||||
|
"http-body",
|
||||||
|
"http-body-util",
|
||||||
|
"hyper",
|
||||||
|
"hyper-util",
|
||||||
|
"itoa",
|
||||||
|
"matchit",
|
||||||
|
"memchr",
|
||||||
|
"mime",
|
||||||
|
"percent-encoding",
|
||||||
|
"pin-project-lite",
|
||||||
|
"serde_core",
|
||||||
|
"serde_json",
|
||||||
|
"serde_path_to_error",
|
||||||
|
"serde_urlencoded",
|
||||||
|
"sync_wrapper",
|
||||||
|
"tokio",
|
||||||
|
"tower",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "axum-core"
|
||||||
|
version = "0.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
|
"http",
|
||||||
|
"http-body",
|
||||||
|
"http-body-util",
|
||||||
|
"mime",
|
||||||
|
"pin-project-lite",
|
||||||
|
"sync_wrapper",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -177,21 +227,95 @@ version = "0.1.15"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
|
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "form_urlencoded"
|
||||||
|
version = "1.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e"
|
||||||
|
dependencies = [
|
||||||
|
"percent-encoding",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "frontend"
|
name = "frontend"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backend",
|
"axum",
|
||||||
|
"curl",
|
||||||
|
"futures",
|
||||||
|
"ironhtml",
|
||||||
|
"ironhtml-elements",
|
||||||
"mlua",
|
"mlua",
|
||||||
|
"scraper",
|
||||||
|
"serde",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures"
|
||||||
|
version = "0.3.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-executor",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-channel"
|
||||||
|
version = "0.3.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-core"
|
name = "futures-core"
|
||||||
version = "0.3.34"
|
version = "0.3.34"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-executor"
|
||||||
|
version = "0.3.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 3.0.10",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-sink"
|
||||||
|
version = "0.3.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-task"
|
name = "futures-task"
|
||||||
version = "0.3.34"
|
version = "0.3.34"
|
||||||
@@ -204,8 +328,13 @@ version = "0.3.34"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-macro",
|
||||||
|
"futures-sink",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
|
"memchr",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"slab",
|
"slab",
|
||||||
]
|
]
|
||||||
@@ -230,6 +359,119 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "http"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"itoa",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "http-body"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"http",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "http-body-util"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
|
"http",
|
||||||
|
"http-body",
|
||||||
|
"pin-project-lite",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "httparse"
|
||||||
|
version = "1.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "httpdate"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyper"
|
||||||
|
version = "1.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "229c6ff5584df4c6becbfe00567128bac768c8cd32ebc8a8366bd81ed072e8f3"
|
||||||
|
dependencies = [
|
||||||
|
"atomic-waker",
|
||||||
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
|
"http",
|
||||||
|
"http-body",
|
||||||
|
"httparse",
|
||||||
|
"httpdate",
|
||||||
|
"itoa",
|
||||||
|
"pin-project-lite",
|
||||||
|
"smallvec",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyper-util"
|
||||||
|
version = "0.1.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"http",
|
||||||
|
"http-body",
|
||||||
|
"hyper",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tokio",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ironhtml"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6b1055728c74b9cf48da2139b1951aba5a85e473f9778eefbaabd4f3239afb8"
|
||||||
|
dependencies = [
|
||||||
|
"ironhtml-attributes",
|
||||||
|
"ironhtml-elements",
|
||||||
|
"ironhtml-macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ironhtml-attributes"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44d594881abb334f538a6de80f67c1cc46f7a403ed8b7741b010475910c7de25"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ironhtml-elements"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a0947a22d731427b06d249cb3c17f7fb517c4218e4f9f5a8a7e447f38e5d72d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ironhtml-macro"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b632b8eddbc93335a6a04e8026f212830cc8d5acb4726ce2f49f8b7c5ec7f51"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.119",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.19"
|
version = "1.0.19"
|
||||||
@@ -299,12 +541,24 @@ dependencies = [
|
|||||||
"web_atoms",
|
"web_atoms",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "matchit"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.8.3"
|
version = "2.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mime"
|
||||||
|
version = "0.3.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d5848f5a9e8117cf94f2f90faac24a87ff81600ff8628c1e3deaab572e76bfa1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "1.2.5"
|
version = "1.2.5"
|
||||||
@@ -361,6 +615,12 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.21.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl-probe"
|
name = "openssl-probe"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
@@ -402,6 +662,12 @@ dependencies = [
|
|||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "percent-encoding"
|
||||||
|
version = "2.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phf"
|
name = "phf"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
@@ -515,6 +781,12 @@ dependencies = [
|
|||||||
"semver",
|
"semver",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schannel"
|
name = "schannel"
|
||||||
version = "0.1.30"
|
version = "0.1.30"
|
||||||
@@ -574,6 +846,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -596,6 +869,42 @@ dependencies = [
|
|||||||
"syn 3.0.10",
|
"syn 3.0.10",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.154"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
"zmij",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_path_to_error"
|
||||||
|
version = "0.1.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_urlencoded"
|
||||||
|
version = "0.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
|
||||||
|
dependencies = [
|
||||||
|
"form_urlencoded",
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servo_arc"
|
name = "servo_arc"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -701,6 +1010,12 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sync_wrapper"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tendril"
|
name = "tendril"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@@ -738,6 +1053,54 @@ dependencies = [
|
|||||||
"syn 3.0.10",
|
"syn 3.0.10",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-util",
|
||||||
|
"pin-project-lite",
|
||||||
|
"sync_wrapper",
|
||||||
|
"tokio",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-layer"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-service"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing"
|
||||||
|
version = "0.1.44"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-core"
|
||||||
|
version = "0.1.36"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.27"
|
version = "1.0.27"
|
||||||
@@ -797,3 +1160,9 @@ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zmij"
|
||||||
|
version = "1.0.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||||
|
|||||||
18
Cargo.toml
18
Cargo.toml
@@ -1,5 +1,15 @@
|
|||||||
[workspace]
|
[package]
|
||||||
members = ["frontend", "backend"]
|
name = "frontend"
|
||||||
default-members = ["frontend"]
|
version = "0.1.0"
|
||||||
resolver = "3"
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
axum = "0.8.9"
|
||||||
|
curl = "0.4.51"
|
||||||
|
futures = "0.3.34"
|
||||||
|
ironhtml = { version = "1.0.0", features = ["macros"] }
|
||||||
|
ironhtml-elements = "1.0.0"
|
||||||
|
mlua = { version = "0.12.2", features = ["lua54", "send", "async", "vendored"] }
|
||||||
|
scraper = "0.29.0"
|
||||||
|
serde = { version = "1.0.229", features = ["derive"] }
|
||||||
|
tokio = { version = "1.54.1", features = ["full"] }
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "backend"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
curl = "0.4.51"
|
|
||||||
scraper = "0.29.0"
|
|
||||||
57
config.lua
57
config.lua
@@ -1,5 +1,5 @@
|
|||||||
local function duckduckgo(query)
|
local function duckduckgo(query)
|
||||||
local result = idx.fetchUrl("https://lite.duckduckgo.com/lite?q=" .. query)
|
local result = idx.request("https://lite.duckduckgo.com/lite?q=" .. query)
|
||||||
|
|
||||||
local htmlTree = idx.decodeHtml(result)
|
local htmlTree = idx.decodeHtml(result)
|
||||||
|
|
||||||
@@ -26,24 +26,30 @@ local function ddgBuilder(values)
|
|||||||
return "<p>" .. values.title .. "</p>"
|
return "<p>" .. values.title .. "</p>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function bingbuilder(values)
|
||||||
|
return "<p class='bing'>" .. values.title .. "</p>"
|
||||||
|
end
|
||||||
|
|
||||||
local function bing(query)
|
local function bing(query)
|
||||||
local result = idx.fetchUrl("https://www.bing.com/search?q=" .. query)
|
local result = idx.request("https://www.bing.com/search?q=" .. query)
|
||||||
|
|
||||||
local htmlTree = idx.decodeHtml(result)
|
local htmlTree = idx.decodeHtml(result)
|
||||||
local searchResults = htmlTree:filter("li.b_algo")
|
local searchResults = htmlTree:filter("li.b_algo")
|
||||||
|
|
||||||
local selected = {}
|
local selected = {}
|
||||||
|
|
||||||
for i, searchResult in ipairs(searchResults) do
|
for _, searchResult in ipairs(searchResults) do
|
||||||
local selector = {
|
local selector = {
|
||||||
source = "title",
|
source = "title",
|
||||||
title = "h2 a",
|
title = "h2 a",
|
||||||
snippet = "div.b_caption p",
|
snippet = "div.b_caption p",
|
||||||
|
url = "h2 a/href",
|
||||||
}
|
}
|
||||||
|
|
||||||
local sectionResult = searchResult:scrape(selector)
|
local selectionResult = searchResult:scrape(selector)
|
||||||
|
|
||||||
for _, value in ipairs(sectionResult) do
|
|
||||||
|
for _, value in ipairs(selectionResult) do
|
||||||
table.insert(selected, value)
|
table.insert(selected, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -51,6 +57,41 @@ local function bing(query)
|
|||||||
return selected
|
return selected
|
||||||
end
|
end
|
||||||
|
|
||||||
-- SearchEngines =
|
local function nixpkgs(query)
|
||||||
-- { duckduckgo = { grabber = duckduckgo, builder = ddgBuilder }, yahoo = { grabber = yahoo, builder = ddgBuilder } }
|
local result = idx.request("https://www.nixsearch.com/search?q=" .. query)
|
||||||
SearchEngines = { yahoo = { grabber = bing, builder = ddgBuilder } }
|
|
||||||
|
local htmlTree = idx.decodeHtml(result)
|
||||||
|
|
||||||
|
local filtered = htmlTree:filter("div.scroll table tbody tr")
|
||||||
|
|
||||||
|
print(filtered[1])
|
||||||
|
|
||||||
|
local selected = {}
|
||||||
|
|
||||||
|
for _, package in ipairs(filtered) do
|
||||||
|
local selector = {
|
||||||
|
source = "package",
|
||||||
|
package = "a",
|
||||||
|
version = "html",
|
||||||
|
}
|
||||||
|
|
||||||
|
local selectionResult = package:scrape(selector)
|
||||||
|
|
||||||
|
for _, value in ipairs(selectionResult) do
|
||||||
|
-- value["link"] = "https://search.nixos.org/packages?channel=26.05#show=" .. value.package
|
||||||
|
table.insert(selected, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return selected
|
||||||
|
end
|
||||||
|
|
||||||
|
local function nixosBuilder(values)
|
||||||
|
return "<p class='nixpkgs'>" .. values.package .. "</p>"
|
||||||
|
end
|
||||||
|
|
||||||
|
SearchEngines = {
|
||||||
|
duckduckgo = { grabber = duckduckgo, builder = ddgBuilder },
|
||||||
|
-- bing = { grabber = bing, builder = bingbuilder },
|
||||||
|
bing = bing,
|
||||||
|
-- nixpkgs = { grabber = nixpkgs, builder = nixosBuilder },
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "frontend"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
backend = {path = "../backend/"}
|
|
||||||
mlua = { version = "0.12.2", features = ["lua54", "async", "vendored"] }
|
|
||||||
tokio = { version = "1.54.1", features = ["full"] }
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
mod lua;
|
|
||||||
use lua::engine_decoder;
|
|
||||||
use lua::engine_decoder::Engine;
|
|
||||||
|
|
||||||
// use backend::return_results_vec;
|
|
||||||
use std::{env, process};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut args = env::args();
|
|
||||||
let _bin = args.next();
|
|
||||||
// let something = return_results_vec();
|
|
||||||
|
|
||||||
let mut config_location: Option<String> = None;
|
|
||||||
|
|
||||||
while let Some(arg) = args.next() {
|
|
||||||
match arg.as_str() {
|
|
||||||
"--config" | "-c" => {
|
|
||||||
config_location = args.next().or_else(|| {
|
|
||||||
eprintln!("--config needs a path");
|
|
||||||
process::exit(1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
&_ => {
|
|
||||||
eprintln!("Unknown command line option {}", arg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Long lived lua instance
|
|
||||||
let mut lua_instance = lua::create_instance();
|
|
||||||
|
|
||||||
let engine_table: mlua::Table =
|
|
||||||
lua::intialise_lua(&mut lua_instance, config_location).expect("Failed to initialise lua");
|
|
||||||
|
|
||||||
let engine_vec = engine_decoder::get_engine_vec(lua_instance, engine_table);
|
|
||||||
|
|
||||||
// for pair in search_engines.pairs::<String, mlua::Value>() {
|
|
||||||
// let (name, functions) = pair.expect("Invalid Search Engine Pair");
|
|
||||||
//
|
|
||||||
// println!("{}", name);
|
|
||||||
//
|
|
||||||
// let mut grabber_function: Option<mlua::Function> = None;
|
|
||||||
// let mut builder_function: Option<mlua::Function> = lua_instance
|
|
||||||
// .globals()
|
|
||||||
// .get("DefaultBuilder")
|
|
||||||
// .expect("Could Not Unwrap DefaultBuilder");
|
|
||||||
//
|
|
||||||
// match functions {
|
|
||||||
// // If only grabber is supplied
|
|
||||||
// mlua::Value::Function(function) => grabber_function = Some(function),
|
|
||||||
// mlua::Value::Table(table) => {
|
|
||||||
// for inner_pair in table.pairs::<String, mlua::Function>() {
|
|
||||||
// let (name, function) = inner_pair.expect("Error decoding pairs");
|
|
||||||
//
|
|
||||||
// match name.as_str() {
|
|
||||||
// "grabber" => grabber_function = Some(function),
|
|
||||||
// "builder" => builder_function = Some(function),
|
|
||||||
// _ => {}
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// _ => {
|
|
||||||
// eprintln!("Unexpected value in returned lua table")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// let results = grabber_function
|
|
||||||
// .expect("No function found")
|
|
||||||
// .call::<mlua::Table>("test");
|
|
||||||
//
|
|
||||||
// let mut built_results: Vec<String> = Vec::new();
|
|
||||||
//
|
|
||||||
// for result in results
|
|
||||||
// .expect("cannot get results")
|
|
||||||
// .sequence_values::<mlua::Table>()
|
|
||||||
// {
|
|
||||||
// let built_node = builder_function
|
|
||||||
// .clone()
|
|
||||||
// .expect("Invalid Builder Function")
|
|
||||||
// .call::<String>(result);
|
|
||||||
//
|
|
||||||
// built_results.push(built_node.expect("invalid built node"));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// println!("{:#?}", built_results)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,7 @@ pub struct Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_engine_vec(
|
pub fn get_engine_vec(
|
||||||
lua_instance: mlua::Lua,
|
lua_instance: &mut mlua::Lua,
|
||||||
engine_table: mlua::Table,
|
engine_table: mlua::Table,
|
||||||
) -> mlua::Result<Vec<Engine>> {
|
) -> mlua::Result<Vec<Engine>> {
|
||||||
let mut engine_vec: Vec<Engine> = Vec::new();
|
let mut engine_vec: Vec<Engine> = Vec::new();
|
||||||
@@ -15,8 +15,6 @@ pub fn get_engine_vec(
|
|||||||
for pair in engine_table.pairs::<String, mlua::Value>() {
|
for pair in engine_table.pairs::<String, mlua::Value>() {
|
||||||
let (name, functions) = pair.expect("Invalid Search Engine Pair");
|
let (name, functions) = pair.expect("Invalid Search Engine Pair");
|
||||||
|
|
||||||
println!("{}", name);
|
|
||||||
|
|
||||||
let mut grabber_function: Option<mlua::Function> = None;
|
let mut grabber_function: Option<mlua::Function> = None;
|
||||||
let mut builder_function: Option<mlua::Function> = lua_instance
|
let mut builder_function: Option<mlua::Function> = lua_instance
|
||||||
.globals()
|
.globals()
|
||||||
@@ -1,30 +1,37 @@
|
|||||||
use backend::scraper;
|
use crate::backend::{self, scraper};
|
||||||
use mlua::{Table, UserData, UserDataMethods};
|
use mlua::{Table, UserData, UserDataMethods};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct LuaHtml {
|
pub struct LuaHtml {
|
||||||
pub document: scraper::Html,
|
pub document: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserData for LuaHtml {
|
impl UserData for LuaHtml {
|
||||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||||
// Allow documents to be implicitly converted to strings
|
// Allow documents to be implicitly converted to strings
|
||||||
methods.add_meta_method(mlua::MetaMethod::ToString, |_, this, ()| {
|
methods.add_meta_method(mlua::MetaMethod::ToString, |_, this, ()| {
|
||||||
Ok(this.document.root_element().html())
|
let document = backend::get_sanitised_html_graph(&this.document);
|
||||||
|
Ok(document.root_element().html())
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return table of all snippets (as LuaHtml objects) matching a certain css selector
|
// Return table of all snippets (as LuaHtml objects) matching a certain css selector
|
||||||
methods.add_method("filter", |lua, this, filter: String| {
|
methods.add_method("filter", |lua, this, filter: String| {
|
||||||
|
let document = backend::get_sanitised_html_graph(&this.document);
|
||||||
let selector = scraper::Selector::parse(&filter).map_err(mlua::Error::external)?;
|
let selector = scraper::Selector::parse(&filter).map_err(mlua::Error::external)?;
|
||||||
|
|
||||||
let output = lua.create_table()?;
|
let output = lua.create_table()?;
|
||||||
|
|
||||||
for (index, element) in this.document.select(&selector).enumerate() {
|
for (index, element) in document.select(&selector).enumerate() {
|
||||||
let html = element.html();
|
let html = element.html();
|
||||||
|
|
||||||
let document = scraper::Html::parse_fragment(&html);
|
let document = scraper::Html::parse_fragment(&html);
|
||||||
|
|
||||||
output.set(index + 1, lua.create_userdata(LuaHtml { document })?)?;
|
output.set(
|
||||||
|
index + 1,
|
||||||
|
lua.create_userdata(LuaHtml {
|
||||||
|
document: document.html(),
|
||||||
|
})?,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
@@ -33,6 +40,7 @@ impl UserData for LuaHtml {
|
|||||||
// Return a table of tables matching the input schema, with all found results
|
// Return a table of tables matching the input schema, with all found results
|
||||||
// requires source attribute that matches one of the given fields, ie title
|
// requires source attribute that matches one of the given fields, ie title
|
||||||
methods.add_method("scrape", |lua, this, config: Table| {
|
methods.add_method("scrape", |lua, this, config: Table| {
|
||||||
|
let document = backend::get_sanitised_html_graph(&this.document);
|
||||||
let mut selectors = Vec::new();
|
let mut selectors = Vec::new();
|
||||||
|
|
||||||
// Determine which configured selector provides the result containers.
|
// Determine which configured selector provides the result containers.
|
||||||
@@ -68,7 +76,7 @@ impl UserData for LuaHtml {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Collect source elements.
|
// Collect source elements.
|
||||||
let source_elements: Vec<_> = this.document.select(source_selector).collect();
|
let source_elements: Vec<_> = document.select(source_selector).collect();
|
||||||
|
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
|
|
||||||
@@ -77,7 +85,7 @@ impl UserData for LuaHtml {
|
|||||||
let mut result = HashMap::new();
|
let mut result = HashMap::new();
|
||||||
|
|
||||||
for (name, selector, attribute) in &selectors {
|
for (name, selector, attribute) in &selectors {
|
||||||
let value = this.document.select(selector).nth(index);
|
let value = document.select(selector).nth(index);
|
||||||
|
|
||||||
let extracted = match (value, attribute) {
|
let extracted = match (value, attribute) {
|
||||||
(Some(element), Some(attribute)) => {
|
(Some(element), Some(attribute)) => {
|
||||||
@@ -113,8 +121,6 @@ impl UserData for LuaHtml {
|
|||||||
output.set(index + 1, result_table)?;
|
output.set(index + 1, result_table)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// println!("output {:#?}", &output);
|
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
extern crate backend;
|
use crate::backend;
|
||||||
use mlua::{Lua, Table};
|
use mlua::{Lua, Table};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
mod luahtml;
|
mod luahtml;
|
||||||
use luahtml::LuaHtml;
|
use luahtml::LuaHtml;
|
||||||
|
|
||||||
|
use ironhtml::html;
|
||||||
|
|
||||||
pub mod engine_decoder;
|
pub mod engine_decoder;
|
||||||
|
|
||||||
pub fn create_instance() -> mlua::Lua {
|
pub fn create_instance() -> mlua::Lua {
|
||||||
@@ -32,11 +34,32 @@ fn create_lua_function_table(lua: &Lua) -> mlua::Result<Table> {
|
|||||||
|
|
||||||
lua.globals().set(
|
lua.globals().set(
|
||||||
"DefaultBuilder",
|
"DefaultBuilder",
|
||||||
"function (values) return '<p>'..values.title..'</p>'",
|
lua.create_function(|_, values: Table| {
|
||||||
|
let title: String = values.get("title").unwrap();
|
||||||
|
let snippet: String = values.get("snippet").unwrap();
|
||||||
|
let url: String = values.get("url").unwrap();
|
||||||
|
|
||||||
|
let url = url.trim_matches('"').trim_matches('\\');
|
||||||
|
|
||||||
|
dbg!(&url);
|
||||||
|
|
||||||
|
let html = html! {
|
||||||
|
div {
|
||||||
|
A.href(url) {
|
||||||
|
#title.to_string()
|
||||||
|
}
|
||||||
|
P {
|
||||||
|
#snippet.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(html.render())
|
||||||
|
})?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
idx_table.set(
|
idx_table.set(
|
||||||
"fetchUrl",
|
"request",
|
||||||
lua.create_async_function(|_, url: String| async move {
|
lua.create_async_function(|_, url: String| async move {
|
||||||
let scraped_data =
|
let scraped_data =
|
||||||
tokio::task::spawn_blocking(move || backend::scrape_url_blocking(&url))
|
tokio::task::spawn_blocking(move || backend::scrape_url_blocking(&url))
|
||||||
@@ -48,10 +71,7 @@ fn create_lua_function_table(lua: &Lua) -> mlua::Result<Table> {
|
|||||||
|
|
||||||
idx_table.set(
|
idx_table.set(
|
||||||
"decodeHtml",
|
"decodeHtml",
|
||||||
lua.create_function(|_, result: String| {
|
lua.create_function(|_, result: String| Ok(LuaHtml { document: result }))?,
|
||||||
let document = backend::get_sanitised_html_graph(&result);
|
|
||||||
Ok(LuaHtml { document })
|
|
||||||
})?,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(idx_table)
|
Ok(idx_table)
|
||||||
34
src/main.rs
Normal file
34
src/main.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
mod lua;
|
||||||
|
use lua::engine_decoder;
|
||||||
|
|
||||||
|
pub mod backend;
|
||||||
|
|
||||||
|
use std::{env, process};
|
||||||
|
|
||||||
|
mod runner;
|
||||||
|
|
||||||
|
mod webserver;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let mut args = env::args();
|
||||||
|
let _bin = args.next();
|
||||||
|
|
||||||
|
let mut config_location: Option<String> = None;
|
||||||
|
|
||||||
|
while let Some(arg) = args.next() {
|
||||||
|
match arg.as_str() {
|
||||||
|
"--config" | "-c" => {
|
||||||
|
config_location = args.next().or_else(|| {
|
||||||
|
eprintln!("--config needs a path");
|
||||||
|
process::exit(1)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
&_ => {
|
||||||
|
eprintln!("Unknown command line option {}", arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
webserver::main_server(config_location).await;
|
||||||
|
}
|
||||||
41
src/runner.rs
Normal file
41
src/runner.rs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
use crate::engine_decoder::Engine;
|
||||||
|
use futures::future::try_join_all;
|
||||||
|
use mlua::{Table, Value};
|
||||||
|
|
||||||
|
pub async fn run_engines(
|
||||||
|
engines: Vec<Engine>,
|
||||||
|
query: String,
|
||||||
|
) -> mlua::Result<Vec<(String, Value)>> {
|
||||||
|
let engine_futures = engines.into_iter().map(|engine| {
|
||||||
|
let value = query.clone();
|
||||||
|
async move {
|
||||||
|
let results: Table = engine.grabber.call_async(value).await?;
|
||||||
|
|
||||||
|
let items: Vec<Value> = results
|
||||||
|
.sequence_values::<Value>()
|
||||||
|
.collect::<Result<Vec<Value>, mlua::Error>>()?;
|
||||||
|
|
||||||
|
let builder = engine.builder;
|
||||||
|
let engine_name = engine.name;
|
||||||
|
|
||||||
|
let builder_futures = items.into_iter().map(|item| {
|
||||||
|
let builder = builder.clone();
|
||||||
|
let engine_name = engine_name.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
|
let result: Value = builder.call_async((item, "test")).await?;
|
||||||
|
|
||||||
|
Ok::<_, mlua::Error>((engine_name, result))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try_join_all(builder_futures).await
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let results: Vec<Vec<(String, Value)>> = try_join_all(engine_futures).await?;
|
||||||
|
|
||||||
|
let flattened: Vec<(String, Value)> = results.into_iter().flatten().collect();
|
||||||
|
|
||||||
|
Ok(flattened)
|
||||||
|
}
|
||||||
59
src/webserver/mod.rs
Normal file
59
src/webserver/mod.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
use crate::engine_decoder;
|
||||||
|
use crate::lua;
|
||||||
|
use axum::{
|
||||||
|
Router,
|
||||||
|
extract::{Query, State},
|
||||||
|
response::Html,
|
||||||
|
routing::get,
|
||||||
|
};
|
||||||
|
use serde;
|
||||||
|
|
||||||
|
use crate::runner;
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct Params {
|
||||||
|
query: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn main_server(config_location: Option<String>) {
|
||||||
|
// build our application with a single route
|
||||||
|
let app = Router::new()
|
||||||
|
.route("/", get(handler))
|
||||||
|
.with_state(config_location);
|
||||||
|
|
||||||
|
println!("Running webserver");
|
||||||
|
|
||||||
|
// run our app with hyper, listening globally on port 3000
|
||||||
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||||
|
axum::serve(listener, app).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handler(
|
||||||
|
State(config_location): State<Option<String>>,
|
||||||
|
Query(params): Query<Params>,
|
||||||
|
) -> Html<String> {
|
||||||
|
// Long lived lua instance
|
||||||
|
let mut lua_instance = lua::create_instance();
|
||||||
|
|
||||||
|
let engine_table: mlua::Table =
|
||||||
|
lua::intialise_lua(&mut lua_instance, config_location).expect("Failed to initialise lua");
|
||||||
|
|
||||||
|
let engine_vec = engine_decoder::get_engine_vec(&mut lua_instance, engine_table)
|
||||||
|
.expect("could not get engines");
|
||||||
|
|
||||||
|
let results = runner::run_engines(engine_vec, params.query.to_string()).await;
|
||||||
|
|
||||||
|
let html = results
|
||||||
|
.iter()
|
||||||
|
.flat_map(|result| result.iter())
|
||||||
|
.map(|(_, value)| {
|
||||||
|
let tostring: mlua::Function = lua_instance.globals().get("tostring").unwrap();
|
||||||
|
let value: String = tostring.call(value.clone()).unwrap();
|
||||||
|
|
||||||
|
format!("<li>{}</li>", value)
|
||||||
|
})
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("");
|
||||||
|
|
||||||
|
Html(format!("<h1>Engine Results</h1><ul>{}</ul>", html))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user