Compare commits
46 Commits
aad7a0a928
...
v1.3.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f00c229cb | ||
| f4f38cf6d1 | |||
| 6eddc11253 | |||
| c6d5843022 | |||
| ffb84b41a9 | |||
| 7c3467d85f | |||
|
|
a2f2e8f255 | ||
| 5cfafa88cf | |||
| 656917c776 | |||
| 90fd395a26 | |||
| 35cfcb1bcf | |||
| 92ed9b040f | |||
| e52fbaf799 | |||
| 00dc2daa3d | |||
| 7643600196 | |||
| b6375b4242 | |||
| 9393abc8df | |||
| b3fc6f77b1 | |||
| 47bc8ba966 | |||
| 31e101abbd | |||
|
|
126d6b505a | ||
| c758c4d904 | |||
| ffe463e130 | |||
|
|
a8447d6ee1 | ||
| 91d429c4dd | |||
| 505ebd9325 | |||
| d0e39c92b2 | |||
|
|
8bd78a610f | ||
| 975b0f9718 | |||
| 889d723e81 | |||
| 4757c766f6 | |||
| acee6d471c | |||
|
|
60c2fb2d7e | ||
| e372505120 | |||
| 4e393dd5e9 | |||
| 8fd4aba63e | |||
|
|
d63b02fc4e | ||
| 7ed9382e73 | |||
| 539cbdd2f1 | |||
|
|
0d985b62b1 | ||
| 4d76d2697b | |||
| 0863dfad2e | |||
| 440fffc605 | |||
| fb96cc3c32 | |||
| aace834dd4 | |||
| f5cc79f510 |
8
.env.example
Normal file
8
.env.example
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
API_SECRET_KEY=
|
||||||
|
DISCORD_BOT_TOKEN=
|
||||||
|
DISCORD_CHANNEL_ID=
|
||||||
|
BACKUPS_REMOTE_HOST=
|
||||||
|
BACKUPS_REMOTE_ROOT=
|
||||||
|
BACKUPS_MAX_FILES=
|
||||||
|
DISK_COMMAND_REMOTE=
|
||||||
|
DISK_COMMAND_LOCAL=
|
||||||
24
.github/workflows/release.yml
vendored
Normal file
24
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- develop
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 22.x
|
||||||
|
cache: npm
|
||||||
|
|
||||||
|
- run: npm ci
|
||||||
|
|
||||||
|
- run: npx semantic-release
|
||||||
19
.releaserc.json
Normal file
19
.releaserc.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"branches": [
|
||||||
|
"develop"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"@semantic-release/commit-analyzer",
|
||||||
|
"@semantic-release/release-notes-generator",
|
||||||
|
"@semantic-release/changelog",
|
||||||
|
[
|
||||||
|
"@semantic-release/git",
|
||||||
|
{
|
||||||
|
"assets": [
|
||||||
|
"CHANGELOG.md"
|
||||||
|
],
|
||||||
|
"message": "chore(release): ${nextRelease.version}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
193
AGENTS.md
193
AGENTS.md
@@ -1,54 +1,159 @@
|
|||||||
# Repository Guidelines
|
# AGENTS.md
|
||||||
|
|
||||||
## Project Structure & Module Organization
|
## Objectif
|
||||||
This repository is a Nuxt 4 application.
|
|
||||||
- `pages/`: route pages (for example `pages/index.vue`).
|
|
||||||
- `components/`: reusable Vue components (for example `DiskSidebarWidget.vue`, `ApiStatusBubble.vue`).
|
|
||||||
- `layouts/`: shared page shells (`layouts/default.vue`).
|
|
||||||
- `server/api/`: Nitro server endpoints (for example `disk.get.ts`, `version-status.get.ts`).
|
|
||||||
- `assets/css/`: global styles and theme tokens (`main.css`, `malio.css`).
|
|
||||||
- `public/`: static files served as-is.
|
|
||||||
|
|
||||||
Keep feature logic close to usage: UI in `components/`, page composition in `pages/`, backend checks in `server/api/`.
|
Ce fichier définit les règles que tout agent de code doit respecter dans ce dépôt.
|
||||||
|
|
||||||
## Build, Test, and Development Commands
|
Les objectifs sont :
|
||||||
Use npm scripts from `package.json`:
|
- maintenir un code clair et cohérent
|
||||||
- `npm run dev`: start local dev server with hot reload.
|
- éviter la complexité inutile
|
||||||
- `npm run build`: production build (client + server).
|
- empêcher la génération de code mort
|
||||||
- `npm run preview`: run the built app locally.
|
- garantir des modifications prévisibles
|
||||||
- `npm run generate`: static generation when needed.
|
|
||||||
|
|
||||||
There is no dedicated test script currently. At minimum, run `npm run build` before opening a PR.
|
Ce fichier est la source de vérité concernant le comportement de l’agent.
|
||||||
|
|
||||||
## Coding Style & Naming Conventions
|
|
||||||
- Language: TypeScript + Vue SFCs (`<script setup lang="ts">`).
|
|
||||||
- Indentation: 2 spaces.
|
|
||||||
- Prefer double quotes in TS files to match current codebase.
|
|
||||||
- Components: PascalCase file names (`ApiStatusBubble.vue`).
|
|
||||||
- API handlers: kebab-case + HTTP suffix (`version-status.get.ts`).
|
|
||||||
- Use Tailwind utility classes and project color tokens (`text-m-error`, `bg-m-success`, `text-m-primary`).
|
|
||||||
|
|
||||||
## Testing Guidelines
|
## Principes généraux
|
||||||
No automated framework is configured yet. Use these checks:
|
|
||||||
- Build validation: `npm run build`.
|
|
||||||
- Manual smoke test: open `/`, verify API status cards refresh and disk sidebar renders.
|
|
||||||
- For new endpoints, validate response shape in browser/network tab or `curl`.
|
|
||||||
|
|
||||||
## Commit & Pull Request Guidelines
|
Toujours produire un code clair, simple et minimal.
|
||||||
Git history is not available in this workspace snapshot, so use this convention:
|
|
||||||
- Commit format: `type(scope): short summary`.
|
|
||||||
- Example: `feat(api): add labeled multi-endpoint status check`.
|
|
||||||
- Types: `feat`, `fix`, `refactor`, `style`, `docs`, `chore`.
|
|
||||||
|
|
||||||
PRs should include:
|
Privilégier les implémentations explicites plutôt que les abstractions.
|
||||||
- What changed and why.
|
|
||||||
- Affected paths (e.g. `server/api/version-status.get.ts`).
|
|
||||||
- UI screenshots for visual changes.
|
|
||||||
- Verification steps (commands run, expected result).
|
|
||||||
|
|
||||||
## Security & Configuration Notes
|
Ne jamais introduire de nouveaux patterns si un pattern existant résout déjà le problème.
|
||||||
- Do not hardcode secrets in source.
|
|
||||||
- Prefer environment variables for private endpoints/tokens.
|
|
||||||
- Keep external API checks server-side (`server/api/*`) to avoid exposing sensitive details in the client.
|
|
||||||
|
|
||||||
Ne lance pas de build si je le dit pas
|
Ne jamais générer :
|
||||||
|
- du code mort
|
||||||
|
- du code inutilisé
|
||||||
|
- du code spéculatif
|
||||||
|
- des fonctionnalités non demandées
|
||||||
|
|
||||||
|
|
||||||
|
## Lecture obligatoire avant modification
|
||||||
|
|
||||||
|
Avant toute modification de code, l’agent doit :
|
||||||
|
|
||||||
|
Lire entièrement le fichier à modifier.
|
||||||
|
|
||||||
|
Comprendre la structure et les conventions existantes.
|
||||||
|
|
||||||
|
Respecter :
|
||||||
|
- les conventions de nommage
|
||||||
|
- le style du fichier
|
||||||
|
- l’architecture déjà utilisée
|
||||||
|
|
||||||
|
Vérifier les fichiers liés pouvant être impactés.
|
||||||
|
|
||||||
|
Ne jamais proposer une modification sur du code qui n’a pas été lu.
|
||||||
|
|
||||||
|
|
||||||
|
## Règles de modification
|
||||||
|
|
||||||
|
Lors de l’édition de code :
|
||||||
|
|
||||||
|
Respecter l’architecture existante.
|
||||||
|
|
||||||
|
Réutiliser les utilitaires et fonctions déjà présents lorsque c’est possible.
|
||||||
|
|
||||||
|
Ne pas ajouter de dépendances sauf nécessité réelle.
|
||||||
|
|
||||||
|
Ne pas refactoriser du code non lié à la demande.
|
||||||
|
|
||||||
|
Faire des modifications minimales et ciblées.
|
||||||
|
|
||||||
|
Toujours préférer modifier du code existant plutôt que créer une logique parallèle.
|
||||||
|
|
||||||
|
|
||||||
|
## Qualité du code
|
||||||
|
|
||||||
|
Le code généré doit garantir :
|
||||||
|
|
||||||
|
Aucun code mort.
|
||||||
|
|
||||||
|
Aucune variable inutilisée.
|
||||||
|
|
||||||
|
Aucune branche inaccessible.
|
||||||
|
|
||||||
|
Aucune duplication inutile.
|
||||||
|
|
||||||
|
Aucune abstraction prématurée.
|
||||||
|
|
||||||
|
Si une logique n’est pas utilisée immédiatement, elle ne doit pas être écrite.
|
||||||
|
|
||||||
|
|
||||||
|
## Cohérence architecturale
|
||||||
|
|
||||||
|
Toujours suivre les conventions du dépôt.
|
||||||
|
|
||||||
|
Respecter notamment :
|
||||||
|
|
||||||
|
les conventions de nommage
|
||||||
|
l’organisation des fichiers
|
||||||
|
les patterns architecturaux existants
|
||||||
|
les composants ou modules déjà présents
|
||||||
|
|
||||||
|
|
||||||
|
## Sécurité Git
|
||||||
|
|
||||||
|
L’agent ne doit jamais :
|
||||||
|
|
||||||
|
créer un commit sans demande explicite
|
||||||
|
|
||||||
|
push des modifications
|
||||||
|
|
||||||
|
force push
|
||||||
|
|
||||||
|
modifier la configuration git
|
||||||
|
|
||||||
|
réécrire l’historique
|
||||||
|
|
||||||
|
|
||||||
|
## Sécurité
|
||||||
|
|
||||||
|
Ne jamais introduire dans le code :
|
||||||
|
|
||||||
|
des secrets
|
||||||
|
|
||||||
|
des identifiants
|
||||||
|
|
||||||
|
des tokens
|
||||||
|
|
||||||
|
des variables d’environnement sensibles
|
||||||
|
|
||||||
|
|
||||||
|
## Prise de décision
|
||||||
|
|
||||||
|
Si plusieurs implémentations sont possibles :
|
||||||
|
|
||||||
|
choisir la solution la plus simple
|
||||||
|
|
||||||
|
choisir la solution la plus cohérente avec le code existant
|
||||||
|
|
||||||
|
éviter d’introduire un nouveau pattern architectural
|
||||||
|
|
||||||
|
|
||||||
|
## Actions interdites
|
||||||
|
|
||||||
|
L’agent ne doit jamais :
|
||||||
|
|
||||||
|
ajouter des fonctionnalités non demandées
|
||||||
|
|
||||||
|
introduire du code mort
|
||||||
|
|
||||||
|
introduire des abstractions prématurées
|
||||||
|
|
||||||
|
modifier des fichiers non liés
|
||||||
|
|
||||||
|
réécrire de larges parties du projet sans instruction explicite
|
||||||
|
|
||||||
|
|
||||||
|
## Résultat attendu
|
||||||
|
|
||||||
|
Le code généré doit être :
|
||||||
|
|
||||||
|
lisible
|
||||||
|
|
||||||
|
minimal
|
||||||
|
|
||||||
|
cohérent avec le dépôt
|
||||||
|
|
||||||
|
immédiatement utilisable
|
||||||
60
CHANGELOG.md
Normal file
60
CHANGELOG.md
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
## [1.3.1](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.3.0...v1.3.1) (2026-03-16)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* arch-02 make type file ([ffb84b4](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/ffb84b41a9e15b2edc98378c94050c74c9d200c6))
|
||||||
|
* arch-03 worker system metric ([6eddc11](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/6eddc1125316bb0d77a7c71cfc4674cd99c6e296))
|
||||||
|
* arch-03 worker system metric ([c6d5843](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/c6d5843022bbdcf909662c2c9ce47fb14f88b5a2))
|
||||||
|
* extract shared ssh utilities ([7c3467d](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/7c3467d85f987f1d9b8fe2546a13c2d23ea841b4))
|
||||||
|
|
||||||
|
# [1.3.0](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.4...v1.3.0) (2026-03-13)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add system metrics dashboard ([31e101a](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/31e101abbd3ed82c22770d840a4f7fd20de1c936))
|
||||||
|
|
||||||
|
## [1.2.4](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.3...v1.2.4) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* bundle latest backup downloads ([ffe463e](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/ffe463e13034601843446514abbd7c69cbaee081))
|
||||||
|
|
||||||
|
## [1.2.3](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.2...v1.2.3) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add scroll to backup history ([505ebd9](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/505ebd9325c0aa54adb034c012c45c913bb36d73))
|
||||||
|
* restore backup history listing ([d0e39c9](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/d0e39c92b270993c99cde0eed8577c6dde817fdd))
|
||||||
|
|
||||||
|
## [1.2.2](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.1...v1.2.2) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* align backup ui and downloads ([4757c76](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/4757c766f613a1888b62716a2c6852c8d92e3f6e))
|
||||||
|
* ssh connection correctif ([acee6d4](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/acee6d471c63671bfb9bdef62a3b6e2ebe40ba55))
|
||||||
|
|
||||||
|
## [1.2.1](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.0...v1.2.1) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* reduce style loading flash ([4e393dd](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/4e393dd5e92a28d91e49affb9437687ac8de3817))
|
||||||
|
|
||||||
|
# [1.2.0](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.1.0...v1.2.0) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* show git tag version ([539cbdd](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/539cbdd2f1fa73eddab8adb6e2cc0683e6c424aa))
|
||||||
|
|
||||||
|
# [1.1.0](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.0.0...v1.1.0) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **backup:** add backup scripts workflow ([0863dfa](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/0863dfad2e3c6272a012c30820381a2610e22d1b))
|
||||||
128
README.md
128
README.md
@@ -1,75 +1,93 @@
|
|||||||
# Nuxt Minimal Starter
|
# Projet Monitoring
|
||||||
|
|
||||||
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
|
## Installation du projet
|
||||||
|
|
||||||
## Setup
|
### Windows
|
||||||
|
Sur Windows, installer WSL2, Ubuntu, Docker et nvm.
|
||||||
|
Suivre la documentation suivante :
|
||||||
|
https://wiki.malio.fr/bookstack/books/environnement-de-dev/chapter/windows
|
||||||
|
|
||||||
Make sure to install dependencies:
|
### Linux
|
||||||
|
Sur Linux, installer Docker et nvm.
|
||||||
|
Suivre la documentation suivante :
|
||||||
|
https://wiki.malio.fr/bookstack/books/environnement-de-dev/chapter/linux
|
||||||
|
|
||||||
|
### Installation du projet
|
||||||
|
Une fois les prérequis installés, cloner le dépôt puis installer les dépendances.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# npm
|
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
# pnpm
|
|
||||||
pnpm install
|
|
||||||
|
|
||||||
# yarn
|
|
||||||
yarn install
|
|
||||||
|
|
||||||
# bun
|
|
||||||
bun install
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development Server
|
Lancer ensuite le serveur de développement.
|
||||||
|
|
||||||
Start the development server on `http://localhost:3000`:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# npm
|
|
||||||
npm run dev
|
npm run dev
|
||||||
|
|
||||||
# pnpm
|
|
||||||
pnpm dev
|
|
||||||
|
|
||||||
# yarn
|
|
||||||
yarn dev
|
|
||||||
|
|
||||||
# bun
|
|
||||||
bun run dev
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Production
|
L’application sera accessible sur :
|
||||||
|
http://localhost:3000
|
||||||
|
|
||||||
Build the application for production:
|
Si une erreur liée à la version de Node apparaît, vérifier que Node ≥ 20 est utilisé via nvm.
|
||||||
|
|
||||||
```bash
|
nvm install 20
|
||||||
# npm
|
nvm use 20
|
||||||
|
|
||||||
|
## Utilisation du projet
|
||||||
|
### Frontend
|
||||||
|
|
||||||
|
Lancer le serveur de développement.
|
||||||
|
```
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
Compilation pour la production.
|
||||||
|
```
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
# pnpm
|
|
||||||
pnpm build
|
|
||||||
|
|
||||||
# yarn
|
|
||||||
yarn build
|
|
||||||
|
|
||||||
# bun
|
|
||||||
bun run build
|
|
||||||
```
|
```
|
||||||
|
Prévisualisation du build de production.
|
||||||
Locally preview production build:
|
```
|
||||||
|
|
||||||
```bash
|
|
||||||
# npm
|
|
||||||
npm run preview
|
npm run preview
|
||||||
|
|
||||||
# pnpm
|
|
||||||
pnpm preview
|
|
||||||
|
|
||||||
# yarn
|
|
||||||
yarn preview
|
|
||||||
|
|
||||||
# bun
|
|
||||||
bun run preview
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
|
## Commandes utiles
|
||||||
|
|
||||||
|
Installation des dépendances.
|
||||||
|
```
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
Lancer le serveur de développement.
|
||||||
|
```
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
Build de production.
|
||||||
|
```
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
Prévisualisation du build.
|
||||||
|
```
|
||||||
|
npm run preview
|
||||||
|
```
|
||||||
|
Supprimer les dépendances et réinstaller proprement.
|
||||||
|
```
|
||||||
|
rm -rf node_modules package-lock.json
|
||||||
|
npm install
|
||||||
|
Déploiement
|
||||||
|
```
|
||||||
|
Construire l’application.
|
||||||
|
```
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
Les fichiers générés se trouvent dans :
|
||||||
|
.output/
|
||||||
|
|
||||||
|
Le serveur peut ensuite être lancé avec :
|
||||||
|
```
|
||||||
|
node .output/server/index.mjs
|
||||||
|
```
|
||||||
|
Il est recommandé d’utiliser un reverse proxy comme Nginx en production.
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
|
||||||
|
Les accès SSH ou les chemins système utilisés par les endpoints doivent rester côté serveur.
|
||||||
|
Ne jamais exposer de credentials dans le frontend.
|
||||||
|
Les variables sensibles doivent être stockées dans un fichier .env.
|
||||||
@@ -13,15 +13,155 @@
|
|||||||
--color-m-bg: rgb(var(--m-bg));
|
--color-m-bg: rgb(var(--m-bg));
|
||||||
--color-m-error: rgb(var(--m-error));
|
--color-m-error: rgb(var(--m-error));
|
||||||
--color-m-success: rgb(var(--m-success));
|
--color-m-success: rgb(var(--m-success));
|
||||||
/* Alias pour la faute de frappe courante "m-succes" */
|
--color-m-accent: rgb(var(--m-accent));
|
||||||
|
--color-m-warning: rgb(var(--m-warning));
|
||||||
--color-m-succes: rgb(var(--m-success));
|
--color-m-succes: rgb(var(--m-success));
|
||||||
|
--font-display: "Outfit", system-ui, sans-serif;
|
||||||
|
--font-mono: "JetBrains Mono", "Fira Code", monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
html {
|
||||||
|
background: rgb(var(--m-bg));
|
||||||
|
color-scheme: dark;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
min-height: 100vh;
|
||||||
|
font-family: var(--font-display);
|
||||||
|
background: rgb(var(--m-bg));
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
transition: background-color 0.4s ease, color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer utilities {
|
@layer utilities {
|
||||||
.bg-grid {
|
.bg-grid {
|
||||||
background-image:
|
background-image:
|
||||||
linear-gradient(to right, rgba(148, 163, 184, 0.12) 1px, transparent 1px),
|
linear-gradient(to right, rgb(var(--m-accent) / 0.04) 1px, transparent 1px),
|
||||||
linear-gradient(to bottom, rgba(148, 163, 184, 0.12) 1px, transparent 1px);
|
linear-gradient(to bottom, rgb(var(--m-accent) / 0.04) 1px, transparent 1px);
|
||||||
background-size: 32px 32px;
|
background-size: 32px 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bg-noise {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bg-noise::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
opacity: 0.025;
|
||||||
|
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-glow {
|
||||||
|
box-shadow:
|
||||||
|
0 0 0 1px rgb(var(--m-accent) / var(--m-card-border-opacity)),
|
||||||
|
0 4px 24px -4px rgba(0, 0, 0, var(--m-shadow-opacity)),
|
||||||
|
0 0 48px -12px rgb(var(--m-accent) / 0.06);
|
||||||
|
transition: box-shadow 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-glow-success {
|
||||||
|
box-shadow:
|
||||||
|
0 0 0 1px rgb(var(--m-success) / 0.15),
|
||||||
|
0 4px 24px -4px rgba(0, 0, 0, var(--m-shadow-opacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-glow-error {
|
||||||
|
box-shadow:
|
||||||
|
0 0 0 1px rgb(var(--m-error) / 0.15),
|
||||||
|
0 4px 24px -4px rgba(0, 0, 0, var(--m-shadow-opacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-gradient {
|
||||||
|
background: linear-gradient(135deg, rgb(var(--m-accent)), rgb(var(--m-success)));
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
background-clip: text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade-in-up {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse-glow {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
box-shadow: 0 0 4px currentColor, 0 0 8px currentColor;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
box-shadow: 0 0 8px currentColor, 0 0 16px currentColor;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes shimmer {
|
||||||
|
0% {
|
||||||
|
background-position: -200% 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
background-position: 200% 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.animate-fade-in-up {
|
||||||
|
animation: fade-in-up 0.5s ease-out both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.animate-pulse-glow {
|
||||||
|
animation: pulse-glow 2s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.animate-shimmer {
|
||||||
|
background: linear-gradient(
|
||||||
|
90deg,
|
||||||
|
var(--m-shimmer-from) 0%,
|
||||||
|
var(--m-shimmer-to) 50%,
|
||||||
|
var(--m-shimmer-from) 100%
|
||||||
|
);
|
||||||
|
background-size: 200% 100%;
|
||||||
|
animation: shimmer 2s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: rgb(var(--m-bg));
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: rgb(var(--m-border));
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgb(var(--m-muted));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
@tailwind base;
|
|
||||||
@tailwind components;
|
|
||||||
@tailwind utilities;
|
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
:root {
|
:root {
|
||||||
/* Couleurs en RGB “space separated” pour Tailwind */
|
--m-primary: 15 20 40;
|
||||||
--m-primary: 34 39 131; /* Couleur principal*/
|
--m-secondary: 22 30 55;
|
||||||
--m-secondary: 48 73 152; /* Couleur secondaire */
|
--m-tertiary: 30 41 72;
|
||||||
--m-tertiary: 243 244 248; /* Couleur tertiaire (background) */
|
--m-border: 55 70 110;
|
||||||
--m-border: 203 213 225; /* Couleur des bordures */
|
--m-text: 220 225 240;
|
||||||
--m-text: 15 23 42; /* Couleur du texte */
|
--m-muted: 130 145 175;
|
||||||
--m-muted: 100 116 139; /* Couleur pour les éléments désactivés ou secondaires */
|
--m-bg: 10 14 30;
|
||||||
--m-bg: 243 244 248; /* Couleur de fond générale */
|
--m-error: 255 70 70;
|
||||||
|
--m-success: 0 220 180;
|
||||||
--m-error: 212 0 21; /* rouge pour les erreurs */
|
--m-accent: 80 140 255;
|
||||||
--m-success: 15 200 73; /* vert pour les succès */
|
--m-warning: 255 180 50;
|
||||||
}
|
--m-shadow-opacity: 0.4;
|
||||||
|
--m-glow-opacity: 0.1;
|
||||||
|
--m-card-border-opacity: 0.1;
|
||||||
|
--m-shimmer-from: rgba(80, 140, 255, 0.05);
|
||||||
|
--m-shimmer-to: rgba(80, 140, 255, 0.12);
|
||||||
|
--m-sidebar-from: 15 20 40;
|
||||||
|
--m-sidebar-to: 15 18 35;
|
||||||
|
--m-sidebar-border: rgba(80, 140, 255, 0.08);
|
||||||
|
--m-sidebar-divider: rgba(80, 140, 255, 0.2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +1,99 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="bg-m-secondary w-[250px] h-[259px] rounded-md mx-4 shadow-md/50 shadow-black">
|
<div class="backup-card card-glow">
|
||||||
<p class="font-bold text-3xl text-m-tertiary my-1 mx-3">
|
<div class="card-header">
|
||||||
Backup
|
<h2 class="card-title">Backup</h2>
|
||||||
</p>
|
<span class="font-mono text-[10px] text-m-muted tracking-widest uppercase">Dossiers</span>
|
||||||
<button
|
</div>
|
||||||
type="button"
|
|
||||||
class="bg-m-tertiary w-[200px] h-[32px] rounded-md shadow-md/50 shadow-m-black mx-3 mb-[10px] flex items-center justify-between cursor-pointer"
|
|
||||||
@click="select('bitwarden')"
|
|
||||||
>
|
|
||||||
<p class="font-bold uppercase text-xl ml-[24px]">
|
|
||||||
bitwarden
|
|
||||||
</p>
|
|
||||||
<IconifyIcon
|
|
||||||
icon="mdi:eye"
|
|
||||||
class="text-black text-2xl mr-[24px]"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
<div class="backup-list">
|
||||||
|
<button
|
||||||
|
v-for="item in folders"
|
||||||
|
:key="item.name"
|
||||||
type="button"
|
type="button"
|
||||||
class="bg-m-tertiary w-[200px] h-[32px] rounded-md shadow-md/50 shadow-m-black mx-3 mb-[10px] flex items-center justify-between cursor-pointer"
|
class="backup-btn"
|
||||||
@click="select('inventory')"
|
:class="{ 'backup-btn-active': active === item.name }"
|
||||||
>
|
@click="select(item.name)"
|
||||||
<p class="font-bold uppercase text-xl ml-[24px]">
|
>
|
||||||
inventory
|
<div class="flex items-center gap-2.5">
|
||||||
</p>
|
<IconifyIcon :icon="item.icon" class="text-base text-m-accent" />
|
||||||
<IconifyIcon
|
<span class="font-display text-sm font-semibold uppercase tracking-wide">
|
||||||
icon="mdi:eye"
|
{{ item.name }}
|
||||||
class="text-black text-2xl mr-[24px]"
|
</span>
|
||||||
/>
|
</div>
|
||||||
</button>
|
<IconifyIcon
|
||||||
|
icon="mdi:chevron-right"
|
||||||
<button
|
class="text-lg text-m-muted transition-transform duration-200"
|
||||||
type="button"
|
:class="{ 'translate-x-0.5 !text-m-accent': active === item.name }"
|
||||||
class="bg-m-tertiary w-[200px] h-[32px] rounded-md shadow-md/50 shadow-m-black mx-3 mb-[10px] flex items-center justify-between cursor-pointer"
|
/>
|
||||||
@click="select('sirh')"
|
</button>
|
||||||
>
|
</div>
|
||||||
<p class="font-bold uppercase text-xl ml-[24px]">
|
|
||||||
sirh
|
|
||||||
</p>
|
|
||||||
<IconifyIcon
|
|
||||||
icon="mdi:eye"
|
|
||||||
class="text-black text-2xl mr-[24px]"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="bg-m-tertiary w-[200px] h-[32px] rounded-md shadow-md/50 shadow-m-black mx-3 mb-[10px] flex items-center justify-between cursor-pointer"
|
|
||||||
@click="select('ferme')"
|
|
||||||
>
|
|
||||||
<p class="font-bold uppercase text-xl ml-[24px]">
|
|
||||||
ferme
|
|
||||||
</p>
|
|
||||||
<IconifyIcon
|
|
||||||
icon="mdi:eye"
|
|
||||||
class="text-black text-2xl mr-[24px]"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="bg-m-tertiary w-[200px] h-[32px] rounded-md shadow-md/50 shadow-m-black mx-3 mb-[10px] flex items-center justify-between cursor-pointer"
|
|
||||||
@click="select('user')"
|
|
||||||
>
|
|
||||||
<p class="font-bold uppercase text-xl ml-[24px]">
|
|
||||||
user
|
|
||||||
</p>
|
|
||||||
<IconifyIcon
|
|
||||||
icon="mdi:eye"
|
|
||||||
class="text-black text-2xl mr-[24px]"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { ref } from "vue"
|
||||||
import { Icon as IconifyIcon } from "@iconify/vue"
|
import { Icon as IconifyIcon } from "@iconify/vue"
|
||||||
|
import backupOptions from "~/server/config/backup-options.json"
|
||||||
|
|
||||||
const emit = defineEmits(["select"])
|
const emit = defineEmits(["select"])
|
||||||
|
const active = ref<string | null>(null)
|
||||||
|
const folders = backupOptions as Array<{ name: string; icon: string }>
|
||||||
|
|
||||||
const select = (name: string) => {
|
const select = (name: string) => {
|
||||||
|
active.value = name
|
||||||
emit("select", name)
|
emit("select", name)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.backup-card {
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
transition: background-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.375rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.625rem 0.875rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
border: 1px solid transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-btn:hover {
|
||||||
|
border-color: rgb(var(--m-accent) / 0.15);
|
||||||
|
background: rgb(var(--m-accent) / 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-btn-active {
|
||||||
|
border-color: rgb(var(--m-accent) / 0.25);
|
||||||
|
background: rgb(var(--m-accent) / 0.08);
|
||||||
|
box-shadow: 0 0 12px -4px rgb(var(--m-accent) / 0.15);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,46 +1,68 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="bg-m-secondary w-[507px] h-[367px] rounded-md mx-4 shadow-md/50 shadow-black">
|
<div class="backup-list-card card-glow">
|
||||||
<p class="font-bold text-3xl text-m-tertiary my-1 mx-3">
|
<div class="card-header">
|
||||||
{{ title }}
|
<h2 class="card-title">{{ title }}</h2>
|
||||||
</p>
|
</div>
|
||||||
|
|
||||||
<div v-if="loading">
|
<div v-if="!folder" class="empty-state">
|
||||||
|
<IconifyIcon icon="mdi:folder-open-outline" class="text-3xl text-m-muted/40" />
|
||||||
|
<p class="mt-2 font-mono text-xs text-m-muted/50">
|
||||||
|
Selectionnez un dossier
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="loading" class="file-list">
|
||||||
<div
|
<div
|
||||||
v-for="n in 6"
|
v-for="n in 6"
|
||||||
:key="`backup-skeleton-${n}`"
|
:key="`backup-skeleton-${n}`"
|
||||||
class="relative w-[483px] h-[39px] mx-3 mb-[10px]"
|
class="file-row animate-shimmer"
|
||||||
>
|
>
|
||||||
<ButtonSkeleton custom-class="h-full w-full" />
|
<TextSkeleton custom-class="h-4 w-48" />
|
||||||
<div class="absolute inset-0 flex items-center justify-between px-3">
|
<CircleSkeleton custom-class="h-5 w-5 rounded" />
|
||||||
<TextSkeleton custom-class="h-5 w-[260px]" />
|
|
||||||
<CircleSkeleton custom-class="h-6 w-6 rounded-md" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<div v-else-if="errorMessage" class="empty-state error-state">
|
||||||
v-else
|
<IconifyIcon icon="mdi:alert-circle-outline" class="text-3xl text-m-error/70" />
|
||||||
|
<p class="mt-2 font-mono text-xs text-m-error/80">
|
||||||
|
{{ errorMessage }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="backups.length === 0" class="empty-state">
|
||||||
|
<IconifyIcon icon="mdi:file-hidden" class="text-3xl text-m-muted/40" />
|
||||||
|
<p class="mt-2 font-mono text-xs text-m-muted/50">
|
||||||
|
Aucun backup trouve
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="file-list">
|
||||||
|
<button
|
||||||
v-for="file in backups"
|
v-for="file in backups"
|
||||||
:key="file"
|
:key="file"
|
||||||
class="bg-m-tertiary w-[483px] h-[39px] rounded-md shadow-md/50 shadow-m-black mx-3 mb-[10px] flex items-center justify-between cursor-pointer"
|
class="file-row"
|
||||||
@click="downloadBackup(file)"
|
@click="downloadBackup(file)"
|
||||||
>
|
>
|
||||||
<p class="text-xl ml-3 truncate max-w-[400px]">
|
<div class="flex min-w-0 items-center gap-2.5">
|
||||||
{{ file }}
|
<IconifyIcon icon="mdi:file-document-outline" class="text-base text-m-accent flex-shrink-0" />
|
||||||
</p>
|
<span class="truncate font-mono text-xs text-m-text">
|
||||||
|
{{ file }}
|
||||||
<IconifyIcon
|
</span>
|
||||||
|
</div>
|
||||||
|
<IconifyIcon
|
||||||
icon="mdi:download"
|
icon="mdi:download"
|
||||||
class="text-black text-2xl mr-3"
|
class="text-base text-m-muted flex-shrink-0 transition-colors duration-200"
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {Icon as IconifyIcon} from "@iconify/vue"
|
import {Icon as IconifyIcon} from "@iconify/vue"
|
||||||
import ButtonSkeleton from "~/components/skeleton/ButtonSkeleton.vue"
|
|
||||||
import CircleSkeleton from "~/components/skeleton/CircleSkeleton.vue"
|
import CircleSkeleton from "~/components/skeleton/CircleSkeleton.vue"
|
||||||
import TextSkeleton from "~/components/skeleton/TextSkeleton.vue"
|
import TextSkeleton from "~/components/skeleton/TextSkeleton.vue"
|
||||||
|
import { apiFetch, downloadApiFile } from "~/composables/useApiAuth"
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
folder: string | null
|
folder: string | null
|
||||||
@@ -48,33 +70,109 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const backups = ref<string[]>([])
|
const backups = ref<string[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const errorMessage = ref("")
|
||||||
const title = computed(() => {
|
const title = computed(() => {
|
||||||
if (!props.folder) return "Backup"
|
if (!props.folder) return "Fichiers"
|
||||||
return `Liste des backup de ${props.folder.toUpperCase()}`
|
return `Backup — ${props.folder.toUpperCase()}`
|
||||||
})
|
})
|
||||||
|
|
||||||
const downloadBackup = (file: string) => {
|
const downloadBackup = async (file: string) => {
|
||||||
if (!props.folder) return
|
if (!props.folder) return
|
||||||
const url = `/api/download?folder=${encodeURIComponent(props.folder)}&file=${encodeURIComponent(file)}`
|
const url = `/api/download?folder=${encodeURIComponent(props.folder)}&file=${encodeURIComponent(file)}`
|
||||||
window.location.href = url
|
errorMessage.value = ""
|
||||||
|
|
||||||
|
try {
|
||||||
|
await downloadApiFile(url, file)
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur telechargement backup:", error)
|
||||||
|
errorMessage.value = "Erreur lors de l'opération"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(() => props.folder, async (folder) => {
|
watch(() => props.folder, async (folder) => {
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
backups.value = []
|
backups.value = []
|
||||||
|
errorMessage.value = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
errorMessage.value = ""
|
||||||
try {
|
try {
|
||||||
const data = await $fetch<string[]>(`/api/backups?folder=${folder}`)
|
const data = await apiFetch<string[]>(`/api/backups?folder=${encodeURIComponent(folder)}`)
|
||||||
backups.value = data.slice(0, 6)
|
backups.value = data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erreur récupération backups:", error)
|
console.error("Erreur récupération backups:", error)
|
||||||
backups.value = []
|
backups.value = []
|
||||||
|
errorMessage.value = "Erreur lors de l'opération"
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.backup-list-card {
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
transition: background-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 2.5rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-state {
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgb(var(--m-error) / 0.12);
|
||||||
|
background: rgb(var(--m-error) / 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.375rem;
|
||||||
|
max-height: calc((2.875rem * 5) + (0.375rem * 4));
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-right: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-row {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.625rem 0.875rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
border: 1px solid transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-row:hover {
|
||||||
|
border-color: rgb(var(--m-accent) / 0.15);
|
||||||
|
background: rgb(var(--m-accent) / 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-row:hover .text-m-muted {
|
||||||
|
color: rgb(var(--m-accent));
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
296
components/BackupRun.vue
Normal file
296
components/BackupRun.vue
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="backup-card card-glow"
|
||||||
|
:class="{
|
||||||
|
'card-glow-success': message && !isError,
|
||||||
|
'card-glow-error': message && isError
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<div class="card-header">
|
||||||
|
<h2 class="card-title">Run Script</h2>
|
||||||
|
<span class="font-mono text-[10px] text-m-muted tracking-widest uppercase">Scripts</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="loading"
|
||||||
|
class="status-box"
|
||||||
|
role="status"
|
||||||
|
aria-live="polite"
|
||||||
|
aria-busy="true"
|
||||||
|
>
|
||||||
|
Chargement des scripts...
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else-if="scripts.length"
|
||||||
|
class="backup-list"
|
||||||
|
:aria-busy="runningKey !== null"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
v-for="item in scripts"
|
||||||
|
:key="item.key"
|
||||||
|
type="button"
|
||||||
|
class="backup-btn"
|
||||||
|
:class="{ 'backup-btn-active': active === item.key }"
|
||||||
|
:disabled="runningKey !== null"
|
||||||
|
:aria-pressed="active === item.key"
|
||||||
|
:aria-label="`Executer ${item.label}`"
|
||||||
|
@click="runScript(item.key)"
|
||||||
|
>
|
||||||
|
<div class="flex items-center gap-2.5">
|
||||||
|
<IconifyIcon :icon="item.icon" class="text-base text-m-accent" />
|
||||||
|
<span class="font-display text-sm font-semibold uppercase tracking-wide">
|
||||||
|
{{ item.label }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<IconifyIcon
|
||||||
|
:icon="runningKey === item.key ? 'mdi:loading' : 'mdi:play'"
|
||||||
|
class="text-lg text-m-muted transition-transform duration-200"
|
||||||
|
:class="{
|
||||||
|
'translate-x-0.5 !text-m-accent': active === item.key,
|
||||||
|
'animate-spin': runningKey === item.key
|
||||||
|
}"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="status-box status-empty"
|
||||||
|
role="status"
|
||||||
|
aria-live="polite"
|
||||||
|
>
|
||||||
|
Aucun script disponible.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="message"
|
||||||
|
class="status-box"
|
||||||
|
:class="statusClass"
|
||||||
|
role="status"
|
||||||
|
:aria-live="isError ? 'assertive' : 'polite'"
|
||||||
|
>
|
||||||
|
<p class="status-title">{{ message }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted, ref } from "vue"
|
||||||
|
import { Icon as IconifyIcon } from "@iconify/vue"
|
||||||
|
import { apiFetch } from "~/composables/useApiAuth"
|
||||||
|
|
||||||
|
type BackupScript = {
|
||||||
|
key: string
|
||||||
|
label: string
|
||||||
|
icon: string
|
||||||
|
downloadFolders?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type BackupScriptListResponse = {
|
||||||
|
scripts: BackupScript[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type BackupScriptRunResponse = {
|
||||||
|
ok: boolean
|
||||||
|
key: string
|
||||||
|
label: string
|
||||||
|
downloadFolders?: string[]
|
||||||
|
output: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ScriptResult = {
|
||||||
|
key: string | null
|
||||||
|
label: string
|
||||||
|
output: string
|
||||||
|
isError: boolean
|
||||||
|
downloadFolders: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
result: [payload: ScriptResult]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const active = ref<string | null>(null)
|
||||||
|
const loading = ref(true)
|
||||||
|
const runningKey = ref<string | null>(null)
|
||||||
|
const scripts = ref<BackupScript[]>([])
|
||||||
|
const output = ref<string>("")
|
||||||
|
const message = ref<string>("")
|
||||||
|
const isError = ref(false)
|
||||||
|
|
||||||
|
const statusClass = computed(() => (isError.value ? "status-error" : "status-success"))
|
||||||
|
|
||||||
|
const loadScripts = async () => {
|
||||||
|
loading.value = true
|
||||||
|
message.value = ""
|
||||||
|
output.value = ""
|
||||||
|
isError.value = false
|
||||||
|
emit("result", {
|
||||||
|
key: null,
|
||||||
|
label: "",
|
||||||
|
output: "",
|
||||||
|
isError: false,
|
||||||
|
downloadFolders: []
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
const data = await apiFetch<BackupScriptListResponse>("/api/backup-script")
|
||||||
|
scripts.value = data.scripts
|
||||||
|
} catch {
|
||||||
|
scripts.value = []
|
||||||
|
isError.value = true
|
||||||
|
message.value = "Erreur lors de l'opération"
|
||||||
|
emit("result", {
|
||||||
|
key: null,
|
||||||
|
label: "",
|
||||||
|
output: "",
|
||||||
|
isError: true,
|
||||||
|
downloadFolders: []
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const runScript = async (key: string) => {
|
||||||
|
active.value = key
|
||||||
|
runningKey.value = key
|
||||||
|
output.value = ""
|
||||||
|
message.value = ""
|
||||||
|
isError.value = false
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await apiFetch<BackupScriptRunResponse>("/api/backup-script", {
|
||||||
|
method: "POST",
|
||||||
|
body: { key }
|
||||||
|
})
|
||||||
|
message.value = `${data.label} execute avec succes`
|
||||||
|
output.value = data.output || "Aucune sortie retournee."
|
||||||
|
emit("result", {
|
||||||
|
key: data.key,
|
||||||
|
label: data.label,
|
||||||
|
output: output.value,
|
||||||
|
isError: false,
|
||||||
|
downloadFolders: data.downloadFolders || []
|
||||||
|
})
|
||||||
|
} catch (error: unknown) {
|
||||||
|
isError.value = true
|
||||||
|
const statusMessage =
|
||||||
|
typeof error === "object" &&
|
||||||
|
error !== null &&
|
||||||
|
"data" in error &&
|
||||||
|
typeof error.data === "object" &&
|
||||||
|
error.data !== null &&
|
||||||
|
"statusMessage" in error.data &&
|
||||||
|
typeof error.data.statusMessage === "string"
|
||||||
|
? error.data.statusMessage
|
||||||
|
: null
|
||||||
|
|
||||||
|
message.value = statusMessage || "Erreur lors de l'opération"
|
||||||
|
message.value = error?.data?.statusMessage || "Erreur execution script"
|
||||||
|
output.value = ""
|
||||||
|
emit("result", {
|
||||||
|
key,
|
||||||
|
label: scripts.value.find((item) => item.key === key)?.label || key,
|
||||||
|
output: "",
|
||||||
|
isError: true,
|
||||||
|
downloadFolders: []
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
runningKey.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(loadScripts)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.backup-card {
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
transition: background-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.375rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.625rem 0.875rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
border: 1px solid transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-btn:focus-visible {
|
||||||
|
outline: 2px solid rgb(var(--m-accent) / 0.7);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-btn:disabled {
|
||||||
|
cursor: wait;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-btn:hover {
|
||||||
|
border-color: rgb(var(--m-accent) / 0.15);
|
||||||
|
background: rgb(var(--m-accent) / 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-btn-active {
|
||||||
|
border-color: rgb(var(--m-accent) / 0.25);
|
||||||
|
background: rgb(var(--m-accent) / 0.08);
|
||||||
|
box-shadow: 0 0 12px -4px rgb(var(--m-accent) / 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-box {
|
||||||
|
margin-top: 0.75rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 0.875rem;
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-success {
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-error {
|
||||||
|
border: 1px solid rgb(255 99 99 / 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-empty {
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-title {
|
||||||
|
margin: 0;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,35 +1,48 @@
|
|||||||
<template>
|
<template>
|
||||||
<section class="flex flex-col items-center p-4">
|
<section class="storage-card">
|
||||||
<template v-if="loading">
|
<template v-if="item.loading">
|
||||||
<TextSkeleton custom-class="h-7 w-40" />
|
<TextSkeleton custom-class="h-5 w-28" />
|
||||||
<CircleSkeleton custom-class="mt-2 h-[140px] w-[140px]" />
|
<CircleSkeleton custom-class="mt-3 h-[120px] w-[120px]" />
|
||||||
<BlockSkeleton custom-class="mt-2 h-5 w-36" />
|
<BlockSkeleton custom-class="mt-3 h-4 w-32" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<p class="text-center text-xl font-semibold uppercase">{{ hostName }}</p>
|
<p class="font-mono text-[11px] font-medium uppercase tracking-[0.2em] text-white/60">
|
||||||
<div class="relative h-[140px] w-[140px]" :class="statusColorClass">
|
{{ item.hostName }}
|
||||||
<svg class="h-full w-full -rotate-90" viewBox="0 0 120 120" aria-label="Pourcentage restant">
|
</p>
|
||||||
|
|
||||||
|
<div class="chart-wrapper" :class="item.statusColorClass">
|
||||||
|
<svg class="chart-svg" viewBox="0 0 120 120" aria-label="Pourcentage restant">
|
||||||
<circle
|
<circle
|
||||||
class="fill-none stroke-[rgba(255,255,255,0.22)] [stroke-width:10]"
|
class="track"
|
||||||
cx="60"
|
cx="60" cy="60"
|
||||||
cy="60"
|
:r="item.chartRadius"
|
||||||
:r="chartRadius"
|
|
||||||
/>
|
/>
|
||||||
<circle
|
<circle
|
||||||
class="fill-none stroke-[currentColor] [stroke-linecap:round] [stroke-width:10] transition-[stroke-dashoffset] duration-300"
|
class="progress"
|
||||||
cx="60"
|
cx="60" cy="60"
|
||||||
cy="60"
|
:r="item.chartRadius"
|
||||||
:r="chartRadius"
|
:style="{
|
||||||
:style="{ strokeDasharray: `${chartCircumference}`, strokeDashoffset: `${chartOffset}` }"
|
strokeDasharray: `${item.chartCircumference}`,
|
||||||
|
strokeDashoffset: `${item.chartOffset}`
|
||||||
|
}"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
<div class="absolute inset-0 flex flex-col items-center justify-center">
|
<div class="chart-label">
|
||||||
<strong class="text-2xl leading-none">{{ remainingPercentText }}</strong>
|
<strong class="font-mono text-2xl font-bold leading-none">
|
||||||
|
{{ item.remainingPercentText }}
|
||||||
|
</strong>
|
||||||
|
<span class="mt-1 font-mono text-[9px] uppercase tracking-widest text-m-muted">
|
||||||
|
libre
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="mt-1 text-center text-sm font-semibold">{{ usedText }} / {{ totalText }}</p>
|
<p class="font-mono text-xs font-medium text-m-muted/80">
|
||||||
|
{{ item.usedText }}
|
||||||
|
<span class="mx-0.5 text-m-muted/40">/</span>
|
||||||
|
{{ item.totalText }}
|
||||||
|
</p>
|
||||||
</template>
|
</template>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
@@ -40,24 +53,69 @@ import BlockSkeleton from "~/components/skeleton/BlockSkeleton.vue"
|
|||||||
import TextSkeleton from "~/components/skeleton/TextSkeleton.vue"
|
import TextSkeleton from "~/components/skeleton/TextSkeleton.vue"
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
loading: boolean
|
item: {
|
||||||
hostName: string
|
loading: boolean
|
||||||
statusColorClass: string
|
hostName: string
|
||||||
chartRadius: number
|
statusColorClass: string
|
||||||
chartCircumference: number
|
chartRadius: number
|
||||||
chartOffset: number
|
chartCircumference: number
|
||||||
remainingPercentText: string
|
chartOffset: number
|
||||||
usedText: string
|
remainingPercentText: string
|
||||||
totalText: string
|
usedText: string
|
||||||
|
totalText: string
|
||||||
|
}
|
||||||
}>()
|
}>()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.m-success {
|
.storage-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 1.25rem 1rem;
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-wrapper {
|
||||||
|
position: relative;
|
||||||
|
width: 120px;
|
||||||
|
height: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-svg {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.track {
|
||||||
|
fill: none;
|
||||||
|
stroke: rgba(255, 255, 255, 0.06);
|
||||||
|
stroke-width: 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress {
|
||||||
|
fill: none;
|
||||||
|
stroke: currentColor;
|
||||||
|
stroke-width: 8;
|
||||||
|
stroke-linecap: round;
|
||||||
|
transition: stroke-dashoffset 0.8s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-label {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-success {
|
||||||
color: rgb(var(--m-success));
|
color: rgb(var(--m-success));
|
||||||
}
|
}
|
||||||
|
|
||||||
.m-error {
|
.status-error {
|
||||||
color: rgb(var(--m-error));
|
color: rgb(var(--m-error));
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,19 +1,126 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
const { data: messages } = await useFetch('/api/discord/messages')
|
import {Icon as IconifyIcon} from "@iconify/vue"
|
||||||
|
import { apiFetch } from "~/composables/useApiAuth"
|
||||||
|
|
||||||
|
const { data: messages, error } = await useFetch('/api/discord/messages', {
|
||||||
|
$fetch: apiFetch,
|
||||||
|
server: false
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="bg-m-secondary w-auto h-auto mx-4 rounded-md shadow-md/50 shadow-black p-2">
|
<div class="discord-card card-glow">
|
||||||
<div class="mb-2 flex items-center justify-between">
|
<div class="card-header">
|
||||||
<p class="font-bold text-3xl text-m-tertiary">
|
<div class="flex items-center gap-2.5">
|
||||||
Speedtest
|
<IconifyIcon icon="mdi:message-text" class="text-lg text-m-accent" />
|
||||||
|
<h2 class="card-title">Discord</h2>
|
||||||
|
</div>
|
||||||
|
<span class="font-mono text-[10px] text-m-muted tracking-widest uppercase">Messages</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="error" class="empty-state error-state">
|
||||||
|
<IconifyIcon icon="mdi:alert-circle-outline" class="text-3xl text-m-error/70" />
|
||||||
|
<p class="mt-2 font-mono text-xs text-m-error/80">
|
||||||
|
Erreur lors de l'opération
|
||||||
</p>
|
</p>
|
||||||
<div v-if="messages">
|
</div>
|
||||||
<div v-for="m in messages" :key="m.id">
|
|
||||||
<strong>{{ m.author.username }}</strong>
|
<div v-else-if="!messages || messages.length === 0" class="empty-state">
|
||||||
<p>{{ m.content }}</p>
|
<IconifyIcon icon="mdi:chat-outline" class="text-3xl text-m-muted/40" />
|
||||||
|
<p class="mt-2 font-mono text-xs text-m-muted/50">
|
||||||
|
Aucun message
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="message-list">
|
||||||
|
<div
|
||||||
|
v-for="m in messages"
|
||||||
|
:key="m.id"
|
||||||
|
class="message-row"
|
||||||
|
>
|
||||||
|
<div class="message-avatar">
|
||||||
|
{{ m.author.username.charAt(0).toUpperCase() }}
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<span class="font-display text-xs font-semibold text-m-accent">
|
||||||
|
{{ m.author.username }}
|
||||||
|
</span>
|
||||||
|
<p class="mt-0.5 break-words font-display text-sm leading-relaxed text-m-text/80">
|
||||||
|
{{ m.content }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
</div>
|
|
||||||
</template>
|
<style scoped>
|
||||||
|
.discord-card {
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
max-height: calc(100vh - 7rem);
|
||||||
|
overflow: hidden;
|
||||||
|
transition: background-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 2rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-state {
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgb(var(--m-error) / 0.12);
|
||||||
|
background: rgb(var(--m-error) / 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
max-height: calc(100vh - 12rem);
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.75rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-avatar {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: linear-gradient(135deg, rgb(var(--m-accent) / 0.2), rgb(var(--m-success) / 0.15));
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-accent));
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
222
components/Speed-test.vue
Normal file
222
components/Speed-test.vue
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
<template>
|
||||||
|
<div class="speedtest-card card-glow">
|
||||||
|
<div class="card-header">
|
||||||
|
<h2 class="card-title">Speedtest</h2>
|
||||||
|
<button
|
||||||
|
class="reload-btn"
|
||||||
|
:disabled="isTesting"
|
||||||
|
@click="runTests"
|
||||||
|
>
|
||||||
|
<IconifyIcon
|
||||||
|
icon="mdi:reload"
|
||||||
|
class="text-lg"
|
||||||
|
:class="{ 'animate-spin': isTesting }"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="metrics-grid">
|
||||||
|
<div v-for="metric in metrics" :key="metric.label" class="metric-card">
|
||||||
|
<div class="metric-header">
|
||||||
|
<IconifyIcon :icon="metric.icon" class="text-lg text-m-accent" />
|
||||||
|
<span class="font-mono text-[10px] font-medium uppercase tracking-[0.15em] text-m-muted">
|
||||||
|
{{ metric.label }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="metric-value-area">
|
||||||
|
<template v-if="isTesting">
|
||||||
|
<div class="h-10 w-16 animate-shimmer rounded" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<span class="metric-value font-mono">
|
||||||
|
{{ metric.value !== null ? metric.value : "--" }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<span class="metric-unit font-mono">{{ metric.unit }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-if="errorMessage" class="error-text" role="status" aria-live="polite">
|
||||||
|
{{ errorMessage }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {computed, ref} from "vue"
|
||||||
|
import {Icon as IconifyIcon} from "@iconify/vue"
|
||||||
|
import { apiRequest } from "~/composables/useApiAuth"
|
||||||
|
|
||||||
|
const ping = ref<number | null>(null)
|
||||||
|
const download = ref<number | null>(null)
|
||||||
|
const upload = ref<number | null>(null)
|
||||||
|
const isTesting = ref(false)
|
||||||
|
const errorMessage = ref("")
|
||||||
|
|
||||||
|
const metrics = computed(() => [
|
||||||
|
{ label: "Download", icon: "mdi:arrow-down-bold", value: download.value, unit: "Mbps" },
|
||||||
|
{ label: "Upload", icon: "mdi:arrow-up-bold", value: upload.value, unit: "Mbps" },
|
||||||
|
{ label: "Ping", icon: "mdi:signal", value: ping.value, unit: "ms" },
|
||||||
|
])
|
||||||
|
|
||||||
|
async function testDownload() {
|
||||||
|
const start = performance.now()
|
||||||
|
const res = await apiRequest('/api/speedtest')
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`HTTP ${res.status}`)
|
||||||
|
}
|
||||||
|
const blob = await res.blob()
|
||||||
|
const end = performance.now()
|
||||||
|
const size = blob.size
|
||||||
|
const seconds = (end - start) / 1000
|
||||||
|
download.value = Math.round((size * 8) / seconds / 1000000)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testUpload() {
|
||||||
|
const size = 5 * 1024 * 1024
|
||||||
|
const data = new Uint8Array(size)
|
||||||
|
const start = performance.now()
|
||||||
|
const response = await apiRequest('/api/upload', { method: 'POST', body: data })
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP ${response.status}`)
|
||||||
|
}
|
||||||
|
const end = performance.now()
|
||||||
|
const seconds = (end - start) / 1000
|
||||||
|
upload.value = Math.round((size * 8) / seconds / 1000000)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testPing() {
|
||||||
|
const start = performance.now()
|
||||||
|
const response = await fetch('/api/ping')
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP ${response.status}`)
|
||||||
|
}
|
||||||
|
const end = performance.now()
|
||||||
|
ping.value = Math.round(end - start)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runTests() {
|
||||||
|
isTesting.value = true
|
||||||
|
download.value = null
|
||||||
|
upload.value = null
|
||||||
|
ping.value = null
|
||||||
|
errorMessage.value = ""
|
||||||
|
|
||||||
|
try {
|
||||||
|
await testDownload()
|
||||||
|
await testUpload()
|
||||||
|
await testPing()
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur speedtest:", error)
|
||||||
|
errorMessage.value = "Erreur lors de l'opération"
|
||||||
|
} finally {
|
||||||
|
isTesting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.speedtest-card {
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
transition: background-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.reload-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
color: rgb(var(--m-accent));
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.12);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reload-btn:hover:not(:disabled) {
|
||||||
|
background: rgb(var(--m-accent) / 0.12);
|
||||||
|
border-color: rgb(var(--m-accent) / 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.reload-btn:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metrics-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-card {
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 1rem;
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.06);
|
||||||
|
transition: border-color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-card:hover {
|
||||||
|
border-color: rgb(var(--m-accent) / 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-value-area {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.125rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-value {
|
||||||
|
font-size: 2rem;
|
||||||
|
font-weight: 700;
|
||||||
|
line-height: 1;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-unit {
|
||||||
|
font-size: 0.65rem;
|
||||||
|
font-weight: 500;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-text {
|
||||||
|
margin-top: 0.75rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgb(var(--m-error) / 0.12);
|
||||||
|
background: rgb(var(--m-error) / 0.06);
|
||||||
|
padding: 0.75rem 0.875rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: rgb(var(--m-error));
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="bg-m-secondary w-[507px] h-[184px] mx-4 rounded-md shadow-md/50 shadow-black p-2">
|
|
||||||
<div class="mb-2 flex items-center justify-between">
|
|
||||||
<p class="font-bold text-3xl text-m-tertiary">
|
|
||||||
Speedtest
|
|
||||||
</p>
|
|
||||||
<IconifyIcon
|
|
||||||
icon="mdi:reload"
|
|
||||||
class="bg-m-tertiary text-2xl text-black rounded-md shadow-md/50 mr-1 cursor-pointer"
|
|
||||||
@click="runTests"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="grid grid-cols-3 gap-3">
|
|
||||||
<div class="bg-m-tertiary w-[153px] h-[120px] rounded-md shadow-md/50 shadow-m-black">
|
|
||||||
<div class="flex items-center justify-center">
|
|
||||||
<IconifyIcon
|
|
||||||
icon="mdi:download"
|
|
||||||
class="text-m-primary text-2xl mt-2 ml-1"
|
|
||||||
/>
|
|
||||||
<p class="font-bold uppercase text-xl text-m-text mt-2 mr-1">
|
|
||||||
download
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="mx-2 flex flex-col items-center justify-center">
|
|
||||||
<template v-if="isTesting">
|
|
||||||
<TextSkeleton custom-class="h-10 w-16 mb-1" />
|
|
||||||
</template>
|
|
||||||
<span v-else class="text-4xl">
|
|
||||||
{{ download !== null ? `${download}` : "--" }}
|
|
||||||
</span>
|
|
||||||
<p class="font-bold text-xl leading-tight">
|
|
||||||
Mbps
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="bg-m-tertiary w-[153px] h-[120px] rounded-md shadow-md/50 shadow-m-black">
|
|
||||||
<div class="flex items-center justify-center">
|
|
||||||
<IconifyIcon
|
|
||||||
icon="mdi:upload"
|
|
||||||
class="text-m-primary text-2xl mt-2 ml-1"
|
|
||||||
/>
|
|
||||||
<p class="font-bold uppercase text-xl text-m-text mt-2 mr-1">
|
|
||||||
upload
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="mx-2 flex flex-col items-center justify-center">
|
|
||||||
<template v-if="isTesting">
|
|
||||||
<TextSkeleton custom-class="h-10 w-16 mb-1" />
|
|
||||||
</template>
|
|
||||||
<span v-else class="text-4xl">
|
|
||||||
{{ upload !== null ? `${upload}` : "--" }}
|
|
||||||
</span>
|
|
||||||
<p class="font-bold text-xl leading-tight">
|
|
||||||
Mbps
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="bg-m-tertiary w-[153px] h-[120px] rounded-md shadow-md/50 shadow-m-black">
|
|
||||||
<div class="flex items-center justify-center">
|
|
||||||
<IconifyIcon
|
|
||||||
icon="mdi:wifi"
|
|
||||||
class="text-m-primary text-2xl mt-2 ml-1"
|
|
||||||
/>
|
|
||||||
<p class="font-bold uppercase text-xl text-m-text mt-2 mr-1">
|
|
||||||
ping
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="mx-2 flex flex-col items-center justify-center">
|
|
||||||
<template v-if="isTesting">
|
|
||||||
<TextSkeleton custom-class="h-10 w-16 mb-1" />
|
|
||||||
</template>
|
|
||||||
<span v-else class="text-4xl">
|
|
||||||
{{ ping !== null ? `${ping}` : "--" }}
|
|
||||||
</span>
|
|
||||||
<p class="font-bold text-xl leading-tight">
|
|
||||||
Ms
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<script setup lang="ts">
|
|
||||||
import {ref} from "vue";
|
|
||||||
import {Icon as IconifyIcon} from "@iconify/vue"
|
|
||||||
import TextSkeleton from "~/components/skeleton/TextSkeleton.vue"
|
|
||||||
|
|
||||||
const ping = ref<number | null>(null)
|
|
||||||
const download = ref<number | null>(null)
|
|
||||||
const upload = ref<number | null>(null)
|
|
||||||
const isTesting = ref(false)
|
|
||||||
|
|
||||||
async function testDownload() {
|
|
||||||
const start = performance.now()
|
|
||||||
|
|
||||||
const res = await fetch('/api/download')
|
|
||||||
const blob = await res.blob()
|
|
||||||
|
|
||||||
const end = performance.now()
|
|
||||||
|
|
||||||
const size = blob.size
|
|
||||||
const seconds = (end - start) / 1000
|
|
||||||
download.value = Math.round((size * 8) / seconds / 1000000)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function testUpload() {
|
|
||||||
const size = 5 * 1024 * 1024
|
|
||||||
const data = new Uint8Array(size)
|
|
||||||
|
|
||||||
const start = performance.now()
|
|
||||||
|
|
||||||
await fetch('/api/upload', {
|
|
||||||
method: 'POST',
|
|
||||||
body: data
|
|
||||||
})
|
|
||||||
|
|
||||||
const end = performance.now()
|
|
||||||
|
|
||||||
const seconds = (end - start) / 1000
|
|
||||||
upload.value = Math.round((size * 8) / seconds / 1000000)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async function testPing() {
|
|
||||||
const start = performance.now()
|
|
||||||
|
|
||||||
await fetch('/api/ping')
|
|
||||||
|
|
||||||
const end = performance.now()
|
|
||||||
|
|
||||||
ping.value = Math.round(end - start)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runTests() {
|
|
||||||
isTesting.value = true
|
|
||||||
download.value = null
|
|
||||||
upload.value = null
|
|
||||||
ping.value = null
|
|
||||||
|
|
||||||
try {
|
|
||||||
await testDownload()
|
|
||||||
await testUpload()
|
|
||||||
await testPing()
|
|
||||||
} finally {
|
|
||||||
isTesting.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,52 +1,49 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="bg-m-secondary w-[250px] h-[292px] rounded-md mx-4 shadow-md/50 shadow-black">
|
<div class="status-card card-glow">
|
||||||
<p class="font-bold text-3xl text-m-tertiary my-1 mx-3">
|
<div class="card-header">
|
||||||
Status
|
<h2 class="card-title">Status</h2>
|
||||||
</p>
|
<span class="font-mono text-[10px] text-m-muted tracking-widest uppercase">Services</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<template v-if="loading">
|
<template v-if="loading">
|
||||||
<div
|
<div
|
||||||
v-for="n in 3"
|
v-for="n in 3"
|
||||||
:key="`skeleton-${n}`"
|
:key="`skeleton-${n}`"
|
||||||
class="relative w-[200px] h-[68px] rounded-md mx-[25px] mb-3"
|
class="status-row animate-shimmer"
|
||||||
>
|
>
|
||||||
<ButtonSkeleton custom-class="h-full w-full" />
|
<div class="flex items-center gap-3">
|
||||||
<div class="absolute inset-0 p-2">
|
<CircleSkeleton custom-class="h-3 w-3" />
|
||||||
<TextSkeleton custom-class="h-5 w-24 mb-2" />
|
<TextSkeleton custom-class="h-4 w-20" />
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<CircleSkeleton custom-class="h-6 w-6" />
|
|
||||||
<TextSkeleton custom-class="h-5 w-20" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<TextSkeleton custom-class="h-4 w-16" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-else
|
|
||||||
class="bg-m-tertiary w-[200px] h-[68px] rounded-md shadow-md/50 shadow-m-black mx-[25px] mb-3"
|
|
||||||
v-for="row in rows"
|
v-for="row in rows"
|
||||||
|
v-else
|
||||||
:key="`${row.label}-${row.url}`"
|
:key="`${row.label}-${row.url}`"
|
||||||
|
class="status-row"
|
||||||
|
:class="row.status === 200 ? 'row-ok' : 'row-error'"
|
||||||
>
|
>
|
||||||
<p class="font-bold text-xl text-m-text mt-2 mx-2 mb-1">
|
<div class="flex items-center gap-3">
|
||||||
{{ row.label }}
|
<span class="status-dot" :class="row.status === 200 ? 'dot-ok' : 'dot-error'" />
|
||||||
</p>
|
<span class="font-display text-sm font-semibold text-m-text">
|
||||||
<div class="mx-2 flex items-center">
|
{{ row.label }}
|
||||||
<span
|
|
||||||
class="inline-block h-[24px] w-[24px] rounded-full mr-2"
|
|
||||||
:class="statusClass(row.status)"
|
|
||||||
/>
|
|
||||||
<span class="font-semibold text-lg">
|
|
||||||
{{ statusLabel(row.status) }}
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<span class="font-mono text-xs" :class="row.status === 200 ? 'text-m-success' : 'text-m-error'">
|
||||||
|
{{ statusLabel(row.status) }}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import ButtonSkeleton from "~/components/skeleton/ButtonSkeleton.vue"
|
|
||||||
import CircleSkeleton from "~/components/skeleton/CircleSkeleton.vue"
|
import CircleSkeleton from "~/components/skeleton/CircleSkeleton.vue"
|
||||||
import TextSkeleton from "~/components/skeleton/TextSkeleton.vue"
|
import TextSkeleton from "~/components/skeleton/TextSkeleton.vue"
|
||||||
import {onBeforeUnmount, onMounted, ref} from "vue"
|
import {onBeforeUnmount, onMounted, ref} from "vue"
|
||||||
|
import { apiFetch } from "~/composables/useApiAuth"
|
||||||
|
|
||||||
interface StatusRow {
|
interface StatusRow {
|
||||||
label: string
|
label: string
|
||||||
@@ -77,16 +74,10 @@ const loading = ref(true)
|
|||||||
const initialized = ref(false)
|
const initialized = ref(false)
|
||||||
let timer: ReturnType<typeof setInterval> | null = null
|
let timer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
const statusClass = (status: number) => {
|
|
||||||
if (status === 200) return "bg-m-success"
|
|
||||||
if (status === 0) return "bg-m-error"
|
|
||||||
return "bg-m-error"
|
|
||||||
}
|
|
||||||
|
|
||||||
const statusLabel = (status: number) => {
|
const statusLabel = (status: number) => {
|
||||||
if (status === 200) return "HTTP 200"
|
if (status === 200) return "HTTP 200"
|
||||||
if (status === 0) return "Injoignable"
|
if (status === 0) return "Injoignable"
|
||||||
return `KO (HTTP ${status})`
|
return `KO (${status})`
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkStatus = async () => {
|
const checkStatus = async () => {
|
||||||
@@ -94,7 +85,7 @@ const checkStatus = async () => {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await $fetch<StatusResponse>(props.endpoint)
|
const data = await apiFetch<StatusResponse>(props.endpoint)
|
||||||
rows.value = data.results
|
rows.value = data.results
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
rows.value = [
|
rows.value = [
|
||||||
@@ -125,3 +116,67 @@ onBeforeUnmount(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.status-card {
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.625rem;
|
||||||
|
transition: background-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
border: 1px solid transparent;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-ok {
|
||||||
|
border-color: rgb(var(--m-success) / 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-error {
|
||||||
|
border-color: rgb(var(--m-error) / 0.1);
|
||||||
|
background: rgb(var(--m-error) / 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 50%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot-ok {
|
||||||
|
background: rgb(var(--m-success));
|
||||||
|
box-shadow: 0 0 6px rgb(var(--m-success) / 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot-error {
|
||||||
|
background: rgb(var(--m-error));
|
||||||
|
box-shadow: 0 0 6px rgb(var(--m-error) / 0.5);
|
||||||
|
animation: pulse-glow 2s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
652
components/SystemMetricsChart.vue
Normal file
652
components/SystemMetricsChart.vue
Normal file
@@ -0,0 +1,652 @@
|
|||||||
|
<template>
|
||||||
|
<section class="chart-card card-glow">
|
||||||
|
<div class="card-header">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title">Historique systeme</h2>
|
||||||
|
<p class="card-copy">CPU et RAM avec cache journalier local</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="controls">
|
||||||
|
<div class="toggle-group" role="group" aria-label="Metriques affichees">
|
||||||
|
<button
|
||||||
|
v-for="option in options"
|
||||||
|
:key="option.value"
|
||||||
|
type="button"
|
||||||
|
class="toggle-pill"
|
||||||
|
:class="{ 'toggle-pill-active': isMetricActive(option.value) }"
|
||||||
|
@click="toggleMetric(option.value)"
|
||||||
|
>
|
||||||
|
<span class="toggle-dot" :style="{ backgroundColor: option.color }" />
|
||||||
|
<span>{{ option.label }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="history-toolbar">
|
||||||
|
<label class="window-select">
|
||||||
|
<span>Fenetre</span>
|
||||||
|
<select v-model="selectedWindow">
|
||||||
|
<option
|
||||||
|
v-for="windowOption in windowOptions"
|
||||||
|
:key="windowOption.value"
|
||||||
|
:value="windowOption.value"
|
||||||
|
>
|
||||||
|
{{ windowOption.label }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button type="button" class="clear-btn" @click="clearHistory">
|
||||||
|
Vider le cache
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chart-shell">
|
||||||
|
<template v-if="loading && visibleHistory.length === 0">
|
||||||
|
<div class="chart-skeleton animate-shimmer" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="chart-meta">
|
||||||
|
<div>
|
||||||
|
<span class="meta-label">Echelle</span>
|
||||||
|
<strong class="meta-value">{{ scaleLabel }}</strong>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="meta-label">Periode</span>
|
||||||
|
<strong class="meta-value">{{ activeWindowLabel }}</strong>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-for="option in displayedOptions"
|
||||||
|
:key="option.value"
|
||||||
|
class="meta-metric"
|
||||||
|
>
|
||||||
|
<span class="meta-label">{{ option.label }}</span>
|
||||||
|
<strong class="meta-value" :style="{ color: option.color }">
|
||||||
|
{{ formatValue(currentMetricValue(option.value)) }}
|
||||||
|
</strong>
|
||||||
|
<span class="meta-subvalue">Pic {{ formatValue(peakMetricValue(option.value)) }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<svg
|
||||||
|
class="chart-svg"
|
||||||
|
viewBox="0 0 960 320"
|
||||||
|
preserveAspectRatio="none"
|
||||||
|
aria-label="Graphique des ressources"
|
||||||
|
>
|
||||||
|
<line
|
||||||
|
:x1="chartLeft"
|
||||||
|
:y1="chartBottom"
|
||||||
|
:x2="chartRight"
|
||||||
|
:y2="chartBottom"
|
||||||
|
class="axis-line"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
:x1="chartLeft"
|
||||||
|
:y1="chartTop"
|
||||||
|
:x2="chartLeft"
|
||||||
|
:y2="chartBottom"
|
||||||
|
class="axis-line"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
v-for="line in yAxisTicks"
|
||||||
|
:key="`grid-${line.y}`"
|
||||||
|
:x1="chartLeft"
|
||||||
|
:y1="line.y"
|
||||||
|
:x2="chartRight"
|
||||||
|
:y2="line.y"
|
||||||
|
class="grid-line"
|
||||||
|
/>
|
||||||
|
<text
|
||||||
|
v-for="line in yAxisTicks"
|
||||||
|
:key="`y-label-${line.y}`"
|
||||||
|
:x="chartLeft - 12"
|
||||||
|
:y="line.y + 4"
|
||||||
|
class="axis-label axis-label-y"
|
||||||
|
>
|
||||||
|
{{ line.label }}
|
||||||
|
</text>
|
||||||
|
<line
|
||||||
|
v-for="tick in xAxisTicks"
|
||||||
|
:key="`x-grid-${tick.x}`"
|
||||||
|
:x1="tick.x"
|
||||||
|
:y1="chartTop"
|
||||||
|
:x2="tick.x"
|
||||||
|
:y2="chartBottom"
|
||||||
|
class="grid-line grid-line-vertical"
|
||||||
|
/>
|
||||||
|
<text
|
||||||
|
v-for="tick in xAxisTicks"
|
||||||
|
:key="`x-label-${tick.x}`"
|
||||||
|
:x="tick.x"
|
||||||
|
:y="304"
|
||||||
|
class="axis-label axis-label-x"
|
||||||
|
>
|
||||||
|
{{ tick.label }}
|
||||||
|
</text>
|
||||||
|
<polyline
|
||||||
|
v-for="option in displayedOptions"
|
||||||
|
:key="option.value"
|
||||||
|
:points="polylinePoints(option.value)"
|
||||||
|
class="chart-line"
|
||||||
|
:style="{ stroke: option.color }"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted, ref, watch } from "vue"
|
||||||
|
import type { SystemMetrics } from "~/types/system"
|
||||||
|
|
||||||
|
type MetricKey = "cpu" | "ram"
|
||||||
|
type WindowKey = "day" | "hour" | "5m" | "1m" | "30s"
|
||||||
|
|
||||||
|
type HistoryPoint = {
|
||||||
|
sampledAt: number
|
||||||
|
cpu: number
|
||||||
|
ram: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const HISTORY_STORAGE_KEY = "supervisor-system-history"
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
metrics: SystemMetrics | null
|
||||||
|
loading: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const activeMetrics = ref<MetricKey[]>(["cpu", "ram"])
|
||||||
|
const selectedWindow = ref<WindowKey>("hour")
|
||||||
|
const history = ref<HistoryPoint[]>([])
|
||||||
|
|
||||||
|
const options: Array<{ value: MetricKey; label: string; color: string }> = [
|
||||||
|
{ value: "cpu", label: "CPU", color: "#5aa9ff" },
|
||||||
|
{ value: "ram", label: "RAM", color: "#31c48d" }
|
||||||
|
]
|
||||||
|
|
||||||
|
const windowOptions: Array<{ value: WindowKey; label: string; durationMs: number | null }> = [
|
||||||
|
{ value: "day", label: "Journee", durationMs: null },
|
||||||
|
{ value: "hour", label: "1 h", durationMs: 60 * 60 * 1000 },
|
||||||
|
{ value: "5m", label: "5 min", durationMs: 5 * 60 * 1000 },
|
||||||
|
{ value: "1m", label: "1 min", durationMs: 60 * 1000 },
|
||||||
|
{ value: "30s", label: "30 s", durationMs: 30 * 1000 }
|
||||||
|
]
|
||||||
|
|
||||||
|
const getStartOfToday = (timestamp: number) => {
|
||||||
|
const date = new Date(timestamp)
|
||||||
|
date.setHours(0, 0, 0, 0)
|
||||||
|
return date.getTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizeHistory = (points: HistoryPoint[]) => {
|
||||||
|
if (points.length === 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const startOfToday = getStartOfToday(Date.now())
|
||||||
|
|
||||||
|
return points
|
||||||
|
.filter((point) => point.sampledAt >= startOfToday)
|
||||||
|
.sort((left, right) => left.sampledAt - right.sampledAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
const persistHistory = () => {
|
||||||
|
if (!import.meta.client) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem(HISTORY_STORAGE_KEY, JSON.stringify(history.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
const appendHistoryPoint = (metrics: SystemMetrics) => {
|
||||||
|
const sampledAt = new Date(metrics.sampledAt).getTime()
|
||||||
|
|
||||||
|
if (!Number.isFinite(sampledAt)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextPoint: HistoryPoint = {
|
||||||
|
sampledAt,
|
||||||
|
cpu: metrics.cpuPercent,
|
||||||
|
ram: metrics.memoryPercent
|
||||||
|
}
|
||||||
|
|
||||||
|
const previousPoint = history.value.at(-1)
|
||||||
|
const nextHistory = normalizeHistory(
|
||||||
|
previousPoint?.sampledAt === nextPoint.sampledAt
|
||||||
|
? [...history.value.slice(0, -1), nextPoint]
|
||||||
|
: [...history.value, nextPoint]
|
||||||
|
)
|
||||||
|
|
||||||
|
history.value = nextHistory
|
||||||
|
persistHistory()
|
||||||
|
}
|
||||||
|
|
||||||
|
const clearHistory = () => {
|
||||||
|
history.value = []
|
||||||
|
|
||||||
|
if (!import.meta.client) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.removeItem(HISTORY_STORAGE_KEY)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (!import.meta.client) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const rawHistory = localStorage.getItem(HISTORY_STORAGE_KEY)
|
||||||
|
|
||||||
|
if (!rawHistory) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedHistory = JSON.parse(rawHistory) as HistoryPoint[]
|
||||||
|
history.value = normalizeHistory(
|
||||||
|
parsedHistory.filter((point) => {
|
||||||
|
return (
|
||||||
|
point &&
|
||||||
|
Number.isFinite(point.sampledAt) &&
|
||||||
|
Number.isFinite(point.cpu) &&
|
||||||
|
Number.isFinite(point.ram)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
persistHistory()
|
||||||
|
} catch {
|
||||||
|
localStorage.removeItem(HISTORY_STORAGE_KEY)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.metrics?.sampledAt,
|
||||||
|
() => {
|
||||||
|
if (!props.metrics) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
appendHistoryPoint(props.metrics)
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
const activeWindow = computed(() => {
|
||||||
|
return windowOptions.find((option) => option.value === selectedWindow.value) || windowOptions[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
const displayedOptions = computed(() => {
|
||||||
|
return options.filter((option) => activeMetrics.value.includes(option.value))
|
||||||
|
})
|
||||||
|
|
||||||
|
const visibleHistory = computed(() => {
|
||||||
|
if (activeWindow.value.durationMs === null) {
|
||||||
|
return history.value
|
||||||
|
}
|
||||||
|
|
||||||
|
const minTimestamp = Date.now() - activeWindow.value.durationMs
|
||||||
|
return history.value.filter((point) => point.sampledAt >= minTimestamp)
|
||||||
|
})
|
||||||
|
|
||||||
|
const scaleMax = computed(() => 100)
|
||||||
|
|
||||||
|
const formatValue = (value: number) => `${Math.round(value)}%`
|
||||||
|
|
||||||
|
const scaleLabel = computed(() => {
|
||||||
|
return formatValue(scaleMax.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const activeWindowLabel = computed(() => activeWindow.value.label)
|
||||||
|
|
||||||
|
const isMetricActive = (metric: MetricKey) => activeMetrics.value.includes(metric)
|
||||||
|
|
||||||
|
const toggleMetric = (metric: MetricKey) => {
|
||||||
|
if (isMetricActive(metric)) {
|
||||||
|
activeMetrics.value = activeMetrics.value.filter((value) => value !== metric)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
activeMetrics.value = [...activeMetrics.value, metric]
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentMetricValue = (metric: MetricKey) => {
|
||||||
|
return visibleHistory.value.at(-1)?.[metric] ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const peakMetricValue = (metric: MetricKey) => {
|
||||||
|
return visibleHistory.value.reduce((max, point) => Math.max(max, point[metric]), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
const chartLeft = 72
|
||||||
|
const chartRight = 936
|
||||||
|
const chartTop = 24
|
||||||
|
const chartBottom = 280
|
||||||
|
const chartWidth = chartRight - chartLeft
|
||||||
|
const chartHeight = chartBottom - chartTop
|
||||||
|
|
||||||
|
const yAxisTicks = computed(() => {
|
||||||
|
const steps = 4
|
||||||
|
|
||||||
|
return Array.from({ length: steps + 1 }, (_, index) => {
|
||||||
|
const ratio = index / steps
|
||||||
|
const value = scaleMax.value * (1 - ratio)
|
||||||
|
const y = chartTop + chartHeight * ratio
|
||||||
|
|
||||||
|
return {
|
||||||
|
y,
|
||||||
|
label: formatValue(value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const formatTimeLabel = (timestamp: number) => {
|
||||||
|
return new Intl.DateTimeFormat("fr-FR", {
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
second: activeWindow.value.durationMs !== null && activeWindow.value.durationMs <= 5 * 60 * 1000
|
||||||
|
? "2-digit"
|
||||||
|
: undefined
|
||||||
|
}).format(timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
const xAxisTicks = computed(() => {
|
||||||
|
if (visibleHistory.value.length === 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visibleHistory.value.length === 1) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
x: chartLeft,
|
||||||
|
label: formatTimeLabel(visibleHistory.value[0].sampledAt)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const steps = 3
|
||||||
|
const firstTimestamp = visibleHistory.value[0].sampledAt
|
||||||
|
const lastTimestamp = visibleHistory.value.at(-1)?.sampledAt || firstTimestamp
|
||||||
|
const span = Math.max(1, lastTimestamp - firstTimestamp)
|
||||||
|
|
||||||
|
return Array.from({ length: steps + 1 }, (_, index) => {
|
||||||
|
const ratio = index / steps
|
||||||
|
const targetTimestamp = firstTimestamp + span * ratio
|
||||||
|
const closestPoint = visibleHistory.value.reduce((closest, point) => {
|
||||||
|
const currentDistance = Math.abs(point.sampledAt - targetTimestamp)
|
||||||
|
const closestDistance = Math.abs(closest.sampledAt - targetTimestamp)
|
||||||
|
return currentDistance < closestDistance ? point : closest
|
||||||
|
}, visibleHistory.value[0])
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: chartLeft + chartWidth * ratio,
|
||||||
|
label: formatTimeLabel(closestPoint.sampledAt)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const polylinePoints = (metric: MetricKey) => {
|
||||||
|
const points = visibleHistory.value.map((point) => point[metric])
|
||||||
|
|
||||||
|
if (points.length === 0) {
|
||||||
|
return `${chartLeft},${chartBottom}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (points.length === 1) {
|
||||||
|
const normalizedValue = points[0] / scaleMax.value
|
||||||
|
const y = chartBottom - normalizedValue * chartHeight
|
||||||
|
return `${chartLeft},${y} ${chartRight},${y}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return points
|
||||||
|
.map((value, index) => {
|
||||||
|
const x = chartLeft + (index / (points.length - 1)) * chartWidth
|
||||||
|
const normalizedValue = scaleMax.value > 0 ? value / scaleMax.value : 0
|
||||||
|
const y = chartBottom - normalizedValue * chartHeight
|
||||||
|
|
||||||
|
return `${x},${Math.max(chartTop, Math.min(chartBottom, y))}`
|
||||||
|
})
|
||||||
|
.join(" ")
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.chart-card {
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 1rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-copy {
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.12em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.625rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-pill {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.1);
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
padding: 0.55rem 0.8rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.72rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.12em;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
cursor: pointer;
|
||||||
|
appearance: none;
|
||||||
|
transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-pill-active {
|
||||||
|
border-color: rgb(var(--m-accent) / 0.28);
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-dot {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.history-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.window-select {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.7rem;
|
||||||
|
letter-spacing: 0.12em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
}
|
||||||
|
|
||||||
|
.window-select select {
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.14);
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
padding: 0.55rem 0.8rem;
|
||||||
|
font: inherit;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.clear-btn {
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid rgb(var(--m-error) / 0.18);
|
||||||
|
background: rgb(var(--m-error) / 0.08);
|
||||||
|
padding: 0.55rem 0.85rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.72rem;
|
||||||
|
letter-spacing: 0.12em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgb(var(--m-error));
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.clear-btn:hover {
|
||||||
|
border-color: rgb(var(--m-error) / 0.32);
|
||||||
|
background: rgb(var(--m-error) / 0.14);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-shell {
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1rem;
|
||||||
|
background:
|
||||||
|
linear-gradient(180deg, rgb(var(--m-tertiary)) 0%, rgb(var(--m-secondary)) 100%);
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-meta {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-metric {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.68rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.14em;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-value {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.35rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-subvalue {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.7rem;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-svg {
|
||||||
|
width: 100%;
|
||||||
|
height: 320px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.axis-line {
|
||||||
|
stroke: rgb(var(--m-border) / 0.55);
|
||||||
|
stroke-width: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-line {
|
||||||
|
stroke: rgb(var(--m-border) / 0.35);
|
||||||
|
stroke-width: 1;
|
||||||
|
stroke-dasharray: 6 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-line-vertical {
|
||||||
|
stroke-dasharray: 4 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
.axis-label {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 11px;
|
||||||
|
fill: rgb(var(--m-muted));
|
||||||
|
}
|
||||||
|
|
||||||
|
.axis-label-y {
|
||||||
|
text-anchor: end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.axis-label-x {
|
||||||
|
text-anchor: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-line {
|
||||||
|
fill: none;
|
||||||
|
stroke-width: 4;
|
||||||
|
stroke-linecap: round;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-skeleton {
|
||||||
|
width: 100%;
|
||||||
|
height: 320px;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 820px) {
|
||||||
|
.controls {
|
||||||
|
width: 100%;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.history-toolbar {
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-meta {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
190
components/SystemResources.vue
Normal file
190
components/SystemResources.vue
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
<template>
|
||||||
|
<div class="resources-card card-glow">
|
||||||
|
<div class="card-header">
|
||||||
|
<h2 class="card-title">Ressources</h2>
|
||||||
|
<span class="font-mono text-[10px] uppercase tracking-widest text-m-muted">CPU / RAM</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="metrics-list">
|
||||||
|
<div
|
||||||
|
v-for="metric in metrics"
|
||||||
|
:key="metric.label"
|
||||||
|
class="metric-row"
|
||||||
|
>
|
||||||
|
<div class="metric-copy">
|
||||||
|
<div class="metric-head">
|
||||||
|
<span class="font-display text-sm font-semibold text-m-text">{{ metric.label }}</span>
|
||||||
|
<span class="font-mono text-xs text-m-muted">{{ metric.detail }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-if="isLoading">
|
||||||
|
<div class="metric-skeleton animate-shimmer" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="metric-bar">
|
||||||
|
<div
|
||||||
|
class="metric-bar-fill"
|
||||||
|
:class="metric.toneClass"
|
||||||
|
:style="{ width: `${metric.percent}%` }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="metric-value-area">
|
||||||
|
<template v-if="isLoading">
|
||||||
|
<div class="value-skeleton animate-shimmer" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<span class="metric-value font-mono">{{ metric.percent }}%</span>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {computed} from "vue"
|
||||||
|
import type { SystemMetrics } from "~/types/system";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
metrics: SystemMetrics | null
|
||||||
|
loading: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const formatMemory = (value: number) => {
|
||||||
|
if (!Number.isFinite(value) || value <= 0) {
|
||||||
|
return "0 GB"
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${(value / 1024 / 1024 / 1024).toFixed(1)} GB`
|
||||||
|
}
|
||||||
|
|
||||||
|
const toneClass = (percent: number) => {
|
||||||
|
if (percent >= 85) return "tone-error"
|
||||||
|
if (percent >= 65) return "tone-warning"
|
||||||
|
return "tone-success"
|
||||||
|
}
|
||||||
|
|
||||||
|
const isLoading = computed(() => props.loading || !props.metrics)
|
||||||
|
|
||||||
|
const metrics = computed(() => [
|
||||||
|
{
|
||||||
|
label: "CPU",
|
||||||
|
percent: props.metrics?.cpuPercent ?? 0,
|
||||||
|
detail: "Charge instantanee",
|
||||||
|
toneClass: toneClass(props.metrics?.cpuPercent ?? 0)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "RAM",
|
||||||
|
percent: props.metrics?.memoryPercent ?? 0,
|
||||||
|
detail: `${formatMemory(props.metrics?.usedMemory ?? 0)} / ${formatMemory(props.metrics?.totalMemory ?? 0)}`,
|
||||||
|
toneClass: toneClass(props.metrics?.memoryPercent ?? 0)
|
||||||
|
}
|
||||||
|
])
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.resources-card {
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
transition: background-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.metrics-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) auto;
|
||||||
|
gap: 0.75rem;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.875rem 1rem;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-copy {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-bottom: 0.625rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-bar {
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgb(var(--m-bg) / 0.45);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-bar-fill {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
transition: width 0.35s ease, background-color 0.35s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-value-area {
|
||||||
|
min-width: 54px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-value {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-skeleton {
|
||||||
|
height: 10px;
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value-skeleton {
|
||||||
|
width: 48px;
|
||||||
|
height: 28px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tone-success {
|
||||||
|
background: rgb(var(--m-success));
|
||||||
|
}
|
||||||
|
|
||||||
|
.tone-warning {
|
||||||
|
background: rgb(var(--m-warning));
|
||||||
|
}
|
||||||
|
|
||||||
|
.tone-error {
|
||||||
|
background: rgb(var(--m-error));
|
||||||
|
}
|
||||||
|
</style>
|
||||||
90
composables/useApiAuth.ts
Normal file
90
composables/useApiAuth.ts
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
function toHeadersObject(headers?: HeadersInit): Record<string, string> {
|
||||||
|
if (!headers) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headers instanceof Headers) {
|
||||||
|
return Object.fromEntries(headers.entries())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(headers)) {
|
||||||
|
return Object.fromEntries(headers)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...headers }
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDownloadFileName(contentDisposition: string | null, fallback: string) {
|
||||||
|
if (!contentDisposition) {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
const utf8Match = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i)
|
||||||
|
if (utf8Match?.[1]) {
|
||||||
|
return decodeURIComponent(utf8Match[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
const asciiMatch = contentDisposition.match(/filename="([^"]+)"/i)
|
||||||
|
if (asciiMatch?.[1]) {
|
||||||
|
return asciiMatch[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useApiAuthHeader() {
|
||||||
|
const runtimeConfig = useRuntimeConfig()
|
||||||
|
const token = runtimeConfig.public.apiSecretKey
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tous les appels frontend vers /api/* reutilisent ce header commun.
|
||||||
|
return {
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const apiFetch = $fetch.create({})
|
||||||
|
|
||||||
|
export function apiRequest(input: RequestInfo | URL, init: RequestInit = {}) {
|
||||||
|
return fetch(input, withApiAuth(init))
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function downloadApiFile(url: string, fileNameFallback: string) {
|
||||||
|
// Les telechargements passent aussi par fetch pour pouvoir recuperer
|
||||||
|
// le contenu et le nom de fichier renvoye par l'API.
|
||||||
|
const response = await apiRequest(url)
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP ${response.status}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const blob = await response.blob()
|
||||||
|
const objectUrl = URL.createObjectURL(blob)
|
||||||
|
const fileName = getDownloadFileName(
|
||||||
|
response.headers.get("content-disposition"),
|
||||||
|
fileNameFallback
|
||||||
|
)
|
||||||
|
const link = document.createElement("a")
|
||||||
|
|
||||||
|
link.href = objectUrl
|
||||||
|
link.download = fileName
|
||||||
|
link.style.display = "none"
|
||||||
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
link.remove()
|
||||||
|
URL.revokeObjectURL(objectUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function withApiAuth(init: RequestInit = {}) {
|
||||||
|
// Fusionne le header d'auth avec d'eventuels headers deja fournis.
|
||||||
|
return {
|
||||||
|
...init,
|
||||||
|
headers: {
|
||||||
|
...useApiAuthHeader(),
|
||||||
|
...toHeadersObject(init.headers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
eslint.config.mjs
Normal file
3
eslint.config.mjs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import createConfigForNuxt from "@nuxt/eslint-config"
|
||||||
|
|
||||||
|
export default createConfigForNuxt()
|
||||||
@@ -1,41 +1,484 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-layout">
|
<div class="page-layout">
|
||||||
<aside class="sidebar">
|
<aside class="sidebar" aria-label="Navigation principale">
|
||||||
<div class="flex items-center gap-3 px-14 py-4">
|
<div class="sidebar-header">
|
||||||
<div class="avatar">
|
<div class="logo-container">
|
||||||
<div class="h-[155px] w-[155px]">
|
<img
|
||||||
<img
|
:src="logoSrc"
|
||||||
:src="logoSrc"
|
alt="Logo Malio"
|
||||||
alt="Logo Malio"
|
class="logo"
|
||||||
class="h-full w-full object-contain"
|
>
|
||||||
/>
|
</div>
|
||||||
|
<div class="brand-copy">
|
||||||
|
<p class="brand-title">Supervisor</p>
|
||||||
|
</div>
|
||||||
|
<div class="sidebar-divider"/>
|
||||||
|
</div>
|
||||||
|
<div class="sidebar-content">
|
||||||
|
<slot name="sidebar"/>
|
||||||
|
<nav class="sidebar-nav" aria-label="Sections">
|
||||||
|
<p class="nav-label">Navigation</p>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<div class="bg-m-tertiary rounded-lg border border-m-accent/6">
|
||||||
|
<NuxtLink
|
||||||
|
to="/"
|
||||||
|
class="flex items-center gap-3 px-4 py-2 rounded-lg text-white hover:bg-m-tertiary/80 transition-colors"
|
||||||
|
>
|
||||||
|
<IconifyIcon
|
||||||
|
icon="mdi:home"
|
||||||
|
class="text-lg"/>
|
||||||
|
<p>Home</p>
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
|
<div class="bg-m-tertiary rounded-lg border border-m-accent/6">
|
||||||
|
<NuxtLink
|
||||||
|
to="/backup"
|
||||||
|
class="flex items-center gap-3 px-4 py-2 rounded-lg text-white hover:bg-m-tertiary/80 transition-colors"
|
||||||
|
>
|
||||||
|
<IconifyIcon
|
||||||
|
icon="mdi:data"
|
||||||
|
class="text-lg"/>
|
||||||
|
<p>Backup</p>
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<div class="sidebar-footer">
|
||||||
|
<div class="sidebar-divider"/>
|
||||||
|
<div class="footer-row">
|
||||||
|
<p class="font-mono text-[10px] tracking-widest uppercase text-white/40">
|
||||||
|
Supervisor {{ appVersion }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<slot name="sidebar" />
|
|
||||||
</aside>
|
</aside>
|
||||||
<main class="content">
|
|
||||||
<slot />
|
<button class="mobile-menu-button" type="button" @click="isMenuOpen = true">
|
||||||
|
<IconifyIcon icon="mdi:menu" class="text-2xl"/>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div v-if="isMenuOpen" class="mobile-menu-backdrop" @click="isMenuOpen = false"/>
|
||||||
|
|
||||||
|
<aside v-if="isMenuOpen" class="mobile-sidebar" aria-label="Navigation mobile">
|
||||||
|
<div class="sidebar-header">
|
||||||
|
<div class="logo-container">
|
||||||
|
<img
|
||||||
|
:src="logoSrc"
|
||||||
|
alt="Logo Malio"
|
||||||
|
class="logo"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div class="brand-copy">
|
||||||
|
<p class="brand-kicker">Control Center</p>
|
||||||
|
<p class="brand-title">Supervisor</p>
|
||||||
|
<p class="brand-description">
|
||||||
|
Tableau de bord interne pour le monitoring et les sauvegardes.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="sidebar-divider"/>
|
||||||
|
</div>
|
||||||
|
<div class="sidebar-content">
|
||||||
|
<slot name="sidebar"/>
|
||||||
|
<nav class="sidebar-nav" aria-label="Sections mobiles">
|
||||||
|
<p class="nav-label">Navigation</p>
|
||||||
|
<NuxtLink
|
||||||
|
v-for="item in navItems"
|
||||||
|
:key="`mobile-${item.to}`"
|
||||||
|
v-slot="{ href, navigate, isExactActive }"
|
||||||
|
:to="item.to"
|
||||||
|
custom
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
:href="href"
|
||||||
|
class="nav-link"
|
||||||
|
:class="{ 'nav-link-active': isExactActive }"
|
||||||
|
:aria-current="isExactActive ? 'page' : undefined"
|
||||||
|
@click="navigate(); isMenuOpen = false"
|
||||||
|
>
|
||||||
|
<span class="nav-link-main">
|
||||||
|
<span class="nav-icon">
|
||||||
|
<IconifyIcon :icon="item.icon" class="text-lg"/>
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<span class="nav-title">{{ item.label }}</span>
|
||||||
|
<span class="nav-caption">{{ item.caption }}</span>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<span class="nav-pill">{{ item.short }}</span>
|
||||||
|
</a>
|
||||||
|
</NuxtLink>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<div class="sidebar-footer">
|
||||||
|
<div class="sidebar-divider"/>
|
||||||
|
<div class="status-card">
|
||||||
|
<p class="status-label">Environnement</p>
|
||||||
|
<p class="status-value">Production</p>
|
||||||
|
<p class="status-description">
|
||||||
|
Navigation rapide vers les vues principales de supervision.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="footer-row">
|
||||||
|
<p class="font-mono text-[10px] tracking-widest uppercase text-white/40">
|
||||||
|
Supervisor {{ appVersion }}
|
||||||
|
</p>
|
||||||
|
<button class="close-button" type="button" @click="isMenuOpen = false">
|
||||||
|
<IconifyIcon icon="mdi:close" class="text-xl"/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<main class="content bg-noise">
|
||||||
|
<slot/>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import {ref} from "vue"
|
||||||
|
import {Icon as IconifyIcon} from "@iconify/vue"
|
||||||
import logoSrc from '~/assets/LOGO_CARRE_BLANC.png'
|
import logoSrc from '~/assets/LOGO_CARRE_BLANC.png'
|
||||||
|
|
||||||
|
const {
|
||||||
|
public: {appVersion}
|
||||||
|
} = useRuntimeConfig()
|
||||||
|
const isMenuOpen = ref(false)
|
||||||
|
const navItems = [
|
||||||
|
{
|
||||||
|
to: "/",
|
||||||
|
label: "Monitoring",
|
||||||
|
caption: "Etat global et disponibilite",
|
||||||
|
short: "MON",
|
||||||
|
icon: "mdi:chart-box-outline"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
to: "/backup",
|
||||||
|
label: "Backup",
|
||||||
|
caption: "Scripts et fichiers archives",
|
||||||
|
short: "BKP",
|
||||||
|
icon: "mdi:database-arrow-up-outline"
|
||||||
|
}
|
||||||
|
]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.page-layout {
|
.page-layout {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 280px 1fr;
|
grid-template-columns: 260px 1fr;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar,
|
||||||
|
.mobile-sidebar {
|
||||||
|
background: linear-gradient(
|
||||||
|
180deg,
|
||||||
|
rgb(var(--m-sidebar-from)) 0%,
|
||||||
|
rgb(var(--m-sidebar-to)) 100%
|
||||||
|
);
|
||||||
|
color: white;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
border-right: 1px solid var(--m-sidebar-border);
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar {
|
.sidebar {
|
||||||
background-color: rgb(var(--m-primary));
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
height: 100vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
transition: background 0.4s ease, border-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-header {
|
||||||
|
padding: 1.5rem 2rem 0;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-copy {
|
||||||
|
padding: 0.5rem 0 0.75rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-kicker {
|
||||||
|
margin: 0;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.68rem;
|
||||||
|
letter-spacing: 0.18em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgb(var(--m-accent));
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-title {
|
||||||
|
margin: 0.45rem 0 0;
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.45rem;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-description {
|
||||||
|
margin: 0.55rem 0 0;
|
||||||
|
color: rgb(255 255 255 / 0.58);
|
||||||
|
line-height: 1.6;
|
||||||
|
font-size: 0.92rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
height: 100px;
|
||||||
|
width: 100px;
|
||||||
|
object-fit: contain;
|
||||||
|
filter: drop-shadow(0 0 20px rgba(80, 140, 255, 0.15));
|
||||||
|
transition: filter 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo:hover {
|
||||||
|
filter: drop-shadow(0 0 28px rgba(80, 140, 255, 0.3));
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-content {
|
||||||
|
flex: 1;
|
||||||
|
padding: 0.5rem 1rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-footer {
|
||||||
|
flex-shrink: 0;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-divider {
|
||||||
|
height: 1px;
|
||||||
|
margin: 0.75rem 1.5rem;
|
||||||
|
background: linear-gradient(
|
||||||
|
90deg,
|
||||||
|
transparent,
|
||||||
|
var(--m-sidebar-divider),
|
||||||
|
transparent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.5rem 1.5rem 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-nav {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-label {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 0.75rem 0.25rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.68rem;
|
||||||
|
letter-spacing: 0.18em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgb(255 255 255 / 0.38);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.85rem 0.9rem;
|
||||||
|
border-radius: 14px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: background-color 0.2s ease,
|
||||||
|
border-color 0.2s ease,
|
||||||
|
transform 0.2s ease,
|
||||||
|
box-shadow 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link:hover {
|
||||||
|
background: rgb(255 255 255 / 0.06);
|
||||||
|
border-color: rgb(var(--m-accent) / 0.14);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link:focus-visible {
|
||||||
|
outline: 2px solid rgb(var(--m-accent));
|
||||||
|
outline-offset: 2px;
|
||||||
|
background: rgb(255 255 255 / 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link-active {
|
||||||
|
background: linear-gradient(135deg, rgb(var(--m-accent) / 0.16), rgb(255 255 255 / 0.04));
|
||||||
|
border-color: rgb(var(--m-accent) / 0.24);
|
||||||
|
box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link-main {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.8rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-icon {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 2.5rem;
|
||||||
|
height: 2.5rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: rgb(255 255 255 / 0.06);
|
||||||
|
color: rgb(var(--m-accent));
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-title,
|
||||||
|
.nav-caption {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-title {
|
||||||
|
font-size: 0.96rem;
|
||||||
|
font-weight: 600;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav-caption {
|
||||||
|
margin-top: 0.2rem;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
line-height: 1.45;
|
||||||
|
color: rgb(255 255 255 / 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-pill {
|
||||||
|
flex-shrink: 0;
|
||||||
|
padding: 0.28rem 0.45rem;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.68rem;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
color: rgb(255 255 255 / 0.62);
|
||||||
|
background: rgb(255 255 255 / 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-card {
|
||||||
|
margin: 0 1rem;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 16px;
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.14);
|
||||||
|
background: radial-gradient(circle at top right, rgb(var(--m-accent) / 0.14), transparent 30%),
|
||||||
|
rgb(255 255 255 / 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-label {
|
||||||
|
margin: 0;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.68rem;
|
||||||
|
letter-spacing: 0.16em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgb(255 255 255 / 0.42);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-value {
|
||||||
|
margin: 0.5rem 0 0;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-description {
|
||||||
|
margin: 0.45rem 0 0;
|
||||||
|
font-size: 0.82rem;
|
||||||
|
line-height: 1.55;
|
||||||
|
color: rgb(255 255 255 / 0.54);
|
||||||
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
background-color: rgb(var(--m-tertiary));
|
background: rgb(var(--m-bg));
|
||||||
|
overflow-y: auto;
|
||||||
|
min-height: 100vh;
|
||||||
|
transition: background-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-menu-button,
|
||||||
|
.mobile-menu-backdrop,
|
||||||
|
.mobile-sidebar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 820px) {
|
||||||
|
.page-layout {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-menu-button {
|
||||||
|
position: fixed;
|
||||||
|
top: 1rem;
|
||||||
|
left: 1rem;
|
||||||
|
z-index: 40;
|
||||||
|
display: flex;
|
||||||
|
height: 44px;
|
||||||
|
width: 44px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.18);
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-menu-backdrop {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 45;
|
||||||
|
display: block;
|
||||||
|
background: rgba(3, 8, 20, 0.55);
|
||||||
|
backdrop-filter: blur(3px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-sidebar {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 50;
|
||||||
|
display: flex;
|
||||||
|
height: 100vh;
|
||||||
|
width: min(84vw, 320px);
|
||||||
|
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-content {
|
||||||
|
padding-right: 0.9rem;
|
||||||
|
padding-left: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-button {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 32px;
|
||||||
|
width: 32px;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
background: rgba(255, 255, 255, 0.06);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link {
|
||||||
|
padding: 0.8rem 0.85rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,10 +1,45 @@
|
|||||||
|
import { execSync } from "node:child_process"
|
||||||
import tailwindcss from "@tailwindcss/vite"
|
import tailwindcss from "@tailwindcss/vite"
|
||||||
|
|
||||||
|
const getRepoVersion = () => {
|
||||||
|
try {
|
||||||
|
const tags = execSync(
|
||||||
|
"git for-each-ref --sort=-version:refname --format='%(refname:short)' refs/tags",
|
||||||
|
{ encoding: "utf8" }
|
||||||
|
)
|
||||||
|
.split("\n")
|
||||||
|
.map((tag) => tag.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
|
||||||
|
return tags[0] || "dev"
|
||||||
|
} catch {
|
||||||
|
return "dev"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// https://nuxt.com/docs/api/configuration/nuxt-config
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
compatibilityDate: '2025-07-15',
|
compatibilityDate: "2025-07-15",
|
||||||
devtools: { enabled: true },
|
devtools: { enabled: true },
|
||||||
css: ["~/assets/css/main.css"],
|
css: ["~/assets/css/main.css"],
|
||||||
|
app: {
|
||||||
|
head: {
|
||||||
|
link: [
|
||||||
|
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
|
||||||
|
{ rel: "preconnect", href: "https://fonts.gstatic.com ", crossorigin: "" },
|
||||||
|
{
|
||||||
|
rel: "stylesheet",
|
||||||
|
href: "https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Outfit:wght@300;400;500;600;700;800;900&display=swap"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
runtimeConfig: {
|
||||||
|
apiSecretKey: process.env.API_SECRET_KEY,
|
||||||
|
public: {
|
||||||
|
appVersion: getRepoVersion()
|
||||||
|
}
|
||||||
|
},
|
||||||
vite: {
|
vite: {
|
||||||
plugins: [tailwindcss()]
|
plugins: [tailwindcss()]
|
||||||
}
|
}
|
||||||
|
|||||||
8060
package-lock.json
generated
8060
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@@ -7,16 +7,23 @@
|
|||||||
"dev": "nuxt dev",
|
"dev": "nuxt dev",
|
||||||
"generate": "nuxt generate",
|
"generate": "nuxt generate",
|
||||||
"preview": "nuxt preview",
|
"preview": "nuxt preview",
|
||||||
"postinstall": "nuxt prepare"
|
"postinstall": "nuxt prepare",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"lint:fix": "eslint . --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iconify/vue": "^5.0.0",
|
"@iconify/vue": "^5.0.0",
|
||||||
"nuxt": "^4.3.1",
|
"@nuxt/eslint": "^1.15.2",
|
||||||
"vue": "^3.5.29",
|
"nuxt": "^4.3.1"
|
||||||
"vue-router": "^4.6.4"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@semantic-release/changelog": "^6.0.3",
|
||||||
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
||||||
|
"@semantic-release/git": "^10.0.1",
|
||||||
|
"@semantic-release/github": "^12.0.6",
|
||||||
|
"@semantic-release/release-notes-generator": "^14.1.0",
|
||||||
"@tailwindcss/vite": "^4.2.1",
|
"@tailwindcss/vite": "^4.2.1",
|
||||||
|
"semantic-release": "^25.0.3",
|
||||||
"tailwindcss": "^4.2.1"
|
"tailwindcss": "^4.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
354
pages/backup.vue
Normal file
354
pages/backup.vue
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
<template>
|
||||||
|
<NuxtLayout name="default">
|
||||||
|
<div class="dashboard-container">
|
||||||
|
<header class="dashboard-header">
|
||||||
|
<div class="header-copy">
|
||||||
|
<p class="section-kicker">Operations</p>
|
||||||
|
<h1 class="font-display text-3xl font-bold tracking-tight text-m-text">
|
||||||
|
Backup
|
||||||
|
</h1>
|
||||||
|
<p class="header-description">
|
||||||
|
Centralisez la selection des dossiers, l'execution des scripts et le telechargement
|
||||||
|
des fichiers depuis une seule vue.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<div class="dashboard-grid">
|
||||||
|
<section class="grid-left" aria-label="Commandes de sauvegarde">
|
||||||
|
<BackupButtonSee
|
||||||
|
class="animate-fade-in-up backup-selector"
|
||||||
|
style="animation-delay: 120ms"
|
||||||
|
@select="selectedBackup = $event"
|
||||||
|
/>
|
||||||
|
<BackupRun
|
||||||
|
class="animate-fade-in-up"
|
||||||
|
style="animation-delay: 180ms"
|
||||||
|
@result="handleScriptResult"
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="grid-middle" aria-labelledby="backup-files-title">
|
||||||
|
<div class="files-panel animate-fade-in-up" style="animation-delay: 240ms">
|
||||||
|
<div class="files-panel-header">
|
||||||
|
<div>
|
||||||
|
<p class="section-kicker">Fichiers</p>
|
||||||
|
<h2 id="backup-files-title" class="files-panel-title">
|
||||||
|
Historique des sauvegardes
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<p class="files-panel-meta">
|
||||||
|
{{ selectedBackup ? `Source ${selectedBackup}` : "En attente de selection" }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<BackupList
|
||||||
|
class="backup-list-mobile"
|
||||||
|
:folder="selectedBackup"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section
|
||||||
|
class="files-panel output-panel animate-fade-in-up"
|
||||||
|
style="animation-delay: 300ms"
|
||||||
|
aria-labelledby="backup-output-title"
|
||||||
|
>
|
||||||
|
<div class="files-panel-header">
|
||||||
|
<div>
|
||||||
|
<p class="section-kicker">Execution</p>
|
||||||
|
<h2 id="backup-output-title" class="files-panel-title">Resultat du script</h2>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
class="panel-badge"
|
||||||
|
:class="{
|
||||||
|
'panel-badge-idle': !scriptResult.label,
|
||||||
|
'panel-badge-success': scriptResult.label && !scriptResult.isError,
|
||||||
|
'panel-badge-error': scriptResult.isError
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ scriptResult.label || "Pret" }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="!scriptResult.output"
|
||||||
|
class="output-empty"
|
||||||
|
role="status"
|
||||||
|
aria-live="polite"
|
||||||
|
>
|
||||||
|
<p class="output-empty-title">Aucune sortie disponible</p>
|
||||||
|
<p class="output-empty-text">
|
||||||
|
Lancez un script depuis le panneau de gauche pour afficher son retour ici.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<pre
|
||||||
|
v-else
|
||||||
|
class="output-console"
|
||||||
|
:class="{ 'output-console-error': scriptResult.isError }"
|
||||||
|
>{{ scriptResult.output }}</pre>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</NuxtLayout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from "vue"
|
||||||
|
import BackupRun from "~/components/BackupRun.vue"
|
||||||
|
import { apiFetch, downloadApiFile } from "~/composables/useApiAuth"
|
||||||
|
|
||||||
|
definePageMeta({ layout: false })
|
||||||
|
|
||||||
|
type ScriptResult = {
|
||||||
|
key: string | null
|
||||||
|
label: string
|
||||||
|
output: string
|
||||||
|
isError: boolean
|
||||||
|
downloadFolders: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const emptyScriptResult = (): ScriptResult => ({
|
||||||
|
key: null,
|
||||||
|
label: "",
|
||||||
|
output: "",
|
||||||
|
isError: false,
|
||||||
|
downloadFolders: []
|
||||||
|
})
|
||||||
|
|
||||||
|
const selectedBackup = ref<string | null>(null)
|
||||||
|
const scriptResult = ref<ScriptResult>(emptyScriptResult())
|
||||||
|
|
||||||
|
const fetchLatestBackup = async (folder: string) => {
|
||||||
|
const files = await apiFetch<string[]>(`/api/backups?folder=${encodeURIComponent(folder)}`)
|
||||||
|
return files[0] || null
|
||||||
|
}
|
||||||
|
|
||||||
|
const triggerDownload = async (folder: string, file: string) => {
|
||||||
|
const url = `/api/download?folder=${encodeURIComponent(folder)}&file=${encodeURIComponent(file)}`
|
||||||
|
await downloadApiFile(url, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
const triggerBatchDownload = async (folders: string[]) => {
|
||||||
|
const url = `/api/download-latest?folders=${encodeURIComponent(folders.join(","))}`
|
||||||
|
await downloadApiFile(url, "backup-latest.tar.gz")
|
||||||
|
}
|
||||||
|
|
||||||
|
const downloadLatestBackup = async (folder: string) => {
|
||||||
|
const latestFile = await fetchLatestBackup(folder)
|
||||||
|
|
||||||
|
if (latestFile) {
|
||||||
|
await triggerDownload(folder, latestFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleScriptResult = async (payload: ScriptResult) => {
|
||||||
|
scriptResult.value = { ...emptyScriptResult(), ...payload }
|
||||||
|
|
||||||
|
if (payload.isError || payload.downloadFolders.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.downloadFolders.length > 1) {
|
||||||
|
await triggerBatchDownload(payload.downloadFolders)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const folder of payload.downloadFolders) {
|
||||||
|
try {
|
||||||
|
await downloadLatestBackup(folder)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Erreur telechargement automatique pour ${folder}:`, error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.dashboard-container {
|
||||||
|
padding: 2rem 2.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dashboard-header {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
|
||||||
|
gap: 1.5rem;
|
||||||
|
align-items: end;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-copy {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-kicker {
|
||||||
|
margin: 0 0 0.5rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.7rem;
|
||||||
|
letter-spacing: 0.18em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgb(var(--m-accent));
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-description {
|
||||||
|
max-width: 62ch;
|
||||||
|
margin-top: 0.9rem;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
line-height: 1.65;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dashboard-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 300px minmax(0, 1fr);
|
||||||
|
gap: 1.5rem;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-left,
|
||||||
|
.grid-middle {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1.5rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files-panel {
|
||||||
|
padding: 1.25rem;
|
||||||
|
border-radius: 20px;
|
||||||
|
background: rgb(var(--m-secondary) / 0.4);
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-panel {
|
||||||
|
min-height: 220px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files-panel-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: end;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files-panel-title {
|
||||||
|
margin: 0;
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.4rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.files-panel-meta {
|
||||||
|
margin: 0;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-badge {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 999px;
|
||||||
|
padding: 0.35rem 0.7rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.68rem;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-badge-idle {
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
background: rgb(var(--m-tertiary) / 0.45);
|
||||||
|
border-color: rgb(var(--m-border) / 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-badge-success {
|
||||||
|
color: rgb(var(--m-success));
|
||||||
|
background: rgb(var(--m-success) / 0.08);
|
||||||
|
border-color: rgb(var(--m-success) / 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-badge-error {
|
||||||
|
color: rgb(var(--m-error));
|
||||||
|
background: rgb(var(--m-error) / 0.08);
|
||||||
|
border-color: rgb(var(--m-error) / 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-empty {
|
||||||
|
display: flex;
|
||||||
|
min-height: 132px;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
border-radius: 14px;
|
||||||
|
border: 1px dashed rgb(var(--m-border) / 0.55);
|
||||||
|
background: rgb(var(--m-tertiary) / 0.38);
|
||||||
|
padding: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-empty-title {
|
||||||
|
margin: 0;
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-empty-text {
|
||||||
|
margin: 0.5rem 0 0;
|
||||||
|
max-width: 52ch;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
line-height: 1.65;
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-console {
|
||||||
|
margin: 0;
|
||||||
|
min-height: 132px;
|
||||||
|
overflow-x: auto;
|
||||||
|
border-radius: 14px;
|
||||||
|
border: 1px solid rgb(var(--m-border) / 0.3);
|
||||||
|
background:
|
||||||
|
linear-gradient(180deg, rgb(var(--m-bg) / 0.96), rgb(var(--m-secondary) / 0.92));
|
||||||
|
padding: 1rem 1.1rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.78rem;
|
||||||
|
line-height: 1.7;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
color: rgb(var(--m-success));
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-console-error {
|
||||||
|
color: rgb(var(--m-error));
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1180px) {
|
||||||
|
.dashboard-header,
|
||||||
|
.dashboard-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files-panel-header {
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files-panel-meta {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 820px) {
|
||||||
|
.dashboard-container {
|
||||||
|
padding: 4.5rem 1.25rem 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files-panel {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
329
pages/index.vue
329
pages/index.vue
@@ -1,59 +1,104 @@
|
|||||||
<template>
|
<template>
|
||||||
<NuxtLayout name="default">
|
<NuxtLayout name="default">
|
||||||
<template #sidebar>
|
<div class="dashboard-container">
|
||||||
<div class="flex flex-col">
|
<header class="dashboard-header">
|
||||||
<DiagramStorage
|
<div>
|
||||||
v-for="item in diagramItems"
|
<h1 class="font-display text-3xl font-bold tracking-tight text-m-text">
|
||||||
:key="item.key"
|
Monitoring
|
||||||
:loading="loading"
|
</h1>
|
||||||
:host-name="item.hostName"
|
</div>
|
||||||
:status-color-class="item.statusColorClass"
|
</header>
|
||||||
:chart-radius="chartRadius"
|
|
||||||
:chart-circumference="chartCircumference"
|
|
||||||
:chart-offset="item.chartOffset"
|
|
||||||
:remaining-percent-text="item.remainingPercentText"
|
|
||||||
:used-text="item.usedText"
|
|
||||||
:total-text="item.totalText"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<p class="font-bold text-4xl my-6 mx-4">Écran de monitoring</p>
|
<div class="content-grid">
|
||||||
|
<div class="content-main">
|
||||||
|
<section class="storage-section">
|
||||||
|
<div class="storage-section-header">
|
||||||
|
<h2 class="font-display text-xl font-semibold text-m-text">Stockage</h2>
|
||||||
|
<span class="font-mono text-[10px] uppercase tracking-widest text-m-muted">Volumes</span>
|
||||||
|
</div>
|
||||||
|
<div class="storage-grid">
|
||||||
|
<DiagramStorage
|
||||||
|
v-for="(item, idx) in diagramItems"
|
||||||
|
:key="item.key"
|
||||||
|
:item="item"
|
||||||
|
:style="{ animationDelay: `${idx * 150}ms` }"
|
||||||
|
class="animate-fade-in-up"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<div class="flex">
|
<div class="dashboard-grid">
|
||||||
<div class="flex flex-col gap-4">
|
<div class="grid-left">
|
||||||
<StatusSite />
|
<StatusSite class="animate-fade-in-up" style="animation-delay: 100ms" />
|
||||||
<BackupButtonSee @select="selectedBackup = $event" />
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex flex-col gap-4">
|
<div class="grid-middle">
|
||||||
<Speedtest />
|
<SpeedTest class="animate-fade-in-up speedtest-card-mobile" style="animation-delay: 150ms" />
|
||||||
<BackupList :folder="selectedBackup" />
|
</div>
|
||||||
<MessageDiscord/>
|
</div>
|
||||||
|
|
||||||
|
<div class="metrics-row">
|
||||||
|
<SystemMetricsChart
|
||||||
|
:metrics="systemMetrics"
|
||||||
|
:loading="systemLoading"
|
||||||
|
class="animate-fade-in-up"
|
||||||
|
style="animation-delay: 200ms"
|
||||||
|
/>
|
||||||
|
<SystemResources
|
||||||
|
:metrics="systemMetrics"
|
||||||
|
:loading="systemLoading"
|
||||||
|
class="animate-fade-in-up"
|
||||||
|
style="animation-delay: 225ms"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content-aside">
|
||||||
|
<MessageDiscord class="animate-fade-in-up" style="animation-delay: 300ms" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</NuxtLayout>
|
</NuxtLayout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
definePageMeta({layout: false})
|
|
||||||
import {computed, onMounted, ref} from "vue"
|
import {computed, onMounted, ref} from "vue"
|
||||||
|
import { apiFetch } from "~/composables/useApiAuth"
|
||||||
|
import type { SystemMetrics } from "~/types/system";
|
||||||
|
|
||||||
type SourceKey = "remote" | "local"
|
definePageMeta({layout: false})
|
||||||
type DiskCommandResult = { ok: boolean; output: string }
|
|
||||||
type DiskApiResponse = {
|
type DiskSourceResult = {
|
||||||
remote?: string | DiskCommandResult
|
key: string
|
||||||
local?: string | DiskCommandResult
|
label: string
|
||||||
|
ok: boolean
|
||||||
|
output: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedBackup = ref<string | null>(null)
|
type DiskApiResponse = {
|
||||||
const rawResults = ref<Record<SourceKey, string>>({
|
results: DiskSourceResult[]
|
||||||
remote: "",
|
}
|
||||||
local: ""
|
|
||||||
})
|
type DiagramItem = {
|
||||||
|
key: string
|
||||||
|
loading: boolean
|
||||||
|
hostName: string
|
||||||
|
statusColorClass: string
|
||||||
|
chartRadius: number
|
||||||
|
chartCircumference: number
|
||||||
|
chartOffset: number
|
||||||
|
remainingPercentText: string
|
||||||
|
usedText: string
|
||||||
|
totalText: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawResults = ref<DiskSourceResult[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const systemMetrics = ref<SystemMetrics | null>(null)
|
||||||
|
const systemLoading = ref(true)
|
||||||
const chartRadius = 52
|
const chartRadius = 52
|
||||||
const chartCircumference = 2 * Math.PI * chartRadius
|
const chartCircumference = 2 * Math.PI * chartRadius
|
||||||
|
let systemTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
const getHostName = (output: string, fallback: string) => {
|
const getHostName = (output: string, fallback: string) => {
|
||||||
const hostMatch = output.match(/Name:\s*(.+)/i)
|
const hostMatch = output.match(/Name:\s*(.+)/i)
|
||||||
@@ -93,21 +138,9 @@ const getDiskValues = (output: string) => {
|
|||||||
return {availableGb, usedGb, totalGb}
|
return {availableGb, usedGb, totalGb}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getOutputText = (entry: unknown) => {
|
const diagramItems = computed<DiagramItem[]>(() => {
|
||||||
if (typeof entry === "string") return entry
|
return rawResults.value.map((result) => {
|
||||||
if (entry && typeof entry === "object" && "output" in entry) {
|
const diskValues = getDiskValues(result.output)
|
||||||
const output = (entry as DiskCommandResult).output
|
|
||||||
return typeof output === "string" ? output : String(output)
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
const diagramItems = computed(() => {
|
|
||||||
return [
|
|
||||||
{ key: "remote" as const, fallbackHost: "Serveur distant", output: rawResults.value.remote },
|
|
||||||
{ key: "local" as const, fallbackHost: "Machine locale", output: rawResults.value.local }
|
|
||||||
].map((item) => {
|
|
||||||
const diskValues = getDiskValues(item.output)
|
|
||||||
const remainingPercent =
|
const remainingPercent =
|
||||||
diskValues === null
|
diskValues === null
|
||||||
? null
|
? null
|
||||||
@@ -116,15 +149,15 @@ const diagramItems = computed(() => {
|
|||||||
Math.min(100, Math.round((diskValues.availableGb / diskValues.totalGb) * 100))
|
Math.min(100, Math.round((diskValues.availableGb / diskValues.totalGb) * 100))
|
||||||
)
|
)
|
||||||
|
|
||||||
const chartOffset = chartCircumference - ((remainingPercent ?? 0) / 100) * chartCircumference
|
|
||||||
const statusColorClass =
|
|
||||||
remainingPercent !== null && remainingPercent <= 30 ? "m-error" : "m-success"
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: item.key,
|
key: result.key,
|
||||||
hostName: getHostName(item.output, item.fallbackHost),
|
loading: loading.value,
|
||||||
statusColorClass,
|
hostName: getHostName(result.output, result.label),
|
||||||
chartOffset,
|
statusColorClass:
|
||||||
|
remainingPercent !== null && remainingPercent <= 30 ? "status-error" : "status-success",
|
||||||
|
chartRadius,
|
||||||
|
chartCircumference,
|
||||||
|
chartOffset: chartCircumference - ((remainingPercent ?? 0) / 100) * chartCircumference,
|
||||||
remainingPercentText:
|
remainingPercentText:
|
||||||
loading.value ? "..." : remainingPercent === null ? "--%" : `${remainingPercent}%`,
|
loading.value ? "..." : remainingPercent === null ? "--%" : `${remainingPercent}%`,
|
||||||
usedText: loading.value ? "..." : diskValues ? `${diskValues.usedGb.toFixed(2)} GB` : "--",
|
usedText: loading.value ? "..." : diskValues ? `${diskValues.usedGb.toFixed(2)} GB` : "--",
|
||||||
@@ -133,40 +166,166 @@ const diagramItems = computed(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const runScript = async () => {
|
const runScript = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
rawResults.value = {
|
rawResults.value = []
|
||||||
remote: "",
|
|
||||||
local: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const output = await $fetch<DiskApiResponse | string>("/api/disk")
|
const output = await apiFetch<DiskApiResponse>("/api/disk")
|
||||||
|
rawResults.value = output.results
|
||||||
if (typeof output === "string") {
|
} catch {
|
||||||
rawResults.value = {
|
rawResults.value = [
|
||||||
remote: output,
|
{
|
||||||
local: "Erreur: sortie locale indisponible"
|
key: "error",
|
||||||
|
label: "Source indisponible",
|
||||||
|
ok: false,
|
||||||
|
output: "Erreur lors de l'opération"
|
||||||
}
|
}
|
||||||
return
|
]
|
||||||
}
|
|
||||||
|
|
||||||
rawResults.value = {
|
|
||||||
remote: getOutputText(output.remote),
|
|
||||||
local: getOutputText(output.local)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
const message = `Erreur: ${error instanceof Error ? error.message : String(error)}`
|
|
||||||
rawResults.value = {
|
|
||||||
remote: message,
|
|
||||||
local: message
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadSystemMetrics = async () => {
|
||||||
|
try {
|
||||||
|
systemMetrics.value = await $fetch<SystemMetrics>("/api/system")
|
||||||
|
} catch {
|
||||||
|
systemMetrics.value = null
|
||||||
|
} finally {
|
||||||
|
systemLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
runScript()
|
runScript()
|
||||||
|
loadSystemMetrics()
|
||||||
|
systemTimer = setInterval(loadSystemMetrics, 2000)
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (systemTimer) {
|
||||||
|
clearInterval(systemTimer)
|
||||||
|
systemTimer = null
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.dashboard-container {
|
||||||
|
padding: 2rem 2.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dashboard-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
padding-bottom: 1.5rem;
|
||||||
|
border-bottom: 1px solid rgba(80, 140, 255, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.storage-section {
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.storage-section-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.storage-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
padding: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) 320px;
|
||||||
|
gap: 1.5rem;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-main {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-aside {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dashboard-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 280px minmax(0, 1fr);
|
||||||
|
gap: 1.5rem;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metrics-row {
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) 280px;
|
||||||
|
gap: 1.5rem;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-left,
|
||||||
|
.grid-middle,
|
||||||
|
.grid-right {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1180px) {
|
||||||
|
.content-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-aside {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 820px) {
|
||||||
|
.dashboard-container {
|
||||||
|
padding: 4.5rem 1.25rem 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dashboard-header {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.storage-grid,
|
||||||
|
.content-grid,
|
||||||
|
.dashboard-grid,
|
||||||
|
.metrics-row {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-selector {
|
||||||
|
order: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.backup-list-mobile {
|
||||||
|
order: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.speedtest-card-mobile {
|
||||||
|
order: 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-aside {
|
||||||
|
grid-column: auto;
|
||||||
|
order: 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
20
server/api/backup-script.get.ts
Normal file
20
server/api/backup-script.get.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import scripts from "../config/backup-script.json"
|
||||||
|
|
||||||
|
type BackupScript = {
|
||||||
|
key: string
|
||||||
|
label: string
|
||||||
|
icon?: string
|
||||||
|
downloadFolders?: string[]
|
||||||
|
command: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineEventHandler(() => {
|
||||||
|
return {
|
||||||
|
scripts: (scripts as BackupScript[]).map(({ key, label, icon, downloadFolders }) => ({
|
||||||
|
key,
|
||||||
|
label,
|
||||||
|
icon: icon || "mdi:play-circle-outline",
|
||||||
|
downloadFolders: downloadFolders || []
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
})
|
||||||
60
server/api/backup-script.post.ts
Normal file
60
server/api/backup-script.post.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { execFile } from "node:child_process"
|
||||||
|
import scripts from "../config/backup-script.json"
|
||||||
|
|
||||||
|
type BackupScript = {
|
||||||
|
key: string
|
||||||
|
label: string
|
||||||
|
downloadFolders?: string[]
|
||||||
|
command: string
|
||||||
|
args?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
function runCommand(command: string, args: string[] = []): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
execFile(command, args, { timeout: 10 * 60 * 1000 }, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
reject(stderr || error.message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve(stdout || stderr)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const body = await readBody<{ key?: string }>(event)
|
||||||
|
const key = typeof body?.key === "string" ? body.key : null
|
||||||
|
|
||||||
|
if (!key) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 400,
|
||||||
|
statusMessage: "Clé de script manquante"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const script = (scripts as BackupScript[]).find((item) => item.key === key)
|
||||||
|
if (!script) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 404,
|
||||||
|
statusMessage: "Script introuvable"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const output = await runCommand(script.command, script.args || [])
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
key: script.key,
|
||||||
|
label: script.label,
|
||||||
|
downloadFolders: script.downloadFolders || [],
|
||||||
|
output: output.trim()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur execution script:", error)
|
||||||
|
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: "Erreur lors de l'opération"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -1,34 +1,15 @@
|
|||||||
import { execFile } from "node:child_process"
|
import {
|
||||||
|
runSsh,
|
||||||
|
shellQuote,
|
||||||
|
resolveFolderRemoteDir,
|
||||||
|
REMOTE_ROOT,
|
||||||
|
} from "../utils/ssh.ts"
|
||||||
|
|
||||||
const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST || "malio-b@192.168.0.179"
|
import {process} from "std-env";
|
||||||
const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT || "/home/malio-b/backups"
|
|
||||||
const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES || "200")
|
const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES)
|
||||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||||
const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
|
||||||
const FOLDER_MAP: Record<string, string> = {
|
|
||||||
ferme: "bdd_recette/ferme",
|
|
||||||
inventory: "bdd_recette/inventory",
|
|
||||||
sirh: "bdd_recette/sirh",
|
|
||||||
user: "bdd_recette/user",
|
|
||||||
bitwarden: "bitwarden"
|
|
||||||
}
|
|
||||||
|
|
||||||
function runSsh(command: string): Promise<string> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
execFile(
|
|
||||||
"ssh",
|
|
||||||
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", REMOTE_HOST, command],
|
|
||||||
{ maxBuffer: 10 * 1024 * 1024 },
|
|
||||||
(error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
reject(stderr || error.message)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resolve(stdout)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function isMissingPathError(error: unknown): boolean {
|
function isMissingPathError(error: unknown): boolean {
|
||||||
const message = String(error || "").toLowerCase()
|
const message = String(error || "").toLowerCase()
|
||||||
@@ -36,9 +17,11 @@ function isMissingPathError(error: unknown): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toServerError(error: unknown) {
|
function toServerError(error: unknown) {
|
||||||
|
console.error("Erreur backups:", error)
|
||||||
|
|
||||||
return createError({
|
return createError({
|
||||||
statusCode: 500,
|
statusCode: 500,
|
||||||
statusMessage: `Erreur SSH backups: ${String(error)}`
|
statusMessage: "Erreur lors de l'opération"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,30 +58,6 @@ async function getLatestRemoteFile(remoteDir: string): Promise<string | null> {
|
|||||||
return files[0] || null
|
return files[0] || null
|
||||||
}
|
}
|
||||||
|
|
||||||
async function remoteDirExists(remoteDir: string): Promise<boolean> {
|
|
||||||
const output = await runSsh(`[ -d ${quoteDir(remoteDir)} ] && echo yes || echo no`)
|
|
||||||
return output.trim() === "yes"
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveFolderRemoteDir(folderName: string): Promise<string | null> {
|
|
||||||
const mapped = FOLDER_MAP[folderName]
|
|
||||||
if (mapped) {
|
|
||||||
return `${REMOTE_ROOT}/${mapped}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const direct = `${REMOTE_ROOT}/${folderName}`
|
|
||||||
if (await remoteDirExists(direct)) {
|
|
||||||
return direct
|
|
||||||
}
|
|
||||||
|
|
||||||
const nested = `${REMOTE_ROOT}/bdd_recette/${folderName}`
|
|
||||||
if (await remoteDirExists(nested)) {
|
|
||||||
return nested
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const { folder } = getQuery(event)
|
const { folder } = getQuery(event)
|
||||||
const folderName = typeof folder === "string" ? folder : null
|
const folderName = typeof folder === "string" ? folder : null
|
||||||
@@ -123,7 +82,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sinon on récupère le dernier backup de chaque dossier distant.
|
// Sinon, on récupère le dernier backup de chaque dossier distant.
|
||||||
let dirs: string[] = []
|
let dirs: string[] = []
|
||||||
try {
|
try {
|
||||||
dirs = await listRemoteDirs(REMOTE_ROOT)
|
dirs = await listRemoteDirs(REMOTE_ROOT)
|
||||||
|
|||||||
@@ -1,15 +1,31 @@
|
|||||||
export default defineEventHandler(async () => {
|
export default defineEventHandler(async () => {
|
||||||
const token = process.env.DISCORD_BOT_TOKEN
|
const token = process.env.DISCORD_BOT_TOKEN
|
||||||
const channel = process.env.DISCORD_CHANNEL_ID
|
const channel = process.env.DISCORD_CHANNEL_ID
|
||||||
|
|
||||||
|
if (!token || !channel) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 503,
|
||||||
|
statusMessage: "Service indisponible"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const messages = await $fetch(
|
const messages = await $fetch(
|
||||||
`https://discord.com/api/v10/channels/${channel}/messages?limit=20`,
|
`https://discord.com/api/v10/channels/${channel}/messages?limit=20`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bot ${token}`
|
Authorization: `Bot ${token}`
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return messages
|
return messages
|
||||||
})
|
} catch (error) {
|
||||||
|
console.error("Erreur Discord messages:", error)
|
||||||
|
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: "Erreur lors de l'opération"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,14 +1,34 @@
|
|||||||
import { exec } from "child_process"
|
import { exec, execFile } from "child_process"
|
||||||
|
import diskSources from "../config/disk-commands.json"
|
||||||
|
|
||||||
const remoteCommand =
|
type DiskSource = {
|
||||||
process.env.DISK_REMOTE_COMMAND ||
|
key: string
|
||||||
"ssh malio-b@192.168.0.179 'cd /home/malio-b/Scripts-Serveur && bash check_storage.sh && exit'"
|
label: string
|
||||||
|
command: string
|
||||||
|
args?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
const localCommand =
|
function getEnvCommand(source: DiskSource) {
|
||||||
process.env.DISK_LOCAL_COMMAND ||
|
const envKey = `DISK_COMMAND_${source.key.toUpperCase()}`
|
||||||
"bash /home/kevin/check_storage.sh"
|
const legacyEnvKey =
|
||||||
|
source.key === "remote" ? "DISK_REMOTE_COMMAND" : source.key === "local" ? "DISK_LOCAL_COMMAND" : ""
|
||||||
|
|
||||||
function runCommand(command: string): Promise<string> {
|
return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || null
|
||||||
|
}
|
||||||
|
|
||||||
|
function runCommand(command: string, args: string[] = []): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
execFile(command, args, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
reject(stderr || error.message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve(stdout)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function runShellCommand(command: string): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(command, (error, stdout, stderr) => {
|
exec(command, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -21,25 +41,30 @@ function runCommand(command: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default defineEventHandler(async () => {
|
export default defineEventHandler(async () => {
|
||||||
const [remoteResult, localResult] = await Promise.allSettled([
|
const results = await Promise.all(
|
||||||
runCommand(remoteCommand),
|
(diskSources as DiskSource[]).map(async (source) => {
|
||||||
runCommand(localCommand)
|
try {
|
||||||
])
|
const envCommand = getEnvCommand(source)
|
||||||
|
const output = envCommand
|
||||||
|
? await runShellCommand(envCommand)
|
||||||
|
: await runCommand(source.command, source.args || [])
|
||||||
|
return {
|
||||||
|
key: source.key,
|
||||||
|
label: source.label,
|
||||||
|
ok: true,
|
||||||
|
output
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Erreur disk source ${source.key}:`, error)
|
||||||
|
return {
|
||||||
|
key: source.key,
|
||||||
|
label: source.label,
|
||||||
|
ok: false,
|
||||||
|
output: "Erreur lors de l'opération"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return { results }
|
||||||
remote: {
|
|
||||||
ok: remoteResult.status === "fulfilled",
|
|
||||||
output:
|
|
||||||
remoteResult.status === "fulfilled"
|
|
||||||
? remoteResult.value
|
|
||||||
: `Erreur: ${String(remoteResult.reason)}`
|
|
||||||
},
|
|
||||||
local: {
|
|
||||||
ok: localResult.status === "fulfilled",
|
|
||||||
output:
|
|
||||||
localResult.status === "fulfilled"
|
|
||||||
? localResult.value
|
|
||||||
: `Erreur: ${String(localResult.reason)}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|||||||
99
server/api/download-latest.get.ts
Normal file
99
server/api/download-latest.get.ts
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import {
|
||||||
|
runSsh,
|
||||||
|
shellQuote,
|
||||||
|
resolveFolderRemoteDir,
|
||||||
|
REMOTE_HOST,
|
||||||
|
} from "../utils/ssh.ts"
|
||||||
|
|
||||||
|
import {spawn} from "unenv/node/child_process";
|
||||||
|
|
||||||
|
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||||
|
|
||||||
|
async function getLatestRemoteFile(remoteDir: string): Promise<string | null> {
|
||||||
|
const output = await runSsh(`cd ${shellQuote(remoteDir)} && ls -1A | sort -r | head -n 1`)
|
||||||
|
const fileName = output.trim()
|
||||||
|
return fileName || null
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildContentDisposition(fileName: string) {
|
||||||
|
const asciiName = fileName.replace(/[^\x20-\x7E]/g, "_").replace(/["\\]/g, "_")
|
||||||
|
return `attachment; filename="${asciiName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const { folders } = getQuery(event)
|
||||||
|
const folderParam = typeof folders === "string" ? folders : ""
|
||||||
|
const folderNames = folderParam
|
||||||
|
.split(",")
|
||||||
|
.map((folder) => folder.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
|
||||||
|
if (folderNames.length === 0) {
|
||||||
|
throw createError({ statusCode: 400, statusMessage: "Paramètre folders invalide" })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (folderNames.some((folder) => !isSafeFolder(folder))) {
|
||||||
|
throw createError({ statusCode: 400, statusMessage: "Paramètre folders invalide" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const uniqueFolders = [...new Set(folderNames)]
|
||||||
|
const archiveEntries: Array<{ remoteDir: string; fileName: string; archiveName: string }> = []
|
||||||
|
|
||||||
|
for (const folderName of uniqueFolders) {
|
||||||
|
const remoteDir = await resolveFolderRemoteDir(folderName)
|
||||||
|
if (!remoteDir) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileName = await getLatestRemoteFile(remoteDir)
|
||||||
|
if (!fileName) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
archiveEntries.push({
|
||||||
|
remoteDir,
|
||||||
|
fileName,
|
||||||
|
archiveName: `${folderName}/${fileName}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (archiveEntries.length === 0) {
|
||||||
|
throw createError({ statusCode: 404, statusMessage: "Aucun fichier a telecharger" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateLabel = new Date().toISOString().slice(0, 19).replace(/[:T]/g, "-")
|
||||||
|
const archiveName = `backup-latest-${dateLabel}.tar.gz`
|
||||||
|
const tarArgs = archiveEntries.flatMap(({ remoteDir, fileName, archiveName: entryName }) => [
|
||||||
|
"--transform",
|
||||||
|
shellQuote(`s|^${fileName}$|${entryName}|`),
|
||||||
|
"-C",
|
||||||
|
shellQuote(remoteDir),
|
||||||
|
shellQuote(fileName)
|
||||||
|
])
|
||||||
|
const remoteCommand = `tar -czf - ${tarArgs.join(" ")}`
|
||||||
|
|
||||||
|
setHeader(event, "Content-Type", "application/gzip")
|
||||||
|
setHeader(event, "Content-Disposition", buildContentDisposition(archiveName))
|
||||||
|
|
||||||
|
const child = spawn("ssh", [
|
||||||
|
"-o",
|
||||||
|
"BatchMode=yes",
|
||||||
|
"-o",
|
||||||
|
"ConnectTimeout=5",
|
||||||
|
REMOTE_HOST,
|
||||||
|
remoteCommand
|
||||||
|
])
|
||||||
|
|
||||||
|
let stderr = ""
|
||||||
|
child.stderr.on("data", (chunk) => {
|
||||||
|
stderr += chunk.toString()
|
||||||
|
})
|
||||||
|
|
||||||
|
child.on("close", (code) => {
|
||||||
|
if (code !== 0) {
|
||||||
|
console.error(`Erreur archive SSH (${code}): ${stderr}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return sendStream(event, child.stdout)
|
||||||
|
})
|
||||||
@@ -1,97 +1,27 @@
|
|||||||
import { execFile, spawn } from "node:child_process"
|
import {
|
||||||
import { Readable } from "node:stream"
|
runSsh,
|
||||||
|
shellQuote,
|
||||||
const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST || "malio-b@192.168.0.179"
|
resolveFolderRemoteDir,
|
||||||
const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT || "/home/malio-b/backups"
|
REMOTE_HOST,
|
||||||
const FOLDER_MAP: Record<string, string> = {
|
} from "../utils/ssh.ts"
|
||||||
ferme: "bdd_recette/ferme",
|
import {spawn} from "unenv/node/child_process";
|
||||||
inventory: "bdd_recette/inventory",
|
|
||||||
sirh: "bdd_recette/sirh",
|
|
||||||
user: "bdd_recette/user",
|
|
||||||
bitwarden: "bitwarden"
|
|
||||||
}
|
|
||||||
|
|
||||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||||
const isSafeFile = (value: string) => /^[^/\\]+$/.test(value)
|
const isSafeFile = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||||
const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
|
||||||
|
|
||||||
function runSsh(command: string): Promise<string> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
execFile(
|
|
||||||
"ssh",
|
|
||||||
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", REMOTE_HOST, command],
|
|
||||||
{ maxBuffer: 5 * 1024 * 1024 },
|
|
||||||
(error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
reject(stderr || error.message)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resolve(stdout)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function remoteDirExists(remoteDir: string): Promise<boolean> {
|
|
||||||
const output = await runSsh(`[ -d ${shellQuote(remoteDir)} ] && echo yes || echo no`)
|
|
||||||
return output.trim() === "yes"
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveFolderRemoteDir(folderName: string): Promise<string | null> {
|
|
||||||
const mapped = FOLDER_MAP[folderName]
|
|
||||||
if (mapped) {
|
|
||||||
return `${REMOTE_ROOT}/${mapped}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const direct = `${REMOTE_ROOT}/${folderName}`
|
|
||||||
if (await remoteDirExists(direct)) {
|
|
||||||
return direct
|
|
||||||
}
|
|
||||||
|
|
||||||
const nested = `${REMOTE_ROOT}/bdd_recette/${folderName}`
|
|
||||||
if (await remoteDirExists(nested)) {
|
|
||||||
return nested
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildContentDisposition(fileName: string) {
|
function buildContentDisposition(fileName: string) {
|
||||||
const asciiName = fileName.replace(/[^\x20-\x7E]/g, "_").replace(/["\\]/g, "_")
|
const asciiName = fileName.replace(/[^\x20-\x7E]/g, "_").replace(/["\\]/g, "_")
|
||||||
return `attachment; filename="${asciiName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
return `attachment; filename="${asciiName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function speedtestStream(event: any) {
|
|
||||||
const size = 128 * 1024 * 1024
|
|
||||||
let sent = 0
|
|
||||||
|
|
||||||
const stream = new Readable({
|
|
||||||
read(chunkSize) {
|
|
||||||
if (sent >= size) {
|
|
||||||
this.push(null)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const remaining = size - sent
|
|
||||||
const chunk = Buffer.alloc(Math.min(chunkSize, remaining), "a")
|
|
||||||
sent += chunk.length
|
|
||||||
this.push(chunk)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
setHeader(event, "Content-Type", "application/octet-stream")
|
|
||||||
setHeader(event, "Content-Length", size)
|
|
||||||
return stream
|
|
||||||
}
|
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const { folder, file } = getQuery(event)
|
const { folder, file } = getQuery(event)
|
||||||
const folderName = typeof folder === "string" ? folder : null
|
const folderName = typeof folder === "string" ? folder : null
|
||||||
const fileName = typeof file === "string" ? file : null
|
const fileName = typeof file === "string" ? file : null
|
||||||
|
|
||||||
// Compat mode: utilisé par le test de débit.
|
|
||||||
if (!folderName || !fileName) {
|
if (!folderName || !fileName) {
|
||||||
return speedtestStream(event)
|
throw createError({ statusCode: 400, statusMessage: "Paramètres manquants" })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSafeFolder(folderName) || !isSafeFile(fileName)) {
|
if (!isSafeFolder(folderName) || !isSafeFile(fileName)) {
|
||||||
|
|||||||
24
server/api/speedtest.get.ts
Normal file
24
server/api/speedtest.get.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { Readable } from "node:stream"
|
||||||
|
|
||||||
|
export default defineEventHandler((event) => {
|
||||||
|
const size = 128 * 1024 * 1024
|
||||||
|
let sent = 0
|
||||||
|
|
||||||
|
const stream = new Readable({
|
||||||
|
read(chunkSize) {
|
||||||
|
if (sent >= size) {
|
||||||
|
this.push(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const remaining = size - sent
|
||||||
|
const chunk = Buffer.alloc(Math.min(chunkSize, remaining), "a")
|
||||||
|
sent += chunk.length
|
||||||
|
this.push(chunk)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
setHeader(event, "Content-Type", "application/octet-stream")
|
||||||
|
setHeader(event, "Content-Length", size)
|
||||||
|
return stream
|
||||||
|
})
|
||||||
5
server/api/system.get.ts
Normal file
5
server/api/system.get.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { getSystemMetricsSnapshot } from "../plugins/metrics-worker"
|
||||||
|
|
||||||
|
export default defineEventHandler(() => {
|
||||||
|
return getSystemMetricsSnapshot()
|
||||||
|
})
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
export default defineEventHandler(async () => {
|
import targets from "../config/version-status-targets.json"
|
||||||
const targets = [
|
|
||||||
{ label: "Ferme", url: "http://ferme.malio-dev.fr/api/version" },
|
|
||||||
{ label: "SIRH", url: "http://sirh.malio-dev.fr/api/version" },
|
|
||||||
{ label: "Inventory", url: "http://inventory.malio-dev.fr/api/health" },
|
|
||||||
]
|
|
||||||
|
|
||||||
|
export default defineEventHandler(async () => {
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
targets.map(async (target) => {
|
targets.map(async (target) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
7
server/config/backup-folders.json
Normal file
7
server/config/backup-folders.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"ferme": "bdd-recette/ferme",
|
||||||
|
"inventory": "bdd-recette/inventory",
|
||||||
|
"sirh": "bdd-recette/sirh",
|
||||||
|
"user": "bdd-recette/user",
|
||||||
|
"bitwarden": "bitwarden"
|
||||||
|
}
|
||||||
7
server/config/backup-options.json
Normal file
7
server/config/backup-options.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
{ "name": "bitwarden", "icon": "mdi:shield-key" },
|
||||||
|
{ "name": "inventory", "icon": "mdi:package-variant-closed" },
|
||||||
|
{ "name": "sirh", "icon": "mdi:account-group" },
|
||||||
|
{ "name": "ferme", "icon": "mdi:barn" },
|
||||||
|
{ "name": "user", "icon": "mdi:account" }
|
||||||
|
]
|
||||||
34
server/config/backup-script.json
Normal file
34
server/config/backup-script.json
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"key": "backup-bdd-recette",
|
||||||
|
"label": "Backup BDD recette",
|
||||||
|
"icon": "mdi:database-export",
|
||||||
|
"downloadFolders": ["ferme", "inventory", "sirh", "user"],
|
||||||
|
"command": "ssh",
|
||||||
|
"args": [
|
||||||
|
"ferme",
|
||||||
|
"cd /home/malio/Malio-ops/RecetteScripts && bash backup-bdd-recette.sh"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "check-statut-recette",
|
||||||
|
"label": "Check statut recette",
|
||||||
|
"icon": "mdi:server-network",
|
||||||
|
"command": "ssh",
|
||||||
|
"args": [
|
||||||
|
"ferme",
|
||||||
|
"cd /home/malio/Malio-ops/RecetteScripts && bash check-statut-recette.sh"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "backup-vaultwarden",
|
||||||
|
"label": "Backup vaultwarden",
|
||||||
|
"icon": "mdi:data",
|
||||||
|
"downloadFolders": ["bitwarden"],
|
||||||
|
"command": "ssh",
|
||||||
|
"args": [
|
||||||
|
"bitwarden",
|
||||||
|
"cd /home/matt/vaultwarden/Malio-ops/BackupVaultWarden && bash backup-vaultwarden.sh"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
19
server/config/disk-commands.json
Normal file
19
server/config/disk-commands.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"key": "remote",
|
||||||
|
"label": "Serveur distant",
|
||||||
|
"command": "ssh",
|
||||||
|
"args": [
|
||||||
|
"malio-b",
|
||||||
|
"cd /home/malio-b/Malio-ops/CheckStorage && bash check-storage.sh"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "local",
|
||||||
|
"label": "Machine locale",
|
||||||
|
"command": "bash",
|
||||||
|
"args": [
|
||||||
|
"/home/kevin/check_storage.sh"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
5
server/config/version-status-targets.json
Normal file
5
server/config/version-status-targets.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[
|
||||||
|
{ "label": "Ferme", "url": "http://ferme.malio-dev.fr/api/version" },
|
||||||
|
{ "label": "SIRH", "url": "http://sirh.malio-dev.fr/api/version" },
|
||||||
|
{ "label": "Inventory", "url": "http://inventory.malio-dev.fr/api/health" }
|
||||||
|
]
|
||||||
25
server/middleware/auth-cookie.ts
Normal file
25
server/middleware/auth-cookie.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
export default defineEventHandler((event) => {
|
||||||
|
const path = event.path || event.node.req.url || ""
|
||||||
|
|
||||||
|
if (path.startsWith("/api/")) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const runtimeConfig = useRuntimeConfig(event)
|
||||||
|
const expectedToken = runtimeConfig.apiSecretKey
|
||||||
|
|
||||||
|
if (!expectedToken) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getCookie(event, "api_auth_token") === expectedToken) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setCookie(event, "api_auth_token", expectedToken, {
|
||||||
|
httpOnly: true,
|
||||||
|
sameSite: "lax",
|
||||||
|
secure: process.env.NODE_ENV === "production",
|
||||||
|
path: "/"
|
||||||
|
})
|
||||||
|
})
|
||||||
31
server/middleware/auth.ts
Normal file
31
server/middleware/auth.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
export default defineEventHandler((event) => {
|
||||||
|
const path = event.path || event.node.req.url || ""
|
||||||
|
|
||||||
|
// Le middleware ne s'applique qu'aux routes API, sauf l'endpoint de ping
|
||||||
|
// qui reste public pour les tests de connectivite.
|
||||||
|
if (!path.startsWith("/api/") || path === "/api/ping") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const runtimeConfig = useRuntimeConfig(event)
|
||||||
|
const authorization = getHeader(event, "authorization")
|
||||||
|
const cookieToken = getCookie(event, "api_auth_token")
|
||||||
|
const expectedToken = runtimeConfig.apiSecretKey
|
||||||
|
|
||||||
|
// Si aucun secret n'est configure cote serveur, on refuse la requete.
|
||||||
|
if (!expectedToken) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 401,
|
||||||
|
statusMessage: "Unauthorized"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Le secret peut venir soit d'un header serveur explicite,
|
||||||
|
// soit du cookie httpOnly pose pour l'application web.
|
||||||
|
if (authorization !== `Bearer ${expectedToken}` && cookieToken !== expectedToken) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 401,
|
||||||
|
statusMessage: "Unauthorized"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
195
server/plugins/metrics-worker.ts
Normal file
195
server/plugins/metrics-worker.ts
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
import fs from "node:fs"
|
||||||
|
import os from "node:os"
|
||||||
|
import type { SystemMetrics } from "~/types/system"
|
||||||
|
|
||||||
|
type CpuTimesSnapshot = {
|
||||||
|
idle: number
|
||||||
|
total: number
|
||||||
|
}
|
||||||
|
|
||||||
|
type NetworkTotals = {
|
||||||
|
rxBytes: number
|
||||||
|
txBytes: number
|
||||||
|
}
|
||||||
|
|
||||||
|
type NetworkSnapshot = NetworkTotals & {
|
||||||
|
timestamp: number
|
||||||
|
}
|
||||||
|
|
||||||
|
let lastCpuSnapshot: CpuTimesSnapshot | null = null
|
||||||
|
let lastNetworkSnapshot: NetworkSnapshot | null = null
|
||||||
|
let intervalId: NodeJS.Timeout | null = null
|
||||||
|
let latestSnapshot: SystemMetrics = createSnapshot({
|
||||||
|
cpuPercent: 0,
|
||||||
|
incomingMbps: 0,
|
||||||
|
outgoingMbps: 0
|
||||||
|
})
|
||||||
|
|
||||||
|
function createSnapshot(overrides: {
|
||||||
|
cpuPercent: number
|
||||||
|
incomingMbps: number
|
||||||
|
outgoingMbps: number
|
||||||
|
}): SystemMetrics {
|
||||||
|
const totalMemory = os.totalmem()
|
||||||
|
const freeMemory = os.freemem()
|
||||||
|
const usedMemory = totalMemory - freeMemory
|
||||||
|
const memoryPercent = totalMemory > 0 ? Math.round((usedMemory / totalMemory) * 100) : 0
|
||||||
|
|
||||||
|
return {
|
||||||
|
cpuPercent: overrides.cpuPercent,
|
||||||
|
memoryPercent,
|
||||||
|
totalMemory,
|
||||||
|
usedMemory,
|
||||||
|
incomingMbps: overrides.incomingMbps,
|
||||||
|
outgoingMbps: overrides.outgoingMbps,
|
||||||
|
sampledAt: new Date().toISOString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCpuSnapshot(): CpuTimesSnapshot {
|
||||||
|
return os.cpus().reduce(
|
||||||
|
(snapshot, cpu) => {
|
||||||
|
const total = Object.values(cpu.times).reduce((sum, value) => sum + value, 0)
|
||||||
|
|
||||||
|
snapshot.idle += cpu.times.idle
|
||||||
|
snapshot.total += total
|
||||||
|
|
||||||
|
return snapshot
|
||||||
|
},
|
||||||
|
{ idle: 0, total: 0 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCpuUsagePercent() {
|
||||||
|
const currentSnapshot = getCpuSnapshot()
|
||||||
|
|
||||||
|
if (!lastCpuSnapshot) {
|
||||||
|
lastCpuSnapshot = currentSnapshot
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const idleDelta = currentSnapshot.idle - lastCpuSnapshot.idle
|
||||||
|
const totalDelta = currentSnapshot.total - lastCpuSnapshot.total
|
||||||
|
lastCpuSnapshot = currentSnapshot
|
||||||
|
|
||||||
|
if (totalDelta <= 0) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.max(0, Math.min(100, Math.round((1 - idleDelta / totalDelta) * 100)))
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNetworkTotals(): NetworkTotals | null {
|
||||||
|
try {
|
||||||
|
const content = fs.readFileSync("/proc/net/dev", "utf8")
|
||||||
|
|
||||||
|
return content
|
||||||
|
.split("\n")
|
||||||
|
.slice(2)
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.reduce(
|
||||||
|
(totals, line) => {
|
||||||
|
const [namePart, valuesPart] = line.split(":")
|
||||||
|
const interfaceName = namePart?.trim()
|
||||||
|
|
||||||
|
if (!interfaceName || interfaceName === "lo" || !valuesPart) {
|
||||||
|
return totals
|
||||||
|
}
|
||||||
|
|
||||||
|
const values = valuesPart.trim().split(/\s+/)
|
||||||
|
const rxBytes = Number.parseInt(values[0] || "0", 10)
|
||||||
|
const txBytes = Number.parseInt(values[8] || "0", 10)
|
||||||
|
|
||||||
|
if (Number.isFinite(rxBytes)) {
|
||||||
|
totals.rxBytes += rxBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Number.isFinite(txBytes)) {
|
||||||
|
totals.txBytes += txBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
return totals
|
||||||
|
},
|
||||||
|
{ rxBytes: 0, txBytes: 0 }
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNetworkRatesMbps() {
|
||||||
|
const totals = getNetworkTotals()
|
||||||
|
const now = Date.now()
|
||||||
|
|
||||||
|
if (!totals) {
|
||||||
|
lastNetworkSnapshot = null
|
||||||
|
return {
|
||||||
|
incomingMbps: 0,
|
||||||
|
outgoingMbps: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentSnapshot: NetworkSnapshot = {
|
||||||
|
...totals,
|
||||||
|
timestamp: now
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lastNetworkSnapshot) {
|
||||||
|
lastNetworkSnapshot = currentSnapshot
|
||||||
|
return {
|
||||||
|
incomingMbps: 0,
|
||||||
|
outgoingMbps: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const elapsedSeconds = (currentSnapshot.timestamp - lastNetworkSnapshot.timestamp) / 1000
|
||||||
|
|
||||||
|
if (elapsedSeconds <= 0) {
|
||||||
|
lastNetworkSnapshot = currentSnapshot
|
||||||
|
return {
|
||||||
|
incomingMbps: 0,
|
||||||
|
outgoingMbps: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const incomingMbps = Math.max(
|
||||||
|
0,
|
||||||
|
Number((((currentSnapshot.rxBytes - lastNetworkSnapshot.rxBytes) * 8) / elapsedSeconds / 1000000).toFixed(2))
|
||||||
|
)
|
||||||
|
const outgoingMbps = Math.max(
|
||||||
|
0,
|
||||||
|
Number((((currentSnapshot.txBytes - lastNetworkSnapshot.txBytes) * 8) / elapsedSeconds / 1000000).toFixed(2))
|
||||||
|
)
|
||||||
|
|
||||||
|
lastNetworkSnapshot = currentSnapshot
|
||||||
|
|
||||||
|
return {
|
||||||
|
incomingMbps,
|
||||||
|
outgoingMbps
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshSnapshot() {
|
||||||
|
const cpuPercent = getCpuUsagePercent()
|
||||||
|
const { incomingMbps, outgoingMbps } = getNetworkRatesMbps()
|
||||||
|
|
||||||
|
latestSnapshot = createSnapshot({
|
||||||
|
cpuPercent,
|
||||||
|
incomingMbps,
|
||||||
|
outgoingMbps
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSystemMetricsSnapshot() {
|
||||||
|
return latestSnapshot
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineNitroPlugin(() => {
|
||||||
|
if (intervalId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshSnapshot()
|
||||||
|
intervalId = setInterval(refreshSnapshot, 2000)
|
||||||
|
})
|
||||||
51
server/utils/ssh.ts
Normal file
51
server/utils/ssh.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { execFile } from "node:child_process"
|
||||||
|
import {process} from "std-env";
|
||||||
|
import folderMap from "#server/config/backup-folders.json";
|
||||||
|
|
||||||
|
export const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST
|
||||||
|
export const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT || "/home/malio-b/backups"
|
||||||
|
export const FOLDER_MAP = folderMap as Record<string, string>
|
||||||
|
|
||||||
|
|
||||||
|
export const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
||||||
|
|
||||||
|
export function runSsh(command: string): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
execFile(
|
||||||
|
"ssh",
|
||||||
|
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", REMOTE_HOST, command],
|
||||||
|
{ maxBuffer: 10 * 1024 * 1024 },
|
||||||
|
(error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
reject(stderr || error.message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve(stdout)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remoteDirExists(remoteDir: string): Promise<boolean> {
|
||||||
|
const output = await runSsh(`[ -d ${shellQuote(remoteDir)} ] && echo yes || echo no`)
|
||||||
|
return output.trim() === "yes"
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resolveFolderRemoteDir(folderName: string): Promise<string | null> {
|
||||||
|
const mapped = FOLDER_MAP[folderName]
|
||||||
|
if (mapped) {
|
||||||
|
return `${REMOTE_ROOT}/${mapped}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const direct = `${REMOTE_ROOT}/${folderName}`
|
||||||
|
if (await remoteDirExists(direct)) {
|
||||||
|
return direct
|
||||||
|
}
|
||||||
|
|
||||||
|
const nested = `${REMOTE_ROOT}/bdd_recette/${folderName}`
|
||||||
|
if (await remoteDirExists(nested)) {
|
||||||
|
return nested
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
9
types/system.ts
Normal file
9
types/system.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export type SystemMetrics = {
|
||||||
|
cpuPercent: number
|
||||||
|
memoryPercent: number
|
||||||
|
totalMemory: number
|
||||||
|
usedMemory: number
|
||||||
|
incomingMbps: number
|
||||||
|
outgoingMbps: number
|
||||||
|
sampledAt: string
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user