mirror of
https://codeberg.org/demostf/frontend.git
synced 2026-06-03 18:24:12 +02:00
cargo updates
This commit is contained in:
parent
49a100bb61
commit
5470398a39
7 changed files with 862 additions and 498 deletions
1232
Cargo.lock
generated
1232
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
37
Cargo.toml
37
Cargo.toml
|
|
@ -6,36 +6,37 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
tracing-opentelemetry = "0.22.0"
|
tracing-opentelemetry = "0.24.0"
|
||||||
opentelemetry = { version = "0.21.0" }
|
opentelemetry = { version = "0.23.0" }
|
||||||
opentelemetry_sdk = { version = "0.21.2", features = ["rt-tokio"] }
|
opentelemetry_sdk = { version = "0.23.0", features = ["rt-tokio"] }
|
||||||
opentelemetry-otlp = { version = "0.14.0", features = ["tls"] }
|
opentelemetry-otlp = { version = "0.16.0", features = ["tls"] }
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
serde = { version = "1.0.203", features = ["derive"] }
|
||||||
toml = "0.8.12"
|
toml = "0.8.14"
|
||||||
sqlx = { version = "0.7.4", features = ["postgres", "time", "runtime-tokio-rustls"] }
|
sqlx = { version = "0.7.4", features = ["postgres", "time", "runtime-tokio-rustls"] }
|
||||||
sea-query = { version = "0.30.7", features = ["backend-postgres", "with-time", "derive"] }
|
sea-query = { version = "0.30.7", features = ["backend-postgres", "with-time", "derive"] }
|
||||||
sea-query-binder = { version = "0.5.0", features = ["with-time", "sqlx-postgres"] }
|
sea-query-binder = { version = "0.5.0", features = ["with-time", "sqlx-postgres"] }
|
||||||
thiserror = "1.0.58"
|
thiserror = "1.0.61"
|
||||||
tokio = { version = "1.36.0", features = ["full"] }
|
tokio = { version = "1.38.0", features = ["full"] }
|
||||||
config = { version = "0.13.4", features = ["toml"] }
|
config = { version = "0.14.0", features = ["toml"] }
|
||||||
time = "0.3.34"
|
time = "0.3.36"
|
||||||
maud = { version = "0.25.0", features = ["axum"] }
|
maud = { version = "0.26.0", features = ["axum"] }
|
||||||
axum = { version = "0.6.20", features = ["headers", "macros"] }
|
axum = { version = "0.7.5", features = ["macros"] }
|
||||||
hyper = "0.14.28"
|
hyper = "1.3.1"
|
||||||
hyperlocal = "0.8.0"
|
hyper-util = { version = "0.1.5", features = ["tokio", "server"] }
|
||||||
tower-http = { version = "0.4.4", features = ["trace", "fs"] }
|
axum-extra = { version = "0.9.3", features = ["typed-header", "cookie"] }
|
||||||
|
tower-http = { version = "0.5.2", features = ["trace", "fs"] }
|
||||||
steamid-ng = "1.0.0"
|
steamid-ng = "1.0.0"
|
||||||
itertools = "0.12.1"
|
itertools = "0.13.0"
|
||||||
const-fnv1a-hash = "1.1.0"
|
const-fnv1a-hash = "1.1.0"
|
||||||
const_base = "0.2.0"
|
const_base = "0.2.0"
|
||||||
const-str = "0.5.7"
|
const-str = "0.5.7"
|
||||||
steam-openid = "0.2.0"
|
steam-openid = "0.2.0"
|
||||||
async-session = "3.0.0"
|
async-session = "3.0.0"
|
||||||
quick-xml = { version = "0.31.0", features = ["serialize"] }
|
quick-xml = { version = "0.31.0", features = ["serialize"] }
|
||||||
reqwest = "0.11.27"
|
reqwest = "0.12.4"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
demostf-build = { path = "./build", version = "*" }
|
demostf-build = { path = "./build", version = "*" }
|
||||||
include_dir = "0.7.3"
|
include_dir = "0.7.3"
|
||||||
serde-env = "0.1.1"
|
serde-env = "0.1.1"
|
||||||
tonic = { version = "0.9.2", features = ["tls", "tls-webpki-roots"] }
|
tonic = { version = "0.11.0", features = ["tls", "tls-webpki-roots"] }
|
||||||
secretfile = "0.1.0"
|
secretfile = "0.1.0"
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
})
|
})
|
||||||
(import ./overlay.nix)
|
(import ./overlay.nix)
|
||||||
(final: prev: {
|
(final: prev: {
|
||||||
demostf-frontend-toolchain = final.rust-bin.nightly."2024-01-16".default;
|
demostf-frontend-toolchain = final.rust-bin.nightly."2024-06-04".default;
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
pkgs = (import nixpkgs) {
|
pkgs = (import nixpkgs) {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ use time::format_description::well_known::Iso8601;
|
||||||
use time::{OffsetDateTime, PrimitiveDateTime, UtcOffset};
|
use time::{OffsetDateTime, PrimitiveDateTime, UtcOffset};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct Demo {
|
pub struct Demo {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
@ -159,6 +160,7 @@ impl Render for ViewerUrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromRow)]
|
#[derive(FromRow)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct ListDemo {
|
pub struct ListDemo {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ impl Render for Class {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, FromRow)]
|
#[derive(Debug, FromRow)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub steam_id: SteamId,
|
pub steam_id: SteamId,
|
||||||
|
|
|
||||||
90
src/main.rs
90
src/main.rs
|
|
@ -6,6 +6,7 @@ mod fragments;
|
||||||
mod pages;
|
mod pages;
|
||||||
mod session;
|
mod session;
|
||||||
|
|
||||||
|
use std::convert::Infallible;
|
||||||
use crate::asset::{guess_mime, serve_asset};
|
use crate::asset::{guess_mime, serve_asset};
|
||||||
pub use crate::config::Config;
|
pub use crate::config::Config;
|
||||||
use crate::config::Listen;
|
use crate::config::Listen;
|
||||||
|
|
@ -27,16 +28,14 @@ use crate::pages::viewer::{ParseWorkerScript, ParserWasm, ViewerPage, ViewerScri
|
||||||
use crate::pages::{render, GlobalStyle};
|
use crate::pages::{render, GlobalStyle};
|
||||||
use crate::session::{SessionData, COOKIE_NAME};
|
use crate::session::{SessionData, COOKIE_NAME};
|
||||||
use async_session::{MemoryStore, Session, SessionStore};
|
use async_session::{MemoryStore, Session, SessionStore};
|
||||||
use axum::extract::{MatchedPath, Path, Query, RawQuery};
|
use axum::extract::{connect_info, MatchedPath, Path, Query, RawQuery};
|
||||||
use axum::headers::Cookie;
|
|
||||||
use axum::http::header::{CONTENT_TYPE, ETAG, LOCATION, SET_COOKIE};
|
use axum::http::header::{CONTENT_TYPE, ETAG, LOCATION, SET_COOKIE};
|
||||||
use axum::http::{HeaderValue, Request, StatusCode};
|
use axum::http::{HeaderValue, Request, StatusCode};
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::{extract::State, routing::get, Router, Server, TypedHeader};
|
use axum::{extract::State, routing::get, Router, serve};
|
||||||
use demostf_build::Asset;
|
use demostf_build::Asset;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
use hyper::header::CACHE_CONTROL;
|
use hyper::header::CACHE_CONTROL;
|
||||||
use hyperlocal::UnixServerExt;
|
|
||||||
use include_dir::{include_dir, Dir};
|
use include_dir::{include_dir, Dir};
|
||||||
use maud::{Markup, Render};
|
use maud::{Markup, Render};
|
||||||
use opentelemetry::KeyValue;
|
use opentelemetry::KeyValue;
|
||||||
|
|
@ -49,8 +48,16 @@ use std::fs::{remove_file, set_permissions, Permissions};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use axum_extra::headers::Cookie;
|
||||||
|
use axum_extra::TypedHeader;
|
||||||
|
use hyper::body::Incoming;
|
||||||
|
use hyper_util::{rt::{TokioExecutor, TokioIo}, server};
|
||||||
use steam_openid::SteamOpenId;
|
use steam_openid::SteamOpenId;
|
||||||
|
use tokio::net::unix::UCred;
|
||||||
|
use tokio::net::{UnixListener, UnixStream};
|
||||||
|
use tokio::select;
|
||||||
use tokio::signal::ctrl_c;
|
use tokio::signal::ctrl_c;
|
||||||
|
use tonic::codegen::Service;
|
||||||
use tonic::transport::{ClientTlsConfig, Identity};
|
use tonic::transport::{ClientTlsConfig, Identity};
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
use tracing::{error, info, info_span, instrument};
|
use tracing::{error, info, info_span, instrument};
|
||||||
|
|
@ -203,17 +210,17 @@ async fn main() -> Result<()> {
|
||||||
)
|
)
|
||||||
.fallback(handler_404)
|
.fallback(handler_404)
|
||||||
.with_state(state);
|
.with_state(state);
|
||||||
let service = app.into_make_service();
|
|
||||||
let ctrl_c = async {
|
|
||||||
ctrl_c().await.expect("failed to install Ctrl+C handler");
|
|
||||||
};
|
|
||||||
|
|
||||||
match config.listen {
|
match config.listen {
|
||||||
Listen::Tcp { address, port } => {
|
Listen::Tcp { address, port } => {
|
||||||
|
let service = app.into_make_service();
|
||||||
let addr = SocketAddr::from((address, port));
|
let addr = SocketAddr::from((address, port));
|
||||||
info!("listening on http://{}", addr);
|
let listener = tokio::net::TcpListener::bind(addr).await?;
|
||||||
Server::bind(&addr)
|
info!("listening on http://{}", listener.local_addr()?);
|
||||||
.serve(service)
|
let ctrl_c = async {
|
||||||
|
ctrl_c().await.expect("failed to install Ctrl+C handler");
|
||||||
|
};
|
||||||
|
serve(listener, service)
|
||||||
.with_graceful_shutdown(ctrl_c)
|
.with_graceful_shutdown(ctrl_c)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
@ -222,10 +229,60 @@ async fn main() -> Result<()> {
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
remove_file(&path)?;
|
remove_file(&path)?;
|
||||||
}
|
}
|
||||||
let socket = Server::bind_unix(&path)?;
|
let uds = UnixListener::bind(path.clone())?;
|
||||||
set_permissions(&path, Permissions::from_mode(0o666))?;
|
set_permissions(&path, Permissions::from_mode(0o666))?;
|
||||||
|
|
||||||
socket.serve(service).with_graceful_shutdown(ctrl_c).await?;
|
#[derive(Clone, Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
struct UdsConnectInfo {
|
||||||
|
peer_addr: Arc<tokio::net::unix::SocketAddr>,
|
||||||
|
peer_cred: UCred,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl connect_info::Connected<&UnixStream> for UdsConnectInfo {
|
||||||
|
fn connect_info(target: &UnixStream) -> Self {
|
||||||
|
let peer_addr = target.peer_addr().unwrap();
|
||||||
|
let peer_cred = target.peer_cred().unwrap();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
peer_addr: Arc::new(peer_addr),
|
||||||
|
peer_cred,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut make_service = app.into_make_service_with_connect_info::<UdsConnectInfo>();
|
||||||
|
|
||||||
|
// See https://github.com/tokio-rs/axum/blob/main/examples/serve-with-hyper/src/main.rs for
|
||||||
|
// more details about this setup
|
||||||
|
loop {
|
||||||
|
let (socket, _remote_addr) = select! {
|
||||||
|
result = uds.accept() => {
|
||||||
|
result?
|
||||||
|
},
|
||||||
|
_ = ctrl_c() => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let tower_service = unwrap_infallible(make_service.call(&socket).await);
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let socket = TokioIo::new(socket);
|
||||||
|
|
||||||
|
let hyper_service =
|
||||||
|
hyper::service::service_fn(move |request: Request<Incoming>| {
|
||||||
|
tower_service.clone().call(request)
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Err(err) = server::conn::auto::Builder::new(TokioExecutor::new())
|
||||||
|
.serve_connection_with_upgrades(socket, hyper_service)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
eprintln!("failed to serve connection: {err:#}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -489,3 +546,10 @@ pub async fn kill_icons(path: Path<String>) -> impl IntoResponse {
|
||||||
None => StatusCode::NOT_FOUND.into_response(),
|
None => StatusCode::NOT_FOUND.into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unwrap_infallible<T>(result: Result<T, Infallible>) -> T {
|
||||||
|
match result {
|
||||||
|
Ok(value) => value,
|
||||||
|
Err(err) => match err {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,9 +4,11 @@ use crate::{App, Result};
|
||||||
use async_session::SessionStore as _;
|
use async_session::SessionStore as _;
|
||||||
use axum::extract::{FromRef, FromRequestParts};
|
use axum::extract::{FromRef, FromRequestParts};
|
||||||
use axum::http::request::Parts;
|
use axum::http::request::Parts;
|
||||||
use axum::{async_trait, headers::Cookie, RequestPartsExt, TypedHeader};
|
use axum::{async_trait, RequestPartsExt};
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use axum_extra::headers::Cookie;
|
||||||
|
use axum_extra::TypedHeader;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
pub const COOKIE_NAME: &str = "tf_session";
|
pub const COOKIE_NAME: &str = "tf_session";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue