Skip to content

Commit d49e3ce

Browse files
chore: fix some path issues, allow longer id's
Signed-off-by: Henry Gressmann <[email protected]>
1 parent 86ba783 commit d49e3ce

File tree

11 files changed

+43
-53
lines changed

11 files changed

+43
-53
lines changed

Cargo.lock

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

config.example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ base_url="http://localhost:9042"
55
port=9042
66

77
# # Folder to store the database in (Will be created if it doesn't exist)
8-
# # defaults to ./.local/share/liwan/data (or $XDG_DATA_HOME/liwan/data) on linux/macos
8+
# # defaults to $HOME/.local/share/liwan/data on linux/macos
99
# # defaults to ./liwan-data on other platforms
1010
# data_dir="./liwan-data"
1111

data/licenses-npm.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/app/core/geoip.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ impl LiwanGeoIP {
4545
return Ok(None);
4646
};
4747

48+
if geoip.maxmind_account_id.is_none() && geoip.maxmind_license_key.is_none() && geoip.maxmind_db_path.is_none()
49+
{
50+
tracing::trace!("GeoIP support disabled, skipping...");
51+
return Ok(None);
52+
}
53+
4854
let edition = geoip.maxmind_edition.as_deref().unwrap_or("GeoLite2-City");
4955
let default_path = PathBuf::from(config.data_dir.clone()).join(format!("./geoip/{}.mmdb", edition));
5056
let path = geoip.maxmind_db_path.as_ref().map(PathBuf::from).unwrap_or(default_path);

src/cli.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ pub struct AddUser {
8888

8989
pub fn handle_command(mut config: Config, cmd: Command) -> Result<()> {
9090
config.geoip = None; // disable GeoIP support in CLI
91-
let app = Liwan::try_new(config)?;
9291

9392
match cmd {
9493
Command::UpdatePassword(update) => {
94+
let app = Liwan::try_new(config)?;
9595
app.users.update_password(&update.username, &update.password)?;
9696
println!("Password updated for user {}", update.username);
9797
}
9898
Command::Users(_) => {
99+
let app = Liwan::try_new(config)?;
99100
let users = app.users.all()?;
100101
if users.is_empty() {
101102
println!("{}", "No users found".bold());
@@ -109,6 +110,7 @@ pub fn handle_command(mut config: Config, cmd: Command) -> Result<()> {
109110
}
110111
}
111112
Command::AddUser(add) => {
113+
let app = Liwan::try_new(config)?;
112114
app.users.create(
113115
&add.username,
114116
&add.password,
@@ -130,6 +132,7 @@ pub fn handle_command(mut config: Config, cmd: Command) -> Result<()> {
130132
}
131133
#[cfg(debug_assertions)]
132134
Command::SeedDatabase(_) => {
135+
let app = Liwan::try_new(config)?;
133136
app.seed_database()?;
134137
println!("Database seeded with test data");
135138
}

src/config.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ fn default_port() -> u16 {
1616
fn default_data_dir() -> String {
1717
#[cfg(target_family = "unix")]
1818
{
19-
if std::path::Path::new("~/.local/share").exists() {
20-
return "~/.local/share/liwan/data".to_string();
21-
}
19+
let home = std::env::var("HOME").ok().unwrap_or_else(|| "/root".to_string());
2220
std::env::var("XDG_DATA_HOME")
23-
.map(|home| format!("{}/liwan/data", home))
24-
.unwrap_or_else(|_| "./liwan-data".to_string())
21+
.map(|data_home| format!("{data_home}/liwan/data"))
22+
.unwrap_or_else(|_| format!("{home}/.local/share/liwan/data"))
2523
}
2624

2725
#[cfg(not(target_family = "unix"))]
@@ -64,21 +62,22 @@ impl Config {
6462

6563
let path = path.or_else(|| std::env::var("LIWAN_CONFIG").ok());
6664

65+
let mut config = Figment::new()
66+
.merge(Toml::file("liwan.config.toml"))
67+
.merge(Toml::file(path.unwrap_or("liwan.config.toml".to_string())));
68+
6769
#[cfg(target_family = "unix")]
68-
let path = path.or_else(|| match std::env::var("XDG_CONFIG_HOME") {
69-
Ok(home) => Some(format!("{}/liwan/config.toml", home)),
70-
Err(_) => {
71-
if std::path::Path::new("~/.config").exists() {
72-
Some("~/.config/liwan/config.toml".to_string())
73-
} else {
74-
None
75-
}
76-
}
77-
});
70+
{
71+
let home = std::env::var("HOME").unwrap_or_else(|_| "/root".to_string());
72+
let config_dir = std::env::var("XDG_CONFIG_HOME").unwrap_or_else(|_| format!("{home}/.config"));
73+
74+
config = config
75+
.join(Toml::file(format!("{config_dir}/liwan/config.toml")))
76+
.join(Toml::file(format!("{config_dir}/liwan/liwan.config.toml")))
77+
.join(Toml::file(format!("{config_dir}/liwan.config.toml")))
78+
}
7879

79-
let config: Config = Figment::new()
80-
.merge(Toml::file("liwan.config.toml"))
81-
.merge(Toml::file(path.unwrap_or("liwan.config.toml".to_string())))
80+
let config: Config = config
8281
.merge(Env::raw().filter_map(|key| match key {
8382
k if !k.starts_with("LIWAN_") => None,
8483
k if k.starts_with("LIWAN_MAXMIND_") => Some(format!("geoip.maxmind_{}", &k[14..]).into()),

src/web/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use colored::Colorize;
1313
use crossbeam::channel::Sender;
1414
use eyre::{Context, Result};
1515
use rust_embed::RustEmbed;
16-
use std::path::Path;
1716

1817
use poem::endpoint::EmbeddedFileEndpoint;
1918
use poem::listener::TcpListener;
@@ -29,7 +28,10 @@ struct Files;
2928
#[folder = "./tracker"]
3029
struct Script;
3130

31+
#[cfg(debug_assertions)]
3232
fn save_spec() -> Result<()> {
33+
use std::path::Path;
34+
3335
let path = Path::new("./web/src/api/dashboard.ts");
3436
if path.exists() {
3537
let spec = serde_json::to_string(&serde_json::from_str::<serde_json::Value>(&dashboard_service().spec())?)?
@@ -88,7 +90,7 @@ pub async fn start_webserver(app: Liwan, events: Sender<Event>) -> Result<()> {
8890
let listener = TcpListener::bind(("0.0.0.0", app.config.port));
8991

9092
if let Some(onboarding) = app.onboarding.token()? {
91-
let get_started = format!("http://localhost:{}/setup?t={}", app.config.port, onboarding).underline().bold();
93+
let get_started = format!("{}/setup?t={}", app.config.base_url, onboarding).underline().bold();
9294
let command = "liwan --help".bold();
9395
tracing::info!("{}", "It looks like you're running Liwan for the first time!".white());
9496
tracing::info!("{}", format!("You can get started by visiting: {get_started}").white());

web/bun.lockb

0 Bytes
Binary file not shown.

web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@radix-ui/react-dialog": "^1.1.1",
1919
"@radix-ui/react-tabs": "^1.1.0",
2020
"@scaleway/use-query-params": "^5.0.5",
21-
"@tanstack/react-query": "^5.52.1",
21+
"@tanstack/react-query": "^5.52.2",
2222
"@uidotdev/usehooks": "^2.4.1",
2323
"date-fns": "^3.6.0",
2424
"fets": "^0.8.3",

web/src/components/settings/dialogs.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export const CreateProject = () => {
299299
<form onSubmit={handleSubmit}>
300300
<label>
301301
Project ID <small>(This cannot be changed later)</small>
302-
<input required pattern="^[A-Za-z0-9_\-]{1,15}$" name="id" type="text" placeholder="my-project" />
302+
<input required pattern="^[A-Za-z0-9_\-.]{1,40}$" name="id" type="text" placeholder="my-project" />
303303
</label>
304304
<label>
305305
Project Name <small>(Used in the dashboard)</small>
@@ -462,7 +462,7 @@ export const CreateEntity = () => {
462462
<form onSubmit={handleSubmit}>
463463
<label>
464464
Entity ID <small>(This cannot be changed later)</small>
465-
<input required pattern="^[A-Za-z0-9_\-]{1,15}$" name="id" type="text" placeholder="my-website" />
465+
<input required pattern="^[A-Za-z0-9_\-.]{1,40}$" name="id" type="text" placeholder="my-website" />
466466
</label>
467467
<label>
468468
Entity Name <small>(Used in the dashboard)</small>
@@ -669,7 +669,7 @@ export const CreateUser = () => {
669669
Username <small>(This cannot be changed later)</small>
670670
<input
671671
required
672-
pattern="^[A-Za-z0-9_\-]{1,15}$"
672+
pattern="^[A-Za-z0-9_\-]{1,20}$"
673673
name="username"
674674
type="text"
675675
placeholder="MyUsername"

0 commit comments

Comments
 (0)