Projets génériques, logs Apache du vhost et fenêtre de projet
- Un projet est un dossier quelconque avec ses dossiers de logs (proposés d'après le projet : storage/logs, var/log, logs…) ; le format de chaque fichier est détecté (Monolog, erreurs Apache, accès, une ligne par entrée). - Le vhost Apache d'un projet ajoute ses ErrorLog et CustomLog ; les logs d'accès ne comptent jamais dans les non-lus. - Ajout, modification et retrait d'un projet dans une fenêtre modale. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6af0bbe0c0
commit
86c8f1bb49
13 files changed
+1979
-304
No files matched your search
+43
-19
@@ -1,7 +1,10 @@
|
||||
//! Code exécuté uniquement côté serveur : base de données et accès au contexte.
|
||||
|
||||
use crate::{
|
||||
model::{DEFAULT_INTERVAL, FileSort, FileSummary, ProjectSummary, Settings, Summary},
|
||||
model::{
|
||||
DEFAULT_INTERVAL, FileSort, FileSummary, LogFormat, LogKind, ProjectSummary, Settings,
|
||||
Summary, parse_log_dirs,
|
||||
},
|
||||
scanner::Scanner,
|
||||
};
|
||||
use leptos::prelude::*;
|
||||
@@ -103,11 +106,13 @@ pub async fn load_settings(pool: &SqlitePool) -> sqlx::Result<Settings> {
|
||||
})
|
||||
}
|
||||
|
||||
/// (id, project_id, relative_path, size, modifié le, manquant, erreur, non-lus)
|
||||
/// (id, project_id, relative_path, kind, format, size, modifié le, manquant, erreur, non-lus)
|
||||
type FileRow = (
|
||||
i64,
|
||||
i64,
|
||||
String,
|
||||
String,
|
||||
Option<String>,
|
||||
i64,
|
||||
Option<i64>,
|
||||
bool,
|
||||
@@ -117,15 +122,26 @@ type FileRow = (
|
||||
|
||||
/// Projets, fichiers et compteurs de non-lus.
|
||||
///
|
||||
/// Un fichier manquant ou un projet introuvable sur le disque ne compte aucun non-lu.
|
||||
/// Un fichier manquant ou un projet introuvable sur le disque ne compte aucun non-lu, ni un
|
||||
/// log d'accès (cf. [`LogFormat::notifies`]).
|
||||
pub async fn load_summary(pool: &SqlitePool) -> sqlx::Result<Summary> {
|
||||
let projects: Vec<(i64, String, String, Option<String>)> = sqlx::query_as(
|
||||
"SELECT id, name, root_path, last_error FROM projects ORDER BY name COLLATE NOCASE, id",
|
||||
type ProjectRow = (
|
||||
i64,
|
||||
String,
|
||||
String,
|
||||
String,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
);
|
||||
let projects: Vec<ProjectRow> = sqlx::query_as(
|
||||
"SELECT id, name, root_path, log_dirs, last_error, vhost_path, vhost_error
|
||||
FROM projects ORDER BY name COLLATE NOCASE, id",
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
let files: Vec<FileRow> = sqlx::query_as(
|
||||
"SELECT f.id, f.project_id, f.relative_path, f.size, f.modified_at,
|
||||
"SELECT f.id, f.project_id, f.relative_path, f.kind, f.format, f.size, f.modified_at,
|
||||
f.missing_since IS NOT NULL,
|
||||
f.last_error,
|
||||
(SELECT COUNT(*) FROM log_entries_index e
|
||||
@@ -142,24 +158,29 @@ pub async fn load_summary(pool: &SqlitePool) -> sqlx::Result<Summary> {
|
||||
now: time::OffsetDateTime::now_utc().unix_timestamp(),
|
||||
projects: Vec::with_capacity(projects.len()),
|
||||
};
|
||||
for (id, name, root_path, error) in projects {
|
||||
for (id, name, root_path, log_dirs, error, vhost_path, vhost_error) in projects {
|
||||
let project_ok = error.is_none();
|
||||
let files: Vec<FileSummary> = files
|
||||
.iter()
|
||||
.filter(|f| f.1 == id)
|
||||
.map(
|
||||
|(fid, _, rel, size, modified, missing, ferr, unread)| FileSummary {
|
||||
id: *fid,
|
||||
relative_path: rel.clone(),
|
||||
size: *size as u64,
|
||||
modified: *modified,
|
||||
missing: *missing,
|
||||
error: ferr.clone(),
|
||||
unread: if project_ok && !*missing {
|
||||
*unread as u64
|
||||
} else {
|
||||
0
|
||||
},
|
||||
|(fid, _, rel, kind, format, size, modified, missing, ferr, unread)| {
|
||||
let kind = LogKind::parse(kind).unwrap_or_default();
|
||||
let notifies = format
|
||||
.as_deref()
|
||||
.and_then(LogFormat::parse)
|
||||
.is_none_or(LogFormat::notifies);
|
||||
let counted = !*missing && notifies && (project_ok || kind != LogKind::Project);
|
||||
FileSummary {
|
||||
id: *fid,
|
||||
kind,
|
||||
relative_path: rel.clone(),
|
||||
size: *size as u64,
|
||||
modified: *modified,
|
||||
missing: *missing,
|
||||
error: ferr.clone(),
|
||||
unread: if counted { *unread as u64 } else { 0 },
|
||||
}
|
||||
},
|
||||
)
|
||||
.collect();
|
||||
@@ -169,7 +190,10 @@ pub async fn load_summary(pool: &SqlitePool) -> sqlx::Result<Summary> {
|
||||
id,
|
||||
name,
|
||||
root_path,
|
||||
log_dirs: parse_log_dirs(&log_dirs),
|
||||
error,
|
||||
vhost_path,
|
||||
vhost_error,
|
||||
unread,
|
||||
files,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user