Skip to content

Commit cb25544

Browse files
Improved admin dashboard, added config generator
1 parent ab57d28 commit cb25544

File tree

32 files changed

+733
-19
lines changed

32 files changed

+733
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pb_data
3030
minio_data
3131
ModHost.toml
3232
ModHost.toml.*
33-
config.pkl
33+
/config.pkl
34+
/default-config.pkl
3435
config.kjspkg.pkl
3536
config.astro.pkl
3637
!apps/server/ModHost.toml

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"i18n-ally.displayLanguage": "en-US",
1010
"i18n-ally.keystyle": "nested",
1111
"pkl.lsp.java.path": "/usr/local/sdkman/candidates/java/current/bin/java",
12-
"biome.enabled": false
12+
"biome.enabled": false,
13+
"editor.linkedEditing": true
1314
}

Cargo.lock

Lines changed: 50 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ readme = "README.md"
1212

1313
[workspace.dependencies]
1414
anyhow = "1.0.98"
15+
askama = "0.14.0"
1516
axum = { version = "0.8.3", features = ["macros", "multipart", "ws"] }
1617
axum-core = "0.5.2"
1718
axum-extra = { version = "0.10.1", features = ["cookie", "typed-header"] }

apps/astro-migrator/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub async fn main() -> Result<()> {
3333
let user = NewUser {
3434
github_id: -1,
3535
username: "ModHost Migrator".into(),
36+
admin: false,
37+
moderator: false,
3638
};
3739

3840
let id = insert_into(users::table)

apps/kjspkg-migrator/src/migrator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ pub async fn run() -> Result<()> {
8686
let user = NewUser {
8787
github_id: author_id as i32,
8888
username: author_name,
89+
admin: false,
90+
moderator: false,
8991
};
9092

9193
let user: User = insert_into(users::table)

crates/modhost-config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ authors.workspace = true
99
readme.workspace = true
1010

1111
[dependencies]
12+
askama.workspace = true
1213
config.workspace = true
1314
duration-str.workspace = true
1415
modhost-core = { workspace = true, features = ["url", "config", "s3", "toml"] }

crates/modhost-config/src/admin.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ impl Default for AdminConfig {
2121
}
2222
}
2323

24+
impl AdminConfig {
25+
/// Get the formatted stats interval for pkl.
26+
pub fn fmt_stats_interval(&self) -> String {
27+
format!("{}.s", self.stats_interval.as_secs())
28+
}
29+
}
30+
2431
/// Serialize a duration as a human-readable format.
2532
pub fn serialize_duration<S: Serializer>(val: &Duration, ser: S) -> Result<S::Ok, S::Error> {
2633
ser.serialize_str(&val.human_format())

crates/modhost-config/src/config.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
//! The main config models.
22
33
use crate::{AdminConfig, AuthConfigs, MeilisearchConfig, PostgresConfig, StorageConfig, UIConfig};
4+
use askama::Template;
45
use modhost_core::Result;
56
use std::fs;
67

78
/// The main ModHost configuration.
8-
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
9+
#[derive(Debug, Clone, Serialize, Deserialize, Default, Template)]
10+
#[template(path = "config.pkl", escape = "yml")]
911
pub struct AppConfig {
1012
/// The ModHost server configuration.
1113
pub server: ServerConfig,
@@ -57,4 +59,9 @@ impl AppConfig {
5759

5860
Ok(())
5961
}
62+
63+
/// Render the config as a pkl-formatted config.
64+
pub fn render(&self) -> askama::Result<String> {
65+
Template::render(self)
66+
}
6067
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import "./pkl/ModHost.pkl"
2+
3+
app: ModHost.AppConfig = new {
4+
server {
5+
host = "{{ server.host }}"
6+
port = {{ server.port }}
7+
}
8+
9+
postgres {
10+
host = "{{ postgres.host }}""
11+
port = {{ postgres.port }}
12+
user = "{{ postgres.user }}"
13+
{% if let Some(pass) = postgres.pass %}pass = "{{ pass }}"{% endif %}
14+
database = "{{ postgres.database }}"
15+
}
16+
17+
meilisearch {
18+
host = "{{ meilisearch.host }}"
19+
port = {{ meilisearch.port }}
20+
protocol = "{{ meilisearch.protocol }}"
21+
key = "{{ meilisearch.key }}"
22+
23+
indexes {
24+
projects = "{{ meilisearch.project_index }}"
25+
}
26+
}
27+
28+
auth {
29+
github {
30+
client_id = "{{ auth.github.client_id }}"
31+
client_secret = "{{ auth.github.client_secret }}"
32+
}
33+
}
34+
35+
storage {
36+
s3 {
37+
region = "{{ storage.s3_region }}"
38+
endpoint = "{{ storage.s3_endpoint }}"
39+
access_key = "{{ storage.s3_access_key }}"
40+
secret_key = "{{ storage.s3_secret_key }}"
41+
}
42+
43+
buckets {
44+
projects = "{{ storage.projects_bucket }}"
45+
gallery = "{{ storage.gallery_bucket }}"
46+
}
47+
}
48+
49+
ui {
50+
app = "{{ ui.app }}"
51+
tagline = "{{ ui.tagline }}"
52+
show_beta = {{ ui.show_beta }}
53+
default_theme = "{{ ui.default_theme }}"
54+
theme_color = "{{ ui.theme_color }}"
55+
badge_base = "{{ ui.badge_base }}"
56+
badge_secondary = "{{ ui.badge_secondary }}"
57+
58+
favicon {
59+
ico = "{{ ui.favicon_ico }}"
60+
png = "{{ ui.favicon_png }}"
61+
}
62+
63+
game {
64+
beta_name = "{{ ui.game_beta_name.stringify() }}"
65+
}
66+
67+
projects {
68+
kind = "{{ ui.project_kind.stringify() }}"
69+
70+
file_formats = List(
71+
{% for fmt in ui.project_file_formats -%}
72+
"{{ fmt }}",
73+
{% endfor %}
74+
)
75+
}
76+
}
77+
78+
admin {
79+
stats {
80+
interval = {{ admin.fmt_stats_interval() }}
81+
}
82+
}
83+
}
84+
85+
output {
86+
value = app
87+
renderer = ModHost.renderer()
88+
}

0 commit comments

Comments
 (0)