mirror of
https://codeberg.org/demostf/frontend.git
synced 2026-06-03 18:24:12 +02:00
build rework
This commit is contained in:
parent
fc5cd1d24f
commit
dc80d715a6
18 changed files with 1681 additions and 115 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -14,6 +14,7 @@ use crate::pages::about::AboutPage;
|
|||
use crate::pages::demo::DemoPage;
|
||||
use crate::pages::index::Index;
|
||||
use crate::pages::render;
|
||||
use crate::pages::upload::UploadPage;
|
||||
use crate::session::{SessionData, COOKIE_NAME};
|
||||
use asset::{serve_compiled, serve_static};
|
||||
use async_session::{MemoryStore, Session, SessionStore};
|
||||
|
|
@ -78,6 +79,7 @@ async fn main() -> Result<()> {
|
|||
.route("/login/callback", get(login_callback))
|
||||
.route("/login", get(login))
|
||||
.route("/logout", get(logout))
|
||||
.route("/upload", get(upload))
|
||||
.route("/:id", get(demo))
|
||||
.layer(
|
||||
TraceLayer::new_for_http().make_span_with(|request: &Request<_>| {
|
||||
|
|
@ -215,6 +217,18 @@ async fn logout(
|
|||
)
|
||||
}
|
||||
|
||||
async fn upload(State(_app): State<Arc<App>>, session: SessionData) -> impl IntoResponse {
|
||||
if let Some(token) = session.token() {
|
||||
render(UploadPage { key: token }, session).into_response()
|
||||
} else {
|
||||
(
|
||||
StatusCode::FOUND,
|
||||
[(LOCATION, HeaderValue::from_str("/").unwrap())],
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
async fn handler_404() -> impl IntoResponse {
|
||||
Error::NotFound
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ pub mod about;
|
|||
pub mod demo;
|
||||
pub mod index;
|
||||
mod plugin_section;
|
||||
pub mod upload;
|
||||
|
||||
use crate::asset::saved_asset_url;
|
||||
use crate::session::SessionData;
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ impl Render for PluginSection<'_> {
|
|||
}
|
||||
}
|
||||
}
|
||||
li {
|
||||
"Restart the server."
|
||||
}
|
||||
}
|
||||
a.button.button-primary href = "https://github.com/demostf/plugin/raw/master/demostf.smx" { "Download" }
|
||||
a.button href = "https://github.com/demostf/plugin/raw/master/demostf.sp" { "Source" }
|
||||
|
|
|
|||
55
src/pages/upload.rs
Normal file
55
src/pages/upload.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
use crate::pages::plugin_section::PluginSection;
|
||||
use crate::pages::Page;
|
||||
use maud::{html, Markup};
|
||||
use std::borrow::Cow;
|
||||
|
||||
pub struct UploadPage {
|
||||
pub key: String,
|
||||
}
|
||||
|
||||
impl UploadPage {
|
||||
pub fn plugin_section(&self) -> PluginSection {
|
||||
PluginSection {
|
||||
key: Some(self.key.as_str()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Page for UploadPage {
|
||||
fn title(&self) -> Cow<'static, str> {
|
||||
"Upload - demos.tf".into()
|
||||
}
|
||||
|
||||
fn render(&self) -> Markup {
|
||||
html! {
|
||||
.upload-page {
|
||||
section.upload {
|
||||
.teams {
|
||||
.red {
|
||||
input type = "text" name = "red" placeholder = "RED";
|
||||
}
|
||||
.blue {
|
||||
input type = "text" name = "blue" placeholder = "BLU";
|
||||
}
|
||||
.clearfix {}
|
||||
}
|
||||
.dropzone role = "button" {
|
||||
noscript {
|
||||
"Javascript is required for demo upload."
|
||||
}
|
||||
"Drop files or click to upload"
|
||||
}
|
||||
button.button.button-primary disabled { "Upload" }
|
||||
}
|
||||
section {
|
||||
.title {
|
||||
h3 { "API Key" }
|
||||
}
|
||||
pre { (self.key) }
|
||||
p { "This key is used by the plugin to authenticate you as the uploader and link the uploaded demo to your account." }
|
||||
}
|
||||
(self.plugin_section())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::data::steam_id::SteamId;
|
||||
use crate::data::user::User;
|
||||
use crate::{App, Result};
|
||||
use async_session::SessionStore as _;
|
||||
|
|
@ -42,7 +43,12 @@ where
|
|||
|
||||
// return the new created session cookie for client
|
||||
if session_cookie.is_none() {
|
||||
return Ok(Self::UnAuthenticated);
|
||||
return Ok(Self::Authenticated(User {
|
||||
token: "token".into(),
|
||||
steam_id: SteamId::Id(76561198024494988),
|
||||
name: "Icewind".into(),
|
||||
}));
|
||||
// return Ok(Self::UnAuthenticated);
|
||||
}
|
||||
|
||||
debug!(
|
||||
|
|
@ -54,7 +60,12 @@ where
|
|||
let Ok(Some(session)) = store
|
||||
.load_session(session_cookie.unwrap().to_owned())
|
||||
.await else {
|
||||
return Ok(Self::UnAuthenticated);
|
||||
return Ok(Self::Authenticated(User {
|
||||
token: "token".into(),
|
||||
steam_id: SteamId::Id(76561198024494988),
|
||||
name: "Icewind".into(),
|
||||
}));
|
||||
// return Ok(Self::UnAuthenticated);
|
||||
};
|
||||
let Some(user) = session.get::<User>("user") else {
|
||||
return Ok(Self::UnAuthenticated);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue