Skip to content

Commit ffb2300

Browse files
committed
prepare for private demos
1 parent 0c7e51f commit ffb2300

6 files changed

+58
-14
lines changed

Diff for: .sqlx/query-68e8265e13596ad6de3e3d346b6d2fb62a68eda3e98f690e7e8d954627d8025c.json renamed to .sqlx/query-7ea7c5f61e8c77898d8b816fce80f066026822e03d6f74bd4ae19d7c9d914426.json

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: flake.nix

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
inputs.flakelight.follows = "flakelight";
1111
};
1212
};
13-
outputs = {
14-
mill-scale,
15-
...
16-
}:
13+
outputs = {mill-scale, ...}:
1714
mill-scale ./. {
1815
packageOpts = {demostf-frontend-node-modules, ...}: {
1916
preBuild = ''

Diff for: nix/node_modules.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}: let
66
inherit (lib.sources) sourceByRegex;
77
in
8-
importNpmLock.buildNodeModules {
8+
importNpmLock.buildNodeModules {
99
inherit nodejs;
1010
npmRoot = sourceByRegex ../. ["package.*"];
1111
}

Diff for: src/data/demo.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct Demo {
4040
pub player_count: i32,
4141
pub players: Vec<Player>,
4242
pub chat: Vec<Chat>,
43+
pub private_until: Option<OffsetDateTime>,
4344
}
4445

4546
impl Debug for Demo {
@@ -74,6 +75,7 @@ impl Demo {
7475
pub server: String,
7576
pub nick: String,
7677
pub player_count: i32,
78+
pub private_until: Option<OffsetDateTime>,
7779
}
7880

7981
let Some(raw) = query_as!(
@@ -84,7 +86,8 @@ impl Demo {
8486
"playerCount" as player_count,
8587
users_named.name as uploader_name_preferred,
8688
users.steamid as "uploader_steam_id?: SteamId",
87-
users.name as "uploader_name?"
89+
users.name as "uploader_name?",
90+
demos.private_until
8891
FROM demos
8992
LEFT JOIN users_named ON uploader = users_named.id
9093
LEFT JOIN users ON uploader = users.id
@@ -120,6 +123,7 @@ impl Demo {
120123
player_count: raw.player_count,
121124
players,
122125
chat,
126+
private_until: raw.private_until,
123127
}))
124128
}
125129

@@ -149,6 +153,37 @@ impl Demo {
149153
pub fn viewer_url(&self) -> ViewerUrl {
150154
ViewerUrl(self.id)
151155
}
156+
157+
pub fn is_private(&self) -> bool {
158+
if let Some(private_until) = self.private_until {
159+
let now = OffsetDateTime::now_utc();
160+
now < private_until
161+
} else {
162+
false
163+
}
164+
}
165+
166+
pub fn url(&self) -> &str {
167+
if self.is_private() {
168+
""
169+
} else {
170+
self.url.as_str()
171+
}
172+
}
173+
174+
pub fn private_until_text(&self) -> Cow<'static, str> {
175+
if let Some(private_until) = self.private_until {
176+
let now = OffsetDateTime::now_utc();
177+
let days = (private_until - now).whole_days();
178+
if days <= 1 {
179+
"by tomorrow".into()
180+
} else {
181+
format!("in {days} days").into()
182+
}
183+
} else {
184+
"".into()
185+
}
186+
}
152187
}
153188

154189
pub struct ViewerUrl(i32);

Diff for: src/pages/demo.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ impl Page for DemoPage {
2323
fn render(&self) -> Markup {
2424
let style_url = ClassIconsStyle::url();
2525
html! {
26-
@if self.demo.url.is_empty() {
26+
@if self.demo.is_private() {
27+
h3.warning { "This demo is private, it will be available for download " (self.demo.private_until_text()) }
28+
} @else if self.demo.url.is_empty() {
2729
h3.warning { "This demo has been deleted and is no longer available for download." }
2830
}
2931
h2 { (self.demo.server) " - " (self.demo.red) " vs " (self.demo.blu) }
@@ -104,8 +106,8 @@ impl Page for DemoPage {
104106
span.time { (self.demo.duration()) }
105107
}
106108
p.demo-download {
107-
@if !self.demo.url.is_empty() {
108-
a.button.button-primary href = (self.demo.url) download = (self.demo.name) rel = "nofollow" { "Download" }
109+
@if !self.demo.url().is_empty() {
110+
a.button.button-primary href = (self.demo.url()) download = (self.demo.name) rel = "nofollow" { "Download" }
109111
a.button href = (self.demo.viewer_url()) rel = "nofollow" { "View" }
110112
}
111113
@if !self.demo.chat.is_empty() {

Diff for: src/pages/viewer.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ impl Page for ViewerPage<'_> {
5353
html! {
5454
.viewer-page data-maps = (maps) data-sync = (sync) {
5555
@if let Some(demo) = self.demo.as_ref() {
56-
input type = "hidden" name = "url" value = (demo.url) {}
57-
progress.download min = "0" max = "100" value = "0" {}
56+
@if demo.is_private() {
57+
h3.warning { "This demo is private, it will be available for download " (demo.private_until_text()) }
58+
} @else {
59+
input type = "hidden" name = "url" value = (demo.url) {}
60+
progress.download min = "0" max = "100" value = "0" {}
61+
}
5862
} @else {
5963
.dropzone role = "button" {
6064
noscript {

0 commit comments

Comments
 (0)