feat(server): started friend & reworked deps
This commit is contained in:
parent
bd8135e2ad
commit
83433186f3
7 changed files with 328 additions and 7 deletions
161
Cargo.lock
generated
161
Cargo.lock
generated
|
|
@ -2,6 +2,15 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic-waker"
|
||||
version = "1.1.2"
|
||||
|
|
@ -37,6 +46,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8"
|
||||
dependencies = [
|
||||
"axum-core",
|
||||
"axum-macros",
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
"futures-util",
|
||||
|
|
@ -82,6 +92,39 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-extra"
|
||||
version = "0.12.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fef252edff26ddba56bbcdf2ee3307b8129acb86f5749b68990c168a6fcc9c76"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-core",
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"mime",
|
||||
"pin-project-lite",
|
||||
"rustversion",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-macros"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
|
|
@ -331,7 +374,7 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "froxy-scrapper"
|
||||
name = "froxy-scraper"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"constcat",
|
||||
|
|
@ -351,9 +394,17 @@ name = "froxy-server"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-extra",
|
||||
"froxy-scraper",
|
||||
"froxy-templates",
|
||||
"log",
|
||||
"minijinja",
|
||||
"serde",
|
||||
"smol_str",
|
||||
"tokio",
|
||||
"tower-http",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -777,6 +828,12 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.180"
|
||||
|
|
@ -827,6 +884,15 @@ dependencies = [
|
|||
"web_atoms",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matchers"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9"
|
||||
dependencies = [
|
||||
"regex-automata",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matchit"
|
||||
version = "0.8.4"
|
||||
|
|
@ -871,6 +937,15 @@ version = "1.0.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.50.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||
dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
|
|
@ -1119,6 +1194,23 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.13.1"
|
||||
|
|
@ -1444,6 +1536,15 @@ dependencies = [
|
|||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[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 = "shlex"
|
||||
version = "1.3.0"
|
||||
|
|
@ -1637,6 +1738,15 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinystr"
|
||||
version = "0.8.2"
|
||||
|
|
@ -1745,6 +1855,7 @@ dependencies = [
|
|||
"tower",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1767,9 +1878,21 @@ checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
|||
dependencies = [
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.36"
|
||||
|
|
@ -1777,6 +1900,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
||||
dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
|
||||
dependencies = [
|
||||
"matchers",
|
||||
"nu-ansi-term",
|
||||
"once_cell",
|
||||
"regex-automata",
|
||||
"sharded-slab",
|
||||
"smallvec",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1827,6 +1980,12 @@ version = "1.0.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
|
|
|
|||
|
|
@ -6,3 +6,10 @@ resolver = "3"
|
|||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
smol_str = { version = "0.3.5", features = ["serde"] }
|
||||
minijinja = "2.15.1"
|
||||
tracing = "0.1.41"
|
||||
log = "0.4.29"
|
||||
|
||||
froxy-templates = { path = "./templates" }
|
||||
froxy-scraper = { path = "./scraper" }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "froxy-scrapper"
|
||||
name = "froxy-scraper"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
|
|
|||
|
|
@ -5,7 +5,16 @@ edition = "2024"
|
|||
publish = false
|
||||
|
||||
[dependencies]
|
||||
axum = "0.8.8"
|
||||
axum = { version = "0.8.8", features = ["macros"] }
|
||||
axum-extra = { version = "0.12.5", features = ["routing"] }
|
||||
tower-http = {version = "0.6.2", features = ["trace"] }
|
||||
tracing-subscriber = { version = "0.3.19", features=["env-filter"] }
|
||||
serde = { workspace = true }
|
||||
smol_str = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
minijinja = { workspace = true }
|
||||
tracing = {workspace = true }
|
||||
log = {workspace = true }
|
||||
|
||||
froxy-templates = { workspace = true }
|
||||
froxy-scraper = { workspace = true }
|
||||
|
|
|
|||
71
server/src/friends.rs
Normal file
71
server/src/friends.rs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
{ f_front.py
|
||||
/friends
|
||||
}
|
||||
{ f_friends.py
|
||||
/friends/add/<add>
|
||||
/friends/remove/<remove>
|
||||
/friends/set_relation/<who>/<int:relation>
|
||||
}
|
||||
*/
|
||||
|
||||
use axum::extract::{Path, State};
|
||||
use axum::routing::get;
|
||||
use axum::{Router, http::StatusCode, response::Html};
|
||||
use axum_extra::routing::RouterExt;
|
||||
|
||||
#[derive(serde::Deserialize, Debug, Clone)]
|
||||
struct FriendList(#[serde(deserialize_with = "comma_list_deser")] Vec<String>);
|
||||
fn comma_list_deser<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
use serde::Deserialize;
|
||||
|
||||
let s = String::deserialize(deserializer)?;
|
||||
Ok(s.split(',')
|
||||
.map(|v| v.to_string())
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub fn router() -> Router<crate::GlobalState> {
|
||||
Router::<crate::GlobalState>::new()
|
||||
.route_with_tsr("/friends", get(friend_page))
|
||||
.route_with_tsr("/friends/add/{names}", get(add_friend))
|
||||
.route_with_tsr("/friends/remove/{names}", get(remove_friend))
|
||||
.route_with_tsr("/friends/set_relation/{who}/{relation}", get(set_relation))
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
async fn friend_page(State(state): State<crate::GlobalState>) -> Html<String> {
|
||||
log::info!("Serving friends_page");
|
||||
Html(String::new())
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
async fn add_friend(
|
||||
State(state): State<crate::GlobalState>,
|
||||
Path((friends,)): Path<(FriendList,)>,
|
||||
) -> StatusCode {
|
||||
log::debug!("adding friends: {friends:?}");
|
||||
StatusCode::OK
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
async fn remove_friend(
|
||||
State(state): State<crate::GlobalState>,
|
||||
Path((friends,)): Path<(FriendList,)>,
|
||||
) -> StatusCode {
|
||||
log::debug!("removing friends: {friends:?}");
|
||||
StatusCode::OK
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
pub async fn set_relation(
|
||||
State(state): State<crate::GlobalState>,
|
||||
Path((friend, relation)): Path<(String, i32)>,
|
||||
) -> StatusCode {
|
||||
log::debug!("setting relation for {friend} to {relation}");
|
||||
StatusCode::OK
|
||||
}
|
||||
|
|
@ -1,4 +1,79 @@
|
|||
/*
|
||||
{ f_front.py
|
||||
[ SEND FROM STATIC DIRECTORY
|
||||
/static/<path>
|
||||
/favicon.ico
|
||||
/manifest.json
|
||||
/service_worker.json
|
||||
/apple-touch-icon.png
|
||||
]
|
||||
/
|
||||
/settings
|
||||
/profile/{login}
|
||||
/search/<keyword>/<int:friends_only>
|
||||
/friends
|
||||
}
|
||||
{ f_friends.py
|
||||
/friends/add/<add>
|
||||
/friends/remove/<remove>
|
||||
/friends/set_relation/<who>/<int:relation>
|
||||
}
|
||||
{ f_issues.py
|
||||
/addissue/<pc>/<int:issue_type>
|
||||
}
|
||||
{ f_locations.py
|
||||
/goto/<pos>
|
||||
}
|
||||
{ f_users.py
|
||||
/getuser/<login>
|
||||
/settings/profile [POST]
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::Router;
|
||||
use log::info;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
mod friends;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct GlobalState {
|
||||
templates: Arc<minijinja::Environment<'static>>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
println!("Hello, world!");
|
||||
tracing_subscriber::fmt()
|
||||
// This allows you to use, e.g., `RUST_LOG=info` or `RUST_LOG=debug`
|
||||
// when running the app to set log levels.
|
||||
.with_env_filter(
|
||||
EnvFilter::try_from_default_env()
|
||||
.or_else(|_| EnvFilter::try_new("froxy_server=error,tower_http=warn"))
|
||||
.unwrap(),
|
||||
)
|
||||
.init();
|
||||
|
||||
let mut env = minijinja::Environment::new();
|
||||
froxy_templates::friends::add_to_context(&mut env);
|
||||
|
||||
let global_state = GlobalState {
|
||||
templates: Arc::new(env),
|
||||
};
|
||||
|
||||
let app = Router::new()
|
||||
.merge(friends::router())
|
||||
.with_state(global_state)
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
||||
let (ip, port) = ("0.0.0.0", 3000);
|
||||
|
||||
info!("Starting server on {ip}:{port}");
|
||||
|
||||
// run our app with hyper, listening globally on port 3000
|
||||
let listener = tokio::net::TcpListener::bind((ip,port)).await.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ edition = "2024"
|
|||
publish = false
|
||||
|
||||
[dependencies]
|
||||
minijinja = "2.15.1"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
smol_str = { version = "0.3.5", features = ["serde"] }
|
||||
serde = { workspace = true }
|
||||
smol_str = { workspace = true }
|
||||
minijinja = { workspace = true }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue