fix: validation URL Imago vide + ajout username configurable (ui.username)

This commit is contained in:
2026-06-26 09:19:18 -04:00
parent 05d13a7725
commit fb292eaed5
7 changed files with 50 additions and 10 deletions
+4
View File
@@ -104,6 +104,9 @@ fn default_cache_size() -> usize {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UiConfig {
/// Nom affiché dans le dashboard
#[serde(default)]
pub username: String,
#[serde(default = "default_true")]
pub show_notifications: bool,
#[serde(default = "default_true")]
@@ -115,6 +118,7 @@ pub struct UiConfig {
impl Default for UiConfig {
fn default() -> Self {
Self {
username: String::new(),
show_notifications: true,
show_tray_icon: true,
notification_timeout_sec: default_notification_timeout(),
+3 -3
View File
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Changelog — imagod-web v0.2.0+build.30-ce93740-dirty</title>
<title>Changelog — imagod-web v0.2.0+build.31-05d13a7-dirty</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🖼️</text></svg>">
<style>
* { margin:0; padding:0; box-sizing:border-box; }
@@ -37,7 +37,7 @@ footer { text-align:center; color:#484f58; font-size:0.8rem; padding:2rem; }
</head>
<body>
<header>
<h1>📋 imagod-web <span class="version-badge">v0.2.0+build.30-ce93740-dirty</span></h1>
<h1>📋 imagod-web <span class="version-badge">v0.2.0+build.31-05d13a7-dirty</span></h1>
<nav>
<a href="/">🖼️ Galerie</a>
<a href="/changelog" class="active">📋 Changelog</a>
@@ -107,6 +107,6 @@ footer { text-align:center; color:#484f58; font-size:0.8rem; padding:2rem; }
<h2>Légende des tags</h2>
</main>
<footer>imagod-web v0.2.0+build.30-ce93740-dirty — <a href="https://git.dracodev.net/Projets/imagod-web">Gitea</a></footer>
<footer>imagod-web v0.2.0+build.31-05d13a7-dirty — <a href="https://git.dracodev.net/Projets/imagod-web">Gitea</a></footer>
</body>
</html>
+3 -3
View File
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aide & Roadmap — imagod-web v0.2.0+build.30-ce93740-dirty</title>
<title>Aide & Roadmap — imagod-web v0.2.0+build.31-05d13a7-dirty</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🖼️</text></svg>">
<style>
* { margin:0; padding:0; box-sizing:border-box; }
@@ -37,7 +37,7 @@ footer { text-align:center; color:#484f58; font-size:0.8rem; padding:2rem; }
</head>
<body>
<header>
<h1>❓ imagod-web <span class="version-badge">v0.2.0+build.30-ce93740-dirty</span></h1>
<h1>❓ imagod-web <span class="version-badge">v0.2.0+build.31-05d13a7-dirty</span></h1>
<nav>
<a href="/">🖼️ Galerie</a>
<a href="/changelog">📋 Changelog</a>
@@ -169,6 +169,6 @@ footer { text-align:center; color:#484f58; font-size:0.8rem; padding:2rem; }
<p>5. <strong>Corriger le backend Imago</strong> (thumbnails, upload, stockage)</p>
</main>
<footer>imagod-web v0.2.0+build.30-ce93740-dirty — <a href="https://git.dracodev.net/Projets/imagod-web">Gitea</a></footer>
<footer>imagod-web v0.2.0+build.31-05d13a7-dirty — <a href="https://git.dracodev.net/Projets/imagod-web">Gitea</a></footer>
</body>
</html>
+21 -3
View File
@@ -465,7 +465,7 @@
<button class="btn" id="clear-btn" style="display:none">✕</button>
</div>
<button class="btn accent" id="header-upload-btn" onclick="document.getElementById('drop-zone').scrollIntoView({behavior:'smooth'}); document.getElementById('file-input').click()">📤 Upload</button>
<span class="version-badge" id="version-badge">v0.2.0+build.30-ce93740-dirty</span>
<span class="version-badge" id="version-badge">v0.2.0+build.31-05d13a7-dirty</span>
</div>
<!-- ─── Navigation ─── -->
@@ -1245,16 +1245,34 @@ function initApp() {
}
// Check localStorage for existing session
(function checkAuth() {
(async function checkAuth() {
const savedKey = localStorage.getItem('imago_api_key');
const savedName = localStorage.getItem('imago_user_name');
// Récupérer le username configuré côté serveur (priorité)
let serverName = null;
try {
const meResp = await fetch('/api/me');
if (meResp.ok) {
const meData = await meResp.json();
serverName = meData.name;
}
} catch(e) { /* ignore */ }
const displayName = serverName !== 'Utilisateur' ? serverName : (savedName || 'Utilisateur');
if (savedKey) {
apiKey = savedKey;
userName = savedName || 'Utilisateur';
userName = displayName;
document.getElementById('login-overlay').style.display = 'none';
document.getElementById('user-info').style.display = 'flex';
document.getElementById('user-name').textContent = userName;
initApp();
} else {
// Même sans clé API, afficher le nom serveur si configuré
if (serverName && serverName !== 'Utilisateur') {
userName = serverName;
}
}
})();
+5 -1
View File
@@ -143,10 +143,14 @@ pub struct ImagoClient {
impl ImagoClient {
/// Crée un nouveau client Imago
pub fn new(base_url: String, api_key: String) -> Result<Self> {
let url = base_url.trim().to_string();
if url.is_empty() {
anyhow::bail!("URL Imago non configurée — utilisez 'imagod-web config set imago.url \"http://...\"'");
}
let client = Client::builder()
.timeout(std::time::Duration::from_secs(30))
.build()?;
Ok(Self { client, base_url, api_key })
Ok(Self { client, base_url: url, api_key })
}
/// Construit l'URL de base pour l'API images
+1
View File
@@ -51,6 +51,7 @@ pub async fn serve_with_config(host: &str, port: u16, config: &Config) -> anyhow
imago,
base_url: config.imago.url.clone(),
api_key: config.imago.api_key.clone(),
username: config.ui.username.clone(),
ws_hub: ws_hub.clone(),
dedup_db_path,
in_flight: Mutex::new(HashSet::new()),
+13
View File
@@ -19,6 +19,7 @@ pub struct AppState {
pub imago: Arc<ImagoClient>,
pub base_url: String,
pub api_key: String,
pub username: String,
pub ws_hub: crate::server::ws::WsHub,
/// Chemin vers la DB de dédoublonnage (partagée avec le watcher)
pub dedup_db_path: PathBuf,
@@ -102,6 +103,7 @@ pub fn api_routes(state: AppState) -> Router {
.route("/api/health", get(health_check))
.route("/api/ping", get(ping))
.route("/api/auth/validate", post(validate_api_key))
.route("/api/me", get(get_me))
.route("/api/upload", post(upload_image))
.route("/api/images", get(list_images))
.route("/api/images/search", get(search_images))
@@ -125,6 +127,17 @@ async fn ping() -> Json<serde_json::Value> {
Json(serde_json::json!({"pong": true, "timestamp": chrono::Utc::now().to_rfc3339()}))
}
/// Retourne les infos de l'utilisateur configuré (username, etc.)
async fn get_me(
State(state): State<Arc<AppState>>,
) -> Json<serde_json::Value> {
let name = if state.username.is_empty() { "Utilisateur" } else { &state.username };
Json(serde_json::json!({
"name": name,
"username": state.username,
}))
}
/// Retourne la version de l'application et des infos utiles
async fn version() -> Json<serde_json::Value> {
Json(serde_json::json!({