Compare commits
42 Commits
c268b2c312
...
fix/reader
| Author | SHA1 | Date | |
|---|---|---|---|
| 071e12a06c | |||
|
|
59f72339fa | ||
| 3963efa986 | |||
|
|
ca8791cc0d | ||
| c2b55e9018 | |||
|
|
07d1b2daed | ||
| a7e6879e83 | |||
|
|
fa035bfbfa | ||
|
|
ec4a8be934 | ||
| 8443120c2f | |||
| 7a8f749f3f | |||
|
|
670e3f5315 | ||
| 4398170989 | |||
|
|
fc4ab68e8b | ||
| 36f873aaca | |||
|
|
874003eb35 | ||
|
|
01474c264b | ||
|
|
795cbeccc3 | ||
| b0ce36096f | |||
|
|
da8a19cbcb | ||
|
|
367b361eef | ||
|
|
9c5ae4bf16 | ||
|
|
6b58e94fc3 | ||
| e78bc890ef | |||
| 47c33d549b | |||
|
|
814fe46ce5 | ||
| 1478b460ba | |||
|
|
65453c87e5 | ||
|
|
78897eda4a | ||
| 02ad36fb34 | |||
| 929a7d0d61 | |||
|
|
9f83f9c137 | ||
| 2cefea3f72 | |||
| 3e85167875 | |||
|
|
f72ae3cab9 | ||
| 2c7f97c8b7 | |||
|
|
1477106459 | ||
| 2243716800 | |||
| d8a47072da | |||
|
|
fb8f64ee59 | ||
| 23c1028ec6 | |||
|
|
aba8e36231 |
142
.claude/skills/task-workflow/SKILL.md
Normal file
142
.claude/skills/task-workflow/SKILL.md
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
---
|
||||||
|
name: task-workflow
|
||||||
|
description: Workflow complet pour traiter une tâche du TASK.md — branche git, développement, tests, commit conventionnel, push, puis archivage dans DONE.md. Utiliser quand l'utilisateur veut implémenter une tâche listée dans TASK.md.
|
||||||
|
allowed-tools: Read, Bash, Edit, Write, Glob, Grep
|
||||||
|
---
|
||||||
|
|
||||||
|
# Workflow de traitement d'une tâche (TASK.md → DONE.md)
|
||||||
|
|
||||||
|
Quand l'utilisateur demande de traiter une tâche du `TASK.md`, suivre **dans l'ordre** les étapes ci-dessous.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚠️ Étape 0 — Repartir d'une branche saine depuis `origin/main`
|
||||||
|
|
||||||
|
**IMPORTANT : toujours commencer par cette étape, sans exception.**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git fetch origin
|
||||||
|
git checkout main
|
||||||
|
git pull origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
Ensuite seulement créer la branche de travail (voir étape 2).
|
||||||
|
|
||||||
|
> Règle : ne jamais partir d'une branche de feature existante. Toujours tirer depuis `main` à jour.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Étape 1 — Lire et choisir la tâche
|
||||||
|
|
||||||
|
1. Lire `TASK.md` pour identifier la tâche à traiter (si non précisée, demander laquelle).
|
||||||
|
2. Extraire : le titre, les fichiers impactés, et la liste des sous-tâches.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Étape 2 — Créer une branche git
|
||||||
|
|
||||||
|
Nommer la branche d'après le type et le titre de la tâche :
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>/<slug-de-la-tache>
|
||||||
|
```
|
||||||
|
|
||||||
|
Exemples de types : `feat`, `fix`, `style`, `refactor`, `test`, `chore`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git checkout -b style/simplifier-table-homepage
|
||||||
|
```
|
||||||
|
|
||||||
|
Règle : **ne jamais committer directement sur `main`**.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Étape 3 — Implémenter la tâche
|
||||||
|
|
||||||
|
- Lire tous les fichiers mentionnés dans la tâche avant de les modifier.
|
||||||
|
- Cocher mentalement chaque sous-tâche `[ ]` au fur et à mesure.
|
||||||
|
- Respecter les skills existants selon les fichiers touchés :
|
||||||
|
- Composant Vue → skill `vue-frontend`
|
||||||
|
- Domaine PHP → skills `ddd-core`, `hexagonal-arch`, `cqrs`, `api-platform`
|
||||||
|
- Tests → skill `testing-strategy`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Étape 4 — Vérifier que tous les tests passent
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make test
|
||||||
|
```
|
||||||
|
|
||||||
|
- Si des tests échouent, **corriger avant de continuer**.
|
||||||
|
- Ne pas passer à l'étape suivante tant que la suite n'est pas verte.
|
||||||
|
- Pour un test spécifique : `make test f="NomDeLaClasse"`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Étape 5 — Commit conventionnel
|
||||||
|
|
||||||
|
Format Conventional Commits :
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>(<scope>): <description courte en français>
|
||||||
|
|
||||||
|
[corps optionnel : explication du pourquoi]
|
||||||
|
```
|
||||||
|
|
||||||
|
**Types autorisés :** `feat`, `fix`, `style`, `refactor`, `test`, `chore`, `docs`
|
||||||
|
|
||||||
|
**Scope :** nom du domaine ou du composant impacté (ex: `manga-table`, `sidebar`, `homepage`)
|
||||||
|
|
||||||
|
Exemples :
|
||||||
|
```
|
||||||
|
style(manga-table): simplifier le wrapper card + hover vert sur le titre
|
||||||
|
fix(sidebar): séparer toggle et navigation sur MenuGroup
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add <fichiers modifiés>
|
||||||
|
git commit -m "style(manga-table): simplifier le wrapper card + hover vert sur le titre"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Étape 6 — Push de la branche
|
||||||
|
|
||||||
|
**Demander confirmation à l'utilisateur avant de pusher.**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git push -u origin <nom-de-la-branche>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Étape 7 — Archiver la tâche dans DONE.md
|
||||||
|
|
||||||
|
1. Retirer le bloc de la tâche de `TASK.md` (section complète, du titre `##` jusqu'au `---` suivant).
|
||||||
|
2. Ajouter la tâche dans `DONE.md` (créer le fichier s'il n'existe pas) avec la date et le sha du commit :
|
||||||
|
|
||||||
|
Format dans `DONE.md` :
|
||||||
|
```markdown
|
||||||
|
## [TYPE] Titre de la tâche — YYYY-MM-DD
|
||||||
|
|
||||||
|
> Branche : `<nom-de-la-branche>` | Commit : `<sha court>`
|
||||||
|
|
||||||
|
- [x] Sous-tâche 1
|
||||||
|
- [x] Sous-tâche 2
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Résumé du flux
|
||||||
|
|
||||||
|
```
|
||||||
|
fetch + checkout main + pull (branche saine)
|
||||||
|
→ branche git depuis main
|
||||||
|
→ TASK.md (choisir la tâche)
|
||||||
|
→ implémentation
|
||||||
|
→ make test (vert obligatoire)
|
||||||
|
→ conventional commit
|
||||||
|
→ push (après confirmation)
|
||||||
|
→ DONE.md
|
||||||
|
```
|
||||||
223
.claude/skills/ui-style/SKILL.md
Normal file
223
.claude/skills/ui-style/SKILL.md
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
---
|
||||||
|
name: ui-style
|
||||||
|
description: Design system et harmonisation UI de Mangarr — layout de page canonique (Toolbar + flex + sections border-t), palette Tailwind, patterns composants (boutons, badges, upload, progression). Utiliser quand on crée ou modifie une page Vue ou un composant UI.
|
||||||
|
allowed-tools: Read, Grep, Glob
|
||||||
|
---
|
||||||
|
|
||||||
|
# Design system Mangarr — Guide UI
|
||||||
|
|
||||||
|
Les pages de référence canoniques sont :
|
||||||
|
- `assets/vue/app/domain/manga/infrastructure/presentation/pages/NewImportPage.vue`
|
||||||
|
- `assets/vue/app/domain/conversion/infrastructure/presentation/pages/ConversionPage.vue`
|
||||||
|
|
||||||
|
En cas de doute, les lire pour vérifier le pattern en vigueur.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Layout de page canonique
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col h-full">
|
||||||
|
<Toolbar :config="toolbarConfig" />
|
||||||
|
<div class="overflow-y-auto flex-1">
|
||||||
|
<div class="px-6 py-8">
|
||||||
|
<section class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-4">
|
||||||
|
Titre section
|
||||||
|
</h2>
|
||||||
|
<!-- contenu -->
|
||||||
|
</section>
|
||||||
|
<section class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
|
<!-- section suivante -->
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Règles absolues :**
|
||||||
|
- `flex flex-col h-full` toujours à la racine du template
|
||||||
|
- `<Toolbar>` toujours en premier enfant direct de la racine
|
||||||
|
- `overflow-y-auto flex-1` pour le contenu scrollable
|
||||||
|
- `px-6 py-8` comme wrapper interne — **jamais** `container mx-auto`
|
||||||
|
- Chaque bloc logique = une `<section>` avec `border-t border-gray-200 dark:border-gray-700`
|
||||||
|
- **Jamais** de `<h1>` volant dans le contenu — le titre de page va dans `toolbarConfig.leftSection`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Configuration Toolbar
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { SomeIcon } from '@heroicons/vue/24/outline';
|
||||||
|
|
||||||
|
const toolbarConfig = computed(() => ({
|
||||||
|
leftSection: [
|
||||||
|
{ type: 'label', text: 'Titre de la page', class: 'text-sm font-medium' },
|
||||||
|
],
|
||||||
|
rightSection: [
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
icon: SomeIcon,
|
||||||
|
label: 'Action principale',
|
||||||
|
onClick: handler,
|
||||||
|
disabled: condition,
|
||||||
|
},
|
||||||
|
// Bouton conditionnel :
|
||||||
|
...(showAction ? [{
|
||||||
|
type: 'button',
|
||||||
|
icon: OtherIcon,
|
||||||
|
label: 'Action contextuelle',
|
||||||
|
onClick: otherHandler,
|
||||||
|
}] : []),
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
```
|
||||||
|
|
||||||
|
- Icônes : Heroicons v24/outline (`@heroicons/vue/24/outline`)
|
||||||
|
- Boutons toolbar visibles uniquement si pertinents — utiliser le spread conditionnel
|
||||||
|
- `rightSection` peut être vide `[]`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Headers de section
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<!-- Header simple -->
|
||||||
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-4">
|
||||||
|
Titre
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<!-- Header avec info contextuelle à droite -->
|
||||||
|
<div class="flex items-center justify-between mb-3">
|
||||||
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider">
|
||||||
|
Titre
|
||||||
|
</h2>
|
||||||
|
<span class="text-xs text-gray-500 dark:text-gray-400">info contextuelle</span>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Palette de couleurs
|
||||||
|
|
||||||
|
| Usage | Classes Tailwind |
|
||||||
|
|-------|-----------------|
|
||||||
|
| Primaire (action principale) | `bg-green-600 hover:bg-green-700` |
|
||||||
|
| Secondaire | `bg-blue-600 hover:bg-blue-700` |
|
||||||
|
| Danger | `bg-red-600 hover:bg-red-700` |
|
||||||
|
| Désactivé | `disabled:bg-gray-400 disabled:cursor-not-allowed` |
|
||||||
|
| Texte principal | `text-gray-900 dark:text-gray-100` |
|
||||||
|
| Texte secondaire | `text-gray-600 dark:text-gray-300` |
|
||||||
|
| Texte subtil | `text-gray-500 dark:text-gray-400` |
|
||||||
|
| Étiquette section | `text-gray-400 dark:text-gray-500` |
|
||||||
|
| Fond carte / panel | `bg-white dark:bg-gray-800` |
|
||||||
|
| Bordure | `border-gray-200 dark:border-gray-700` |
|
||||||
|
| Séparateur de liste | `divide-y divide-gray-100 dark:divide-gray-700/50` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Boutons
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<!-- Bouton action principale (submit, lancer, confirmer) -->
|
||||||
|
<button
|
||||||
|
class="bg-green-600 hover:bg-green-700 disabled:bg-gray-400 disabled:cursor-not-allowed text-white px-4 py-2 rounded-md font-medium transition-colors"
|
||||||
|
:disabled="condition"
|
||||||
|
>
|
||||||
|
Label
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Bouton ghost / discret -->
|
||||||
|
<button class="text-sm text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors">
|
||||||
|
Label
|
||||||
|
</button>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Barre de progression
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<div class="bg-gray-200 dark:bg-gray-700 h-1.5 mb-4">
|
||||||
|
<div
|
||||||
|
class="bg-green-600 h-1.5 transition-all duration-300"
|
||||||
|
:style="{ width: progress + '%' }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Important :** toujours `bg-green-600`, jamais `bg-blue-600` pour les barres de progression.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Liste avec séparateurs
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<div class="divide-y divide-gray-100 dark:divide-gray-700/50">
|
||||||
|
<div
|
||||||
|
v-for="item in items"
|
||||||
|
:key="item.id"
|
||||||
|
class="flex items-center justify-between py-3"
|
||||||
|
>
|
||||||
|
<!-- contenu de l'item -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. Zone de drop / upload de fichier
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<div
|
||||||
|
class="border-2 border-dashed rounded-lg p-8 text-center transition-colors"
|
||||||
|
:class="isDragging
|
||||||
|
? 'border-green-500 bg-green-50 dark:bg-green-900/10'
|
||||||
|
: 'border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600'"
|
||||||
|
@dragover.prevent="isDragging = true"
|
||||||
|
@dragleave="isDragging = false"
|
||||||
|
@drop.prevent="handleDrop"
|
||||||
|
>
|
||||||
|
<SomeIcon class="mx-auto h-8 w-8 text-gray-400 mb-3" />
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-300">
|
||||||
|
Message principal
|
||||||
|
</p>
|
||||||
|
<p class="text-xs text-gray-400 dark:text-gray-500 mt-1">
|
||||||
|
Précision format/taille
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. Pages non conformes à corriger
|
||||||
|
|
||||||
|
Les pages suivantes dévient encore du pattern canonique :
|
||||||
|
|
||||||
|
| Page | Chemin relatif | Déviations principales |
|
||||||
|
|------|---------------|----------------------|
|
||||||
|
| `HomePage.vue` | `domain/manga/.../pages/` | Pas de `px-6 py-8`, pas de sections `border-t` |
|
||||||
|
| `AddManga.vue` | `domain/manga/.../pages/` | Pas de Toolbar, pas de `flex flex-col h-full` |
|
||||||
|
| `ActivityPage.vue` | `domain/activity/.../pages/` | Pas de `flex flex-col`, pas de Toolbar intégré |
|
||||||
|
| `UserPreferencesPage.vue` | `domain/setting/.../pages/` | `h1` volant, pas de Toolbar |
|
||||||
|
| `ScrapperConfigurations.vue` | `domain/setting/.../pages/` | `h1` volant, `container mx-auto` |
|
||||||
|
| `ScrapperEdit.vue` | `domain/setting/.../pages/` | `container mx-auto` au lieu de `px-6 py-8` |
|
||||||
|
| `MangaDetails.vue` | `domain/manga/.../pages/` | Layout spécial (cover + chapitres), à traiter séparément |
|
||||||
|
| `ChapterPage.vue` | `domain/reader/.../pages/` | Layout lecteur spécialisé — **exception justifiée**, ne pas modifier |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. Checklist avant de livrer une page
|
||||||
|
|
||||||
|
- [ ] Racine : `flex flex-col h-full`
|
||||||
|
- [ ] Premier enfant : `<Toolbar :config="toolbarConfig" />`
|
||||||
|
- [ ] Contenu scrollable : `overflow-y-auto flex-1`
|
||||||
|
- [ ] Wrapper interne : `px-6 py-8` (jamais `container mx-auto`)
|
||||||
|
- [ ] Blocs logiques : `<section class="border-t border-gray-200 dark:border-gray-700 pt-6">`
|
||||||
|
- [ ] Titre de page dans `toolbarConfig.leftSection`, pas de `<h1>` dans le contenu
|
||||||
|
- [ ] Headers de section : classes `text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider`
|
||||||
|
- [ ] Barres de progression : `bg-green-600` (pas `bg-blue-600`)
|
||||||
|
- [ ] Dark mode : chaque couleur a sa variante `dark:`
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -39,3 +39,10 @@ yarn-error.log
|
|||||||
src/Controller/TestController.php
|
src/Controller/TestController.php
|
||||||
.phpunit.cache/test-results
|
.phpunit.cache/test-results
|
||||||
/tests/Fixtures/pages/
|
/tests/Fixtures/pages/
|
||||||
|
|
||||||
|
# Claude Code — versionner les skills partagés, ignorer les fichiers perso
|
||||||
|
!.claude/
|
||||||
|
!.claude/skills/
|
||||||
|
!.claude/skills/**
|
||||||
|
.claude/settings.local.json
|
||||||
|
.claude/projects/
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
import { Job } from '../../domain/entities/job';
|
||||||
import { ApiJobRepository } from '../../infrastructure/api/ApiJobRepository';
|
import { ApiJobRepository } from '../../infrastructure/api/ApiJobRepository';
|
||||||
|
|
||||||
const jobRepository = new ApiJobRepository();
|
const jobRepository = new ApiJobRepository();
|
||||||
|
|
||||||
|
const ACTIVE_STATUSES = ['pending', 'in_progress'];
|
||||||
|
|
||||||
export const useActivityStore = defineStore('activity', {
|
export const useActivityStore = defineStore('activity', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
jobs: [],
|
jobs: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
|
mercureEventSource: null,
|
||||||
// Pagination
|
// Pagination
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
totalPages: 0,
|
totalPages: 0,
|
||||||
@@ -15,21 +19,15 @@ export const useActivityStore = defineStore('activity', {
|
|||||||
limit: 20,
|
limit: 20,
|
||||||
hasNextPage: false,
|
hasNextPage: false,
|
||||||
hasPreviousPage: false,
|
hasPreviousPage: false,
|
||||||
// Filtres
|
// Tri
|
||||||
filter: {
|
sortBy: 'createdAt',
|
||||||
status: ['pending', 'in_progress'], // Par défaut, ne montrer que les actifs
|
sortOrder: 'DESC',
|
||||||
sortBy: 'createdAt',
|
|
||||||
sortOrder: 'DESC'
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
activeJobs: state => state.jobs.filter(job => job.isActive()),
|
activeJobs: state => state.jobs.filter(job => job.isActive()),
|
||||||
completedJobs: state => state.jobs.filter(job => job.isCompleted()),
|
|
||||||
failedJobs: state => state.jobs.filter(job => job.hasError()),
|
|
||||||
isLoading: state => state.loading,
|
isLoading: state => state.loading,
|
||||||
hasError: state => !!state.error,
|
hasError: state => !!state.error,
|
||||||
// Getters pour la pagination
|
|
||||||
paginationInfo: state => ({
|
paginationInfo: state => ({
|
||||||
currentPage: state.currentPage,
|
currentPage: state.currentPage,
|
||||||
totalPages: state.totalPages,
|
totalPages: state.totalPages,
|
||||||
@@ -41,44 +39,25 @@ export const useActivityStore = defineStore('activity', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
/**
|
|
||||||
* Charge la liste des jobs selon les filtres actuels
|
|
||||||
* @param {number} page - Numéro de page optionnel
|
|
||||||
*/
|
|
||||||
async loadJobs(page = null) {
|
async loadJobs(page = null) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {
|
const jobCollection = await jobRepository.getJobs({
|
||||||
page: page || this.currentPage,
|
page: page || this.currentPage,
|
||||||
limit: this.limit,
|
limit: this.limit,
|
||||||
sortBy: this.filter.sortBy,
|
sortBy: this.sortBy,
|
||||||
sortOrder: this.filter.sortOrder,
|
sortOrder: this.sortOrder,
|
||||||
status: this.filter.status
|
status: ACTIVE_STATUSES,
|
||||||
};
|
});
|
||||||
|
|
||||||
const jobCollection = await jobRepository.getJobs(options);
|
|
||||||
|
|
||||||
// Mettre à jour les données
|
|
||||||
this.jobs = jobCollection.items;
|
this.jobs = jobCollection.items;
|
||||||
this.currentPage = jobCollection.page;
|
this.currentPage = jobCollection.page;
|
||||||
this.total = jobCollection.total;
|
this.total = jobCollection.total;
|
||||||
this.hasNextPage = jobCollection.hasNextPage;
|
this.hasNextPage = jobCollection.hasNextPage;
|
||||||
this.hasPreviousPage = jobCollection.hasPreviousPage;
|
this.hasPreviousPage = jobCollection.hasPreviousPage;
|
||||||
|
|
||||||
// Calculer le nombre total de pages
|
|
||||||
this.totalPages = Math.ceil(this.total / this.limit);
|
this.totalPages = Math.ceil(this.total / this.limit);
|
||||||
|
|
||||||
console.log('Store updated with:', {
|
|
||||||
jobs: this.jobs.length,
|
|
||||||
currentPage: this.currentPage,
|
|
||||||
total: this.total,
|
|
||||||
limit: this.limit,
|
|
||||||
totalPages: this.totalPages,
|
|
||||||
hasNextPage: this.hasNextPage,
|
|
||||||
hasPreviousPage: this.hasPreviousPage
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.error = error.message;
|
this.error = error.message;
|
||||||
console.error('Error loading jobs:', error);
|
console.error('Error loading jobs:', error);
|
||||||
@@ -87,10 +66,6 @@ export const useActivityStore = defineStore('activity', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Va à une page spécifique
|
|
||||||
* @param {number} page
|
|
||||||
*/
|
|
||||||
async goToPage(page) {
|
async goToPage(page) {
|
||||||
if (page >= 1 && page <= this.totalPages && page !== this.currentPage) {
|
if (page >= 1 && page <= this.totalPages && page !== this.currentPage) {
|
||||||
this.currentPage = page;
|
this.currentPage = page;
|
||||||
@@ -98,39 +73,26 @@ export const useActivityStore = defineStore('activity', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
async updateSort(sortBy, sortOrder) {
|
||||||
* Met à jour les filtres et recharge la liste
|
this.sortBy = sortBy;
|
||||||
* @param {Object} filter
|
this.sortOrder = sortOrder;
|
||||||
*/
|
this.currentPage = 1;
|
||||||
async updateFilter(filter) {
|
|
||||||
this.filter = { ...this.filter, ...filter };
|
|
||||||
this.currentPage = 1; // Retourner à la première page lors du changement de filtre
|
|
||||||
await this.loadJobs(1);
|
await this.loadJobs(1);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Met à jour la limite par page
|
|
||||||
* @param {number} limit
|
|
||||||
*/
|
|
||||||
async updateLimit(limit) {
|
async updateLimit(limit) {
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
this.currentPage = 1; // Retourner à la première page
|
this.currentPage = 1;
|
||||||
await this.loadJobs(1);
|
await this.loadJobs(1);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Supprime un job par son ID
|
|
||||||
* @param {string} id
|
|
||||||
*/
|
|
||||||
async deleteJob(id) {
|
async deleteJob(id) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await jobRepository.deleteJob(id);
|
await jobRepository.deleteJob(id);
|
||||||
// Supprimer le job de la liste locale
|
|
||||||
this.jobs = this.jobs.filter(job => job.id !== id);
|
this.jobs = this.jobs.filter(job => job.id !== id);
|
||||||
// Recharger la page courante pour avoir les bons totaux
|
|
||||||
await this.loadJobs(this.currentPage);
|
await this.loadJobs(this.currentPage);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.error = error.message;
|
this.error = error.message;
|
||||||
@@ -140,17 +102,75 @@ export const useActivityStore = defineStore('activity', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
updateJobProgress(jobId, progress) {
|
||||||
* Supprime tous les jobs correspondant aux critères
|
const job = this.jobs.find(j => j.id === jobId);
|
||||||
* @param {Object} criteria
|
if (job) job.progress = progress;
|
||||||
*/
|
},
|
||||||
|
|
||||||
|
handleJobCreated(data) {
|
||||||
|
const alreadyExists = this.jobs.some(j => j.id === data.id);
|
||||||
|
if (alreadyExists) return;
|
||||||
|
|
||||||
|
const job = Job.create({
|
||||||
|
id: data.id,
|
||||||
|
type: data.type_job,
|
||||||
|
status: data.status,
|
||||||
|
createdAt: data.createdAt,
|
||||||
|
context: data.context,
|
||||||
|
attempts: data.attempts,
|
||||||
|
maxAttempts: data.maxAttempts,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.jobs.unshift(job);
|
||||||
|
this.total += 1;
|
||||||
|
this.totalPages = Math.ceil(this.total / this.limit);
|
||||||
|
},
|
||||||
|
|
||||||
|
handleJobStatusChange(jobId, newStatus) {
|
||||||
|
const job = this.jobs.find(j => j.id === jobId);
|
||||||
|
if (!job) return;
|
||||||
|
|
||||||
|
if (newStatus === 'in_progress') {
|
||||||
|
job.status = 'in_progress';
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.jobs = this.jobs.filter(j => j.id !== jobId);
|
||||||
|
this.total = Math.max(0, this.total - 1);
|
||||||
|
this.totalPages = Math.ceil(this.total / this.limit);
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
subscribeMercure() {
|
||||||
|
if (this.mercureEventSource) return;
|
||||||
|
const url = new URL('/.well-known/mercure', window.location.origin);
|
||||||
|
url.searchParams.append('topic', 'jobs/activity');
|
||||||
|
this.mercureEventSource = new EventSource(url.toString());
|
||||||
|
this.mercureEventSource.onmessage = (event) => {
|
||||||
|
const data = JSON.parse(event.data);
|
||||||
|
if (data.type === 'job.created') {
|
||||||
|
this.handleJobCreated(data);
|
||||||
|
} else if (data.type === 'job.progress_updated') {
|
||||||
|
this.updateJobProgress(data.jobId, data.progress);
|
||||||
|
} else if (data.type === 'job.status_changed') {
|
||||||
|
this.handleJobStatusChange(data.jobId, data.status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
unsubscribeMercure() {
|
||||||
|
if (this.mercureEventSource) {
|
||||||
|
this.mercureEventSource.close();
|
||||||
|
this.mercureEventSource = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async deleteJobs(criteria = {}) {
|
async deleteJobs(criteria = {}) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const deleted = await jobRepository.deleteJobs(criteria);
|
const deleted = await jobRepository.deleteJobs(criteria);
|
||||||
// Recharger la liste après suppression
|
|
||||||
await this.loadJobs(this.currentPage);
|
await this.loadJobs(this.currentPage);
|
||||||
return deleted;
|
return deleted;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -160,26 +180,5 @@ export const useActivityStore = defineStore('activity', {
|
|||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Supprime tous les jobs terminés
|
|
||||||
*/
|
|
||||||
async deleteCompletedJobs() {
|
|
||||||
return this.deleteJobs({ status: ['COMPLETED'] });
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Supprime tous les jobs en erreur
|
|
||||||
*/
|
|
||||||
async deleteFailedJobs() {
|
|
||||||
return this.deleteJobs({ status: ['ERROR'] });
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Supprime tous les jobs
|
|
||||||
*/
|
|
||||||
async deleteAllJobs() {
|
|
||||||
return this.deleteJobs({});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ export class Job {
|
|||||||
failureReason = null,
|
failureReason = null,
|
||||||
createdAt = new Date().toISOString(),
|
createdAt = new Date().toISOString(),
|
||||||
updatedAt = new Date().toISOString(),
|
updatedAt = new Date().toISOString(),
|
||||||
|
startedAt = null,
|
||||||
|
completedAt = null,
|
||||||
attempts = 0,
|
attempts = 0,
|
||||||
maxAttempts = 1,
|
maxAttempts = 1,
|
||||||
context = {}
|
context = {}
|
||||||
@@ -23,6 +25,8 @@ export class Job {
|
|||||||
this.error = failureReason ?? error;
|
this.error = failureReason ?? error;
|
||||||
this.createdAt = createdAt;
|
this.createdAt = createdAt;
|
||||||
this.updatedAt = updatedAt;
|
this.updatedAt = updatedAt;
|
||||||
|
this.startedAt = startedAt;
|
||||||
|
this.completedAt = completedAt;
|
||||||
this.attempts = attempts;
|
this.attempts = attempts;
|
||||||
this.maxAttempts = maxAttempts;
|
this.maxAttempts = maxAttempts;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class ApiJobRepository extends JobRepositoryInterface {
|
|||||||
* @returns {Promise<JobCollection>} Collection de jobs
|
* @returns {Promise<JobCollection>} Collection de jobs
|
||||||
*/
|
*/
|
||||||
async getJobs(options = {}) {
|
async getJobs(options = {}) {
|
||||||
const { page = 1, limit = 100, sortBy = 'createdAt', sortOrder = 'DESC', status = [] } = options;
|
const { page = 1, limit = 100, sortBy = 'createdAt', sortOrder = 'DESC', status = [], type = null } = options;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let url = `/api/jobs?page=${page}&limit=${limit}&sortBy=${sortBy}&sortOrder=${sortOrder}`;
|
let url = `/api/jobs?page=${page}&limit=${limit}&sortBy=${sortBy}&sortOrder=${sortOrder}`;
|
||||||
@@ -23,6 +23,11 @@ export class ApiJobRepository extends JobRepositoryInterface {
|
|||||||
url += `&status=${status.join(',')}`;
|
url += `&status=${status.join(',')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ajouter le filtre de type si fourni
|
||||||
|
if (type) {
|
||||||
|
url += `&type=${type}`;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -1,169 +1,153 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="overflow-y-auto h-full">
|
<div class="flex flex-col h-full">
|
||||||
<Toolbar :config="toolbarConfig" class="mb-6" />
|
<Toolbar :config="toolbarConfig" />
|
||||||
|
|
||||||
<div v-if="activityStore.loading" class="flex justify-center py-8">
|
<div class="overflow-y-auto flex-1">
|
||||||
<div class="animate-spin rounded-full h-10 w-10 border-t-2 border-b-2 border-indigo-500"></div>
|
<!-- Loading -->
|
||||||
</div>
|
<div v-if="loading" class="flex justify-center py-12">
|
||||||
|
<div class="animate-spin h-10 w-10 border-b-2 border-indigo-500 rounded-full"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-else-if="activityStore.error" class="bg-red-100 dark:bg-red-900/20 border-l-4 border-red-500 text-red-700 dark:text-red-400 p-4 mb-6">
|
<!-- Error -->
|
||||||
<p>{{ activityStore.error }}</p>
|
<div v-else-if="activityStore.error" class="px-6 py-8">
|
||||||
</div>
|
<div class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 p-4">
|
||||||
|
<p class="text-red-800 dark:text-red-200">{{ activityStore.error }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-else class="container mx-auto p-2">
|
<!-- Content -->
|
||||||
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow rounded-lg">
|
<section v-else class="border-t border-gray-200 dark:border-gray-700">
|
||||||
<div class="overflow-x-auto">
|
<!-- Empty -->
|
||||||
<table class="min-w-full bg-white dark:bg-gray-800">
|
<div v-if="activityStore.jobs.length === 0" class="flex flex-col items-center justify-center py-20 text-gray-400 dark:text-gray-500">
|
||||||
|
<ClockIcon class="w-12 h-12 mb-3" />
|
||||||
|
<p class="text-base">Aucun job en cours ou en attente.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Table -->
|
||||||
|
<div v-else class="overflow-x-auto">
|
||||||
|
<table class="min-w-full">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200">
|
<tr class="border-b border-gray-200 dark:border-gray-700 text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider">
|
||||||
<th class="w-1/12 py-3 px-4 text-left">
|
<th class="w-2/11 py-3 px-6 text-left">Type</th>
|
||||||
<input
|
<th class="w-2/11 py-3 px-4 text-left">Statut</th>
|
||||||
type="checkbox"
|
<th class="w-3/11 py-3 px-4 text-left">Informations</th>
|
||||||
class="form-checkbox h-5 w-5 text-green-600"
|
<th class="w-3/11 py-3 px-4 text-left">Progression</th>
|
||||||
@change="toggleSelectAll" />
|
<th class="w-1/11 py-3 px-4 text-left">Actions</th>
|
||||||
</th>
|
|
||||||
<th class="w-2/12 py-3 px-4 text-left">Type</th>
|
|
||||||
<th class="w-2/12 py-3 px-4 text-left">Statut</th>
|
|
||||||
<th class="w-3/12 py-3 px-4 text-left">Informations</th>
|
|
||||||
<th class="w-3/12 py-3 px-4 text-left">Progression</th>
|
|
||||||
<th class="w-1/12 py-3 px-4 text-left">Actions</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="text-gray-700 dark:text-gray-300">
|
<tbody class="divide-y divide-gray-100 dark:divide-gray-700/50 text-gray-700 dark:text-gray-300">
|
||||||
<template v-if="activityStore.jobs.length === 0">
|
<JobItem
|
||||||
<tr>
|
v-for="job in activityStore.jobs"
|
||||||
<td colspan="6" class="py-8 px-4 text-center text-gray-500">
|
:key="job.id"
|
||||||
<div class="flex flex-col items-center">
|
:job="job"
|
||||||
<ClockIcon class="h-12 w-12 text-gray-300 dark:text-gray-600 mb-4" />
|
@delete="deleteJob" />
|
||||||
<p class="text-lg font-medium dark:text-gray-300">Aucune activité trouvée</p>
|
|
||||||
<p class="text-sm dark:text-gray-400">Aucune activité ne correspond aux filtres actuels.</p>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</template>
|
|
||||||
<template v-else>
|
|
||||||
<JobItem
|
|
||||||
v-for="job in activityStore.jobs"
|
|
||||||
:key="job.id"
|
|
||||||
:job="job"
|
|
||||||
@delete="deleteJob" />
|
|
||||||
</template>
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Pagination -->
|
<!-- Pagination -->
|
||||||
<Pagination
|
<Pagination
|
||||||
v-if="activityStore.total > activityStore.limit"
|
v-if="total > activityStore.limit"
|
||||||
:current-page="activityStore.currentPage"
|
:current-page="activityStore.currentPage"
|
||||||
:total-pages="activityStore.totalPages"
|
:total-pages="activityStore.totalPages"
|
||||||
:total="activityStore.total"
|
:total="total"
|
||||||
:limit="activityStore.limit"
|
:limit="activityStore.limit"
|
||||||
:has-next-page="activityStore.hasNextPage"
|
:has-next-page="activityStore.hasNextPage"
|
||||||
:has-previous-page="activityStore.hasPreviousPage"
|
:has-previous-page="activityStore.hasPreviousPage"
|
||||||
@page-change="changePage" />
|
@page-change="changePage" />
|
||||||
</div>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ArrowPathIcon, ClockIcon, FunnelIcon, TrashIcon } from '@heroicons/vue/24/outline';
|
import { ArrowPathIcon, BarsArrowDownIcon, ClockIcon, TrashIcon } from '@heroicons/vue/24/outline';
|
||||||
import { computed, onMounted, ref } from 'vue';
|
import { storeToRefs } from 'pinia';
|
||||||
|
import { computed, onMounted, onUnmounted } from 'vue';
|
||||||
import Pagination from '../../../../shared/components/ui/Pagination.vue';
|
import Pagination from '../../../../shared/components/ui/Pagination.vue';
|
||||||
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
||||||
import { useActivityStore } from '../../application/store/activityStore';
|
import { useActivityStore } from '../../application/store/activityStore';
|
||||||
import JobItem from '../components/JobItem.vue';
|
import JobItem from '../components/JobItem.vue';
|
||||||
|
|
||||||
const activityStore = useActivityStore();
|
const activityStore = useActivityStore();
|
||||||
const selectedAll = ref(false);
|
|
||||||
|
|
||||||
// Statuts disponibles pour le filtre
|
const { sortBy, sortOrder, total, loading } = storeToRefs(activityStore);
|
||||||
const statusOptions = [
|
|
||||||
{ value: ['pending', 'in_progress'], label: 'Actifs' },
|
|
||||||
{ value: ['pending', 'in_progress', 'completed', 'failed'], label: 'Tous' },
|
|
||||||
{ value: ['completed'], label: 'Terminés' },
|
|
||||||
{ value: ['failed'], label: 'En erreur' },
|
|
||||||
{ value: ['pending'], label: 'En attente' },
|
|
||||||
{ value: ['in_progress'], label: 'En cours' }
|
|
||||||
];
|
|
||||||
|
|
||||||
// Index du statut actif (par défaut "Actifs")
|
const isSortSelected = (by, order) => sortBy.value === by && sortOrder.value === order;
|
||||||
const activeStatusIndex = ref(0);
|
|
||||||
|
|
||||||
// Configuration de la toolbar réactive
|
const toolbarConfig = computed(() => ({
|
||||||
const toolbarConfig = computed(() => ({
|
leftSection: [
|
||||||
leftSection: [
|
{ type: 'label', text: 'Activité', class: 'text-sm font-medium' },
|
||||||
{
|
{ type: 'label', text: `(${total.value})`, class: 'text-sm text-gray-400' },
|
||||||
icon: FunnelIcon,
|
],
|
||||||
type: 'dropdown',
|
rightSection: [
|
||||||
label: statusOptions[activeStatusIndex.value].label,
|
{
|
||||||
active: false,
|
type: 'dropdown',
|
||||||
items: statusOptions.map((option, index) => ({
|
icon: BarsArrowDownIcon,
|
||||||
label: option.label,
|
label: 'Trier',
|
||||||
isSelected: index === activeStatusIndex.value,
|
items: [
|
||||||
onClick: () => setStatusFilter(index)
|
{
|
||||||
}))
|
label: 'Plus récent',
|
||||||
}
|
isSelected: isSortSelected('createdAt', 'DESC'),
|
||||||
],
|
onClick: () => activityStore.updateSort('createdAt', 'DESC'),
|
||||||
rightSection: [
|
},
|
||||||
{
|
{
|
||||||
icon: ArrowPathIcon,
|
label: 'Plus ancien',
|
||||||
type: 'button',
|
isSelected: isSortSelected('createdAt', 'ASC'),
|
||||||
label: 'Rafraîchir',
|
onClick: () => activityStore.updateSort('createdAt', 'ASC'),
|
||||||
onClick: refreshJobs
|
},
|
||||||
},
|
{
|
||||||
{
|
label: 'Par type',
|
||||||
icon: TrashIcon,
|
isSelected: isSortSelected('type', 'ASC'),
|
||||||
type: 'button',
|
onClick: () => activityStore.updateSort('type', 'ASC'),
|
||||||
label: 'Supprimer visibles',
|
},
|
||||||
onClick: deleteVisibleJobs
|
{
|
||||||
}
|
label: 'Par statut',
|
||||||
]
|
isSelected: isSortSelected('status', 'ASC'),
|
||||||
}));
|
onClick: () => activityStore.updateSort('status', 'ASC'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
icon: ArrowPathIcon,
|
||||||
|
label: 'Rafraîchir',
|
||||||
|
disabled: loading.value,
|
||||||
|
onClick: () => activityStore.loadJobs(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
icon: TrashIcon,
|
||||||
|
label: 'Supprimer visibles',
|
||||||
|
disabled: loading.value || total.value === 0,
|
||||||
|
onClick: deleteVisibleJobs,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadJobs();
|
activityStore.loadJobs();
|
||||||
});
|
activityStore.subscribeMercure();
|
||||||
|
});
|
||||||
|
|
||||||
function loadJobs() {
|
onUnmounted(() => {
|
||||||
activityStore.loadJobs();
|
activityStore.unsubscribeMercure();
|
||||||
|
});
|
||||||
|
|
||||||
|
function changePage(page) {
|
||||||
|
activityStore.goToPage(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteJob(id) {
|
||||||
|
if (confirm('Voulez-vous vraiment supprimer ce job ?')) {
|
||||||
|
activityStore.deleteJob(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function refreshJobs() {
|
function deleteVisibleJobs() {
|
||||||
loadJobs();
|
if (activityStore.jobs.length === 0) return;
|
||||||
}
|
if (confirm('Voulez-vous vraiment supprimer tous les jobs visibles ?')) {
|
||||||
|
activityStore.deleteJobs({ status: ['pending', 'in_progress'] });
|
||||||
function changePage(page) {
|
|
||||||
activityStore.goToPage(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleSelectAll() {
|
|
||||||
selectedAll.value = !selectedAll.value;
|
|
||||||
// La logique pour sélectionner tous les jobs serait ajoutée ici
|
|
||||||
}
|
|
||||||
|
|
||||||
function setStatusFilter(index) {
|
|
||||||
if (index >= 0 && index < statusOptions.length) {
|
|
||||||
activeStatusIndex.value = index;
|
|
||||||
activityStore.updateFilter({ status: statusOptions[index].value });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteJob(id) {
|
|
||||||
if (confirm('Voulez-vous vraiment supprimer ce job ?')) {
|
|
||||||
activityStore.deleteJob(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteVisibleJobs() {
|
|
||||||
if (activityStore.jobs.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const statusLabel = statusOptions[activeStatusIndex.value].label.toLowerCase();
|
|
||||||
if (confirm(`Voulez-vous vraiment supprimer tous les jobs ${statusLabel} ?`)) {
|
|
||||||
activityStore.deleteJobs({ status: activityStore.filter.status });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,84 +1,77 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col h-full bg-gray-50 dark:bg-gray-900">
|
<div class="flex flex-col h-full">
|
||||||
<div class="overflow-y-auto flex-1">
|
<Toolbar :config="toolbarConfig" />
|
||||||
<div class="container mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
|
||||||
|
|
||||||
<FileUploadArea
|
<div class="overflow-y-auto flex-1">
|
||||||
:selected-file="conversionStore.currentFile"
|
<div class="px-6 py-8">
|
||||||
:disabled="conversionStore.isProcessing"
|
|
||||||
@file-selected="handleFileSelected"
|
|
||||||
@file-cleared="handleFileClear"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div v-if="conversionStore.hasSelectedFile && !conversionStore.hasSucceeded" class="mt-6 flex justify-center">
|
<!-- Zone d'upload -->
|
||||||
<button
|
<section class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
@click="handleConvert"
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-4">Fichier</h2>
|
||||||
:disabled="conversionStore.isProcessing"
|
<FileUploadArea
|
||||||
:class="[
|
:selected-file="conversionStore.currentFile"
|
||||||
'flex items-center gap-2 px-6 py-3 text-white font-medium rounded-lg transition-colors',
|
:disabled="conversionStore.isProcessing"
|
||||||
conversionStore.isProcessing
|
@file-selected="handleFileSelected"
|
||||||
? 'bg-gray-400 cursor-not-allowed'
|
@file-cleared="handleFileClear"
|
||||||
: 'bg-green-600 hover:bg-green-700'
|
/>
|
||||||
]"
|
</section>
|
||||||
>
|
|
||||||
<ArrowPathIcon :class="['w-5 h-5', conversionStore.isProcessing && 'animate-spin']" />
|
|
||||||
{{ conversionStore.isProcessing ? 'Conversion en cours...' : 'Convertir en CBZ' }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ConversionProgress
|
<!-- Progression -->
|
||||||
v-if="showProgress"
|
<section v-if="showProgress" class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
class="mt-6"
|
<ConversionProgress
|
||||||
:is-converting="conversionStore.isProcessing"
|
:is-converting="conversionStore.isProcessing"
|
||||||
:progress="conversionStore.conversionProgress"
|
:progress="conversionStore.conversionProgress"
|
||||||
:is-success="conversionStore.hasSucceeded"
|
:is-success="conversionStore.hasSucceeded"
|
||||||
:has-error="conversionStore.hasError"
|
:has-error="conversionStore.hasError"
|
||||||
:error-message="conversionStore.conversionError"
|
:error-message="conversionStore.conversionError"
|
||||||
:file-name="conversionStore.currentFileName"
|
:file-name="conversionStore.currentFileName"
|
||||||
:original-size="conversionStore.currentFile?.size || 0"
|
:original-size="conversionStore.currentFile?.size || 0"
|
||||||
:converted-size="conversionStore.convertedFile?.size || 0"
|
:converted-size="conversionStore.convertedFile?.size || 0"
|
||||||
@download="handleDownload"
|
@download="handleDownload"
|
||||||
@reset="handleReset"
|
@reset="handleReset"
|
||||||
/>
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Historique -->
|
||||||
|
<section v-if="conversionStore.conversionCount > 0" class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
|
<div class="flex items-center justify-between mb-3">
|
||||||
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider">Historique</h2>
|
||||||
|
<button
|
||||||
|
@click="conversionStore.clearHistory()"
|
||||||
|
class="text-sm text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors"
|
||||||
|
>
|
||||||
|
Effacer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="divide-y divide-gray-100 dark:divide-gray-700/50">
|
||||||
|
<div
|
||||||
|
v-for="(conversion, index) in conversionStore.conversionHistory"
|
||||||
|
:key="index"
|
||||||
|
class="flex items-center justify-between py-3"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<p class="text-sm text-gray-900 dark:text-gray-100">{{ conversion.originalName }}</p>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400">{{ formatDate(conversion.timestamp) }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="text-right text-sm">
|
||||||
|
<p class="text-gray-600 dark:text-gray-300">
|
||||||
|
{{ formatFileSize(conversion.originalSize) }} → {{ formatFileSize(conversion.convertedSize) }}
|
||||||
|
</p>
|
||||||
|
<p class="text-xs text-green-600">{{ calculateSaving(conversion.originalSize, conversion.convertedSize) }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<div v-if="conversionStore.conversionCount > 0" class="mt-8">
|
|
||||||
<div class="flex items-center justify-between mb-3">
|
|
||||||
<h3 class="text-sm font-medium text-gray-700 dark:text-gray-300">Historique</h3>
|
|
||||||
<button
|
|
||||||
@click="conversionStore.clearHistory()"
|
|
||||||
class="text-sm text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors"
|
|
||||||
>
|
|
||||||
Effacer
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="divide-y divide-gray-200 dark:divide-gray-700">
|
|
||||||
<div
|
|
||||||
v-for="(conversion, index) in conversionStore.conversionHistory"
|
|
||||||
:key="index"
|
|
||||||
class="flex items-center justify-between py-3"
|
|
||||||
>
|
|
||||||
<div>
|
|
||||||
<p class="text-sm text-gray-900 dark:text-gray-100">{{ conversion.originalName }}</p>
|
|
||||||
<p class="text-xs text-gray-500 dark:text-gray-400">{{ formatDate(conversion.timestamp) }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="text-right text-sm">
|
|
||||||
<p class="text-gray-600 dark:text-gray-300">
|
|
||||||
{{ formatFileSize(conversion.originalSize) }} → {{ formatFileSize(conversion.convertedSize) }}
|
|
||||||
</p>
|
|
||||||
<p class="text-xs text-green-600">{{ calculateSaving(conversion.originalSize, conversion.convertedSize) }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ArrowPathIcon } from '@heroicons/vue/24/outline';
|
import { ArrowPathIcon } from '@heroicons/vue/24/outline';
|
||||||
import { computed, onMounted } from 'vue';
|
import { computed, onMounted } from 'vue';
|
||||||
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
||||||
import { useConversionStore } from '../../application/store/conversionStore';
|
import { useConversionStore } from '../../application/store/conversionStore';
|
||||||
import { useNotifications } from '../../../../shared/composables/useNotifications';
|
import { useNotifications } from '../../../../shared/composables/useNotifications';
|
||||||
import ConversionProgress from '../components/ConversionProgress.vue';
|
import ConversionProgress from '../components/ConversionProgress.vue';
|
||||||
@@ -88,53 +81,68 @@ const conversionStore = useConversionStore();
|
|||||||
const { showSuccess, showError } = useNotifications();
|
const { showSuccess, showError } = useNotifications();
|
||||||
|
|
||||||
const showProgress = computed(() =>
|
const showProgress = computed(() =>
|
||||||
conversionStore.hasSelectedFile &&
|
conversionStore.hasSelectedFile &&
|
||||||
(conversionStore.isProcessing || conversionStore.hasSucceeded || conversionStore.hasError)
|
(conversionStore.isProcessing || conversionStore.hasSucceeded || conversionStore.hasError)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const toolbarConfig = computed(() => ({
|
||||||
|
leftSection: [
|
||||||
|
{ type: 'label', text: 'Conversion CBR → CBZ', class: 'text-sm font-medium' },
|
||||||
|
],
|
||||||
|
rightSection: [
|
||||||
|
...(conversionStore.hasSelectedFile && !conversionStore.hasSucceeded ? [{
|
||||||
|
type: 'button',
|
||||||
|
icon: ArrowPathIcon,
|
||||||
|
label: conversionStore.isProcessing ? 'Conversion en cours...' : 'Convertir en CBZ',
|
||||||
|
onClick: handleConvert,
|
||||||
|
disabled: conversionStore.isProcessing,
|
||||||
|
}] : []),
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
const handleFileSelected = (file) => {
|
const handleFileSelected = (file) => {
|
||||||
conversionStore.selectFile(file);
|
conversionStore.selectFile(file);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFileClear = () => {
|
const handleFileClear = () => {
|
||||||
conversionStore.resetConversion();
|
conversionStore.resetConversion();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleConvert = async () => {
|
const handleConvert = async () => {
|
||||||
if (!conversionStore.currentFile) return;
|
if (!conversionStore.currentFile) return;
|
||||||
const success = await conversionStore.convertCurrentFile();
|
const success = await conversionStore.convertCurrentFile();
|
||||||
if (success) {
|
if (success) {
|
||||||
showSuccess('Conversion réussie !');
|
showSuccess('Conversion réussie !');
|
||||||
} else {
|
} else {
|
||||||
showError(conversionStore.conversionError ?? 'Échec de la conversion');
|
showError(conversionStore.conversionError ?? 'Échec de la conversion');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDownload = () => conversionStore.downloadConvertedFile();
|
const handleDownload = () => conversionStore.downloadConvertedFile();
|
||||||
const handleReset = () => conversionStore.resetConversion();
|
const handleReset = () => conversionStore.resetConversion();
|
||||||
|
|
||||||
const formatFileSize = (bytes) => {
|
const formatFileSize = (bytes) => {
|
||||||
if (bytes === 0) return '0 octets';
|
if (bytes === 0) return '0 octets';
|
||||||
const k = 1024;
|
const k = 1024;
|
||||||
const sizes = ['octets', 'Ko', 'Mo', 'Go'];
|
const sizes = ['octets', 'Ko', 'Mo', 'Go'];
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatDate = (isoString) =>
|
const formatDate = (isoString) =>
|
||||||
new Intl.DateTimeFormat('fr-FR', {
|
new Intl.DateTimeFormat('fr-FR', {
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
month: 'short',
|
month: 'short',
|
||||||
hour: '2-digit',
|
hour: '2-digit',
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
}).format(new Date(isoString));
|
}).format(new Date(isoString));
|
||||||
|
|
||||||
const calculateSaving = (originalSize, convertedSize) => {
|
const calculateSaving = (originalSize, convertedSize) => {
|
||||||
if (!originalSize || !convertedSize) return '';
|
if (!originalSize || !convertedSize) return '';
|
||||||
const saving = ((originalSize - convertedSize) / originalSize) * 100;
|
const saving = ((originalSize - convertedSize) / originalSize) * 100;
|
||||||
if (saving > 0) return `-${saving.toFixed(1)}%`;
|
if (saving > 0) return `-${saving.toFixed(1)}%`;
|
||||||
if (saving < 0) return `+${Math.abs(saving).toFixed(1)}%`;
|
if (saving < 0) return `+${Math.abs(saving).toFixed(1)}%`;
|
||||||
return '0%';
|
return '0%';
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => conversionStore.resetConversion());
|
onMounted(() => conversionStore.resetConversion());
|
||||||
|
|||||||
@@ -1,228 +1,150 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border dark:border-gray-700 p-6">
|
<div class="py-3">
|
||||||
<div class="flex items-start space-x-4">
|
|
||||||
<!-- File Icon and Info -->
|
|
||||||
<div class="flex-shrink-0">
|
|
||||||
<div class="w-12 h-12 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center">
|
|
||||||
<svg class="w-6 h-6 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- File Details -->
|
<!-- Row principal : icône, nom, statut, actions -->
|
||||||
<div class="flex-1 min-w-0">
|
<div class="flex items-center gap-3">
|
||||||
<div class="flex items-center justify-between">
|
<div class="w-8 h-8 bg-gray-100 dark:bg-gray-700 flex items-center justify-center shrink-0">
|
||||||
<h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 truncate">
|
<DocumentIcon class="w-4 h-4 text-gray-500 dark:text-gray-400" />
|
||||||
{{ file.filename }}
|
</div>
|
||||||
</h3>
|
|
||||||
|
<div class="flex-1 min-w-0">
|
||||||
<!-- Status Badge -->
|
<p class="text-sm font-medium text-gray-900 dark:text-gray-100 truncate">{{ file.filename }}</p>
|
||||||
<div class="flex-shrink-0 ml-4">
|
<p class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
<StatusBadge :status="file.status" :is-analyzing="isAnalyzing" :is-importing="isImporting" />
|
{{ file.getFormattedSize() }} · {{ file.getFileExtension().toUpperCase() }}
|
||||||
</div>
|
<span v-if="file.isAnalyzed() && file.getExtractedChapterNumber()" class="ml-2 text-green-600 dark:text-green-400">
|
||||||
</div>
|
Ch. {{ file.getExtractedChapterNumber() }}
|
||||||
|
</span>
|
||||||
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">
|
<span v-if="file.isAnalyzed() && file.getExtractedVolumeNumber()" class="ml-2 text-green-600 dark:text-green-400">
|
||||||
{{ file.getFormattedSize() }} • {{ file.getFileExtension().toUpperCase() }}
|
Vol. {{ file.getExtractedVolumeNumber() }}
|
||||||
</p>
|
</span>
|
||||||
|
</p>
|
||||||
<!-- Extracted Info -->
|
</div>
|
||||||
<div v-if="file.isAnalyzed()" class="mt-2 flex gap-3 text-sm">
|
|
||||||
<span v-if="file.getExtractedChapterNumber()" class="inline-flex items-center px-2 py-1 rounded-md bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300">
|
<div class="flex items-center gap-2 shrink-0">
|
||||||
Chapitre {{ file.getExtractedChapterNumber() }}
|
<StatusBadge :status="file.status" :is-analyzing="isAnalyzing" :is-importing="isImporting" />
|
||||||
</span>
|
|
||||||
<span v-if="file.getExtractedVolumeNumber()" class="inline-flex items-center px-2 py-1 rounded-md bg-purple-50 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300">
|
<button
|
||||||
Volume {{ file.getExtractedVolumeNumber() }}
|
v-if="file.isReadyForImport()"
|
||||||
</span>
|
@click="$emit('import-file')"
|
||||||
</div>
|
:disabled="isImporting"
|
||||||
|
class="inline-flex items-center gap-1 px-3 py-1.5 bg-green-600 hover:bg-green-700 disabled:bg-gray-400 text-white text-xs font-medium transition-colors"
|
||||||
<!-- Error Display -->
|
>
|
||||||
<div v-if="file.hasError()" class="mt-3 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-md">
|
<ArrowUpTrayIcon class="w-3.5 h-3.5" />
|
||||||
<div class="flex">
|
Importer
|
||||||
<svg class="flex-shrink-0 h-5 w-5 text-red-400" fill="currentColor" viewBox="0 0 20 20">
|
</button>
|
||||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
<button
|
||||||
<div class="ml-3">
|
v-if="file.hasError()"
|
||||||
<h3 class="text-sm font-medium text-red-800 dark:text-red-300">Erreur</h3>
|
@click="$emit('retry-file')"
|
||||||
<div class="mt-2 text-sm text-red-700 dark:text-red-400">{{ file.errorMessage }}</div>
|
class="inline-flex items-center gap-1 px-3 py-1.5 bg-green-600 hover:bg-green-700 text-white text-xs font-medium transition-colors"
|
||||||
|
>
|
||||||
|
Réessayer
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
@click="$emit('remove-file')"
|
||||||
|
class="p-1.5 text-gray-400 hover:text-red-500 dark:hover:text-red-400 transition-colors"
|
||||||
|
title="Supprimer"
|
||||||
|
>
|
||||||
|
<XMarkIcon class="w-4 h-4" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Manga Selection -->
|
<!-- Message d'erreur -->
|
||||||
<div v-if="file.isAnalyzed() && file.hasMatches()" class="mt-4 space-y-3">
|
<div v-if="file.hasError()" class="mt-2 flex items-start gap-2 text-xs text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-900/20 px-3 py-2">
|
||||||
<div>
|
<ExclamationCircleIcon class="w-4 h-4 shrink-0 mt-0.5" />
|
||||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">
|
{{ file.errorMessage }}
|
||||||
Sélectionner un manga ({{ file.getMatches().length }} correspondance(s) trouvée(s))
|
</div>
|
||||||
</label>
|
|
||||||
|
|
||||||
<!-- Matches Grid -->
|
<!-- Aucun manga trouvé -->
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
|
<div v-if="file.isAnalyzed() && !file.hasMatches()" class="mt-2 flex items-start gap-2 text-xs text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-900/20 px-3 py-2">
|
||||||
<MangaMatchCard
|
<ExclamationTriangleIcon class="w-4 h-4 shrink-0 mt-0.5" />
|
||||||
v-for="match in sortedMatches"
|
Aucun manga correspondant trouvé. Vérifiez le nom du fichier.
|
||||||
:key="match.id"
|
</div>
|
||||||
:match="match"
|
|
||||||
:is-selected="file.selectedManga?.id === match.id"
|
<!-- Sélection du manga -->
|
||||||
@select-match="handleMangaSelection"
|
<div v-if="file.isAnalyzed() && file.hasMatches()" class="mt-3 space-y-3">
|
||||||
/>
|
<p class="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide">
|
||||||
|
{{ file.getMatches().length }} correspondance(s)
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-2">
|
||||||
|
<MangaMatchCard
|
||||||
|
v-for="match in sortedMatches"
|
||||||
|
:key="match.id"
|
||||||
|
:match="match"
|
||||||
|
:is-selected="file.selectedManga?.id === match.id"
|
||||||
|
@select-match="handleMangaSelection"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Selected Manga Preview -->
|
<!-- Numéros de chapitre / volume -->
|
||||||
<div v-if="file.selectedManga" class="flex items-center gap-3 p-3 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-md">
|
<div v-if="file.selectedManga" class="mt-3 grid grid-cols-2 gap-3">
|
||||||
<img
|
|
||||||
v-if="file.selectedManga.thumbnailUrl"
|
|
||||||
:src="file.selectedManga.thumbnailUrl"
|
|
||||||
:alt="file.selectedManga.title"
|
|
||||||
class="w-12 h-16 object-cover rounded"
|
|
||||||
/>
|
|
||||||
<div class="flex-1">
|
|
||||||
<p class="font-medium text-gray-900 dark:text-gray-100">{{ file.selectedManga.title }}</p>
|
|
||||||
<p class="text-sm text-gray-500 dark:text-gray-400">{{ file.selectedManga.slug }}</p>
|
|
||||||
<p class="text-xs text-blue-600 dark:text-blue-400 mt-1">Score: {{ file.selectedManga.matchScore }}%</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Chapter/Volume Number Inputs -->
|
|
||||||
<div v-if="file.selectedManga" class="grid grid-cols-2 gap-3">
|
|
||||||
<!-- Chapter Number -->
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
<label class="block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1">Chapitre</label>
|
||||||
Numéro de chapitre
|
<input
|
||||||
</label>
|
type="number"
|
||||||
<input
|
step="0.5"
|
||||||
type="number"
|
:value="file.selectedChapterNumber ?? ''"
|
||||||
step="0.5"
|
@input="handleChapterNumberInput"
|
||||||
:value="file.selectedChapterNumber ?? ''"
|
:disabled="file.selectedVolumeNumber !== null"
|
||||||
@input="handleChapterNumberInput"
|
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-green-500 disabled:bg-gray-100 dark:disabled:bg-gray-600 disabled:text-gray-400"
|
||||||
:disabled="file.selectedVolumeNumber !== null"
|
placeholder="Ex: 1, 1.5..."
|
||||||
class="w-full border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 dark:disabled:bg-gray-600"
|
/>
|
||||||
placeholder="Ex: 1, 1.5, 2..."
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Volume Number -->
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
<label class="block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1">Volume</label>
|
||||||
Numéro de volume
|
<input
|
||||||
</label>
|
type="number"
|
||||||
<input
|
step="0.5"
|
||||||
type="number"
|
:value="file.selectedVolumeNumber ?? ''"
|
||||||
step="0.5"
|
@input="handleVolumeNumberInput"
|
||||||
:value="file.selectedVolumeNumber ?? ''"
|
:disabled="file.selectedChapterNumber !== null"
|
||||||
@input="handleVolumeNumberInput"
|
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-green-500 disabled:bg-gray-100 dark:disabled:bg-gray-600 disabled:text-gray-400"
|
||||||
:disabled="file.selectedChapterNumber !== null"
|
placeholder="Ex: 1, 1.5..."
|
||||||
class="w-full border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 dark:disabled:bg-gray-600"
|
/>
|
||||||
placeholder="Ex: 1, 1.5, 2..."
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- No Matches Message -->
|
|
||||||
<div v-if="file.isAnalyzed() && !file.hasMatches()" class="mt-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-md">
|
|
||||||
<div class="flex">
|
|
||||||
<svg class="flex-shrink-0 h-5 w-5 text-yellow-400" fill="currentColor" viewBox="0 0 20 20">
|
|
||||||
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
<div class="ml-3">
|
|
||||||
<h3 class="text-sm font-medium text-yellow-800 dark:text-yellow-300">Aucun manga trouvé</h3>
|
|
||||||
<div class="mt-2 text-sm text-yellow-700 dark:text-yellow-400">
|
|
||||||
Aucun manga ne correspond à ce fichier. Vérifiez le nom du fichier.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Actions -->
|
|
||||||
<div class="mt-6 flex justify-between items-center border-t dark:border-gray-700 pt-4">
|
|
||||||
<div class="flex space-x-3">
|
|
||||||
<!-- Import Button -->
|
|
||||||
<button
|
|
||||||
v-if="file.isReadyForImport()"
|
|
||||||
@click="$emit('import-file')"
|
|
||||||
:disabled="isImporting"
|
|
||||||
class="bg-green-600 hover:bg-green-700 disabled:bg-gray-400 text-white px-4 py-2 rounded-md text-sm font-medium flex items-center"
|
|
||||||
>
|
|
||||||
<svg v-if="isImporting" class="animate-spin -ml-1 mr-2 h-4 w-4 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
|
||||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
|
||||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
|
||||||
</svg>
|
|
||||||
{{ isImporting ? 'Import en cours...' : 'Importer' }}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<!-- Retry Button -->
|
|
||||||
<button
|
|
||||||
v-if="file.hasError()"
|
|
||||||
@click="$emit('retry-file')"
|
|
||||||
class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium"
|
|
||||||
>
|
|
||||||
Réessayer
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Remove Button -->
|
|
||||||
<button
|
|
||||||
@click="$emit('remove-file')"
|
|
||||||
class="text-red-600 hover:text-red-700 text-sm font-medium"
|
|
||||||
>
|
|
||||||
Supprimer
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { ArrowUpTrayIcon, DocumentIcon, ExclamationCircleIcon, ExclamationTriangleIcon, XMarkIcon } from '@heroicons/vue/24/outline';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import MangaMatchCard from './MangaMatchCard.vue';
|
import MangaMatchCard from './MangaMatchCard.vue';
|
||||||
import StatusBadge from './StatusBadge.vue';
|
import StatusBadge from './StatusBadge.vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
file: {
|
file: { type: Object, required: true },
|
||||||
type: Object,
|
isAnalyzing: { type: Boolean, default: false },
|
||||||
required: true
|
isImporting: { type: Boolean, default: false },
|
||||||
},
|
|
||||||
isAnalyzing: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
isImporting: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits([
|
const emit = defineEmits([
|
||||||
'manga-selected',
|
'manga-selected',
|
||||||
'chapter-number-selected',
|
'chapter-number-selected',
|
||||||
'volume-number-selected',
|
'volume-number-selected',
|
||||||
'import-file',
|
'import-file',
|
||||||
'retry-file',
|
'retry-file',
|
||||||
'remove-file'
|
'remove-file',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Computed property to get sorted matches
|
const sortedMatches = computed(() =>
|
||||||
const sortedMatches = computed(() => {
|
[...props.file.getMatches()].sort((a, b) => b.matchScore - a.matchScore)
|
||||||
const matches = props.file.getMatches();
|
);
|
||||||
return matches.sort((a, b) => b.matchScore - a.matchScore);
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleMangaSelection = (selectedManga) => {
|
const handleMangaSelection = (manga) => emit('manga-selected', manga);
|
||||||
emit('manga-selected', selectedManga);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChapterNumberInput = (event) => {
|
const handleChapterNumberInput = (event) => {
|
||||||
const value = event.target.value;
|
const value = event.target.value;
|
||||||
const chapterNumber = value ? parseFloat(value) : null;
|
emit('chapter-number-selected', value ? parseFloat(value) : null);
|
||||||
emit('chapter-number-selected', chapterNumber);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleVolumeNumberInput = (event) => {
|
const handleVolumeNumberInput = (event) => {
|
||||||
const value = event.target.value;
|
const value = event.target.value;
|
||||||
const volumeNumber = value ? parseFloat(value) : null;
|
emit('volume-number-selected', value ? parseFloat(value) : null);
|
||||||
emit('volume-number-selected', volumeNumber);
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,96 +1,94 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border dark:border-gray-700 p-6">
|
<div>
|
||||||
<div class="text-center mb-6">
|
<!-- En-tête -->
|
||||||
<div class="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-green-100 dark:bg-green-900/40 mb-4">
|
<section class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
<svg class="h-6 w-6 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<div class="flex items-center justify-between">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
<div class="flex items-center gap-3">
|
||||||
</svg>
|
<div class="flex items-center justify-center h-9 w-9 bg-green-100 dark:bg-green-900/40">
|
||||||
|
<CheckCircleIcon class="h-5 w-5 text-green-600" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="text-sm font-medium text-gray-900 dark:text-gray-100">Import terminé</h3>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400">Voici le résumé de votre session d'import</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-6 text-center">
|
||||||
|
<div>
|
||||||
|
<div class="text-xl font-bold text-green-600">{{ importedCount }}</div>
|
||||||
|
<div class="text-xs text-gray-500 dark:text-gray-400">Importés</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="text-xl font-bold text-red-600">{{ errorCount }}</div>
|
||||||
|
<div class="text-xs text-gray-500 dark:text-gray-400">Erreurs</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="text-xl font-bold text-gray-600 dark:text-gray-300">{{ totalCount }}</div>
|
||||||
|
<div class="text-xs text-gray-500 dark:text-gray-400">Total</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 mb-2">Import terminé</h3>
|
</section>
|
||||||
<p class="text-sm text-gray-500 dark:text-gray-400">
|
|
||||||
Voici le résumé de votre session d'import
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Statistics -->
|
<!-- Fichiers importés -->
|
||||||
<div class="grid grid-cols-3 gap-4 mb-6">
|
<section v-if="importedFiles.length > 0" class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
<div class="text-center">
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-3">
|
||||||
<div class="text-2xl font-bold text-green-600">{{ importedCount }}</div>
|
Importés ({{ importedFiles.length }})
|
||||||
<div class="text-sm text-gray-500 dark:text-gray-400">Importés</div>
|
</h2>
|
||||||
</div>
|
<div class="divide-y divide-gray-100 dark:divide-gray-700/50">
|
||||||
<div class="text-center">
|
<div
|
||||||
<div class="text-2xl font-bold text-red-600">{{ errorCount }}</div>
|
|
||||||
<div class="text-sm text-gray-500">Erreurs</div>
|
|
||||||
</div>
|
|
||||||
<div class="text-center">
|
|
||||||
<div class="text-2xl font-bold text-gray-600">{{ totalCount }}</div>
|
|
||||||
<div class="text-sm text-gray-500">Total</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Success Files List -->
|
|
||||||
<div v-if="importedFiles.length > 0" class="mb-6">
|
|
||||||
<h4 class="text-sm font-medium text-gray-900 dark:text-gray-100 mb-3">
|
|
||||||
Fichiers importés avec succès ({{ importedFiles.length }})
|
|
||||||
</h4>
|
|
||||||
<ul class="space-y-2">
|
|
||||||
<li
|
|
||||||
v-for="file in importedFiles"
|
v-for="file in importedFiles"
|
||||||
:key="file.id"
|
:key="file.id"
|
||||||
class="flex items-center text-sm"
|
class="flex items-center gap-2 py-2.5 text-sm"
|
||||||
>
|
>
|
||||||
<svg class="flex-shrink-0 h-4 w-4 text-green-400 mr-2" fill="currentColor" viewBox="0 0 20 20">
|
<CheckCircleIcon class="flex-shrink-0 h-4 w-4 text-green-400" />
|
||||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
|
<span class="text-gray-900 dark:text-gray-100 truncate">{{ file.filename }}</span>
|
||||||
</svg>
|
<span v-if="file.selectedManga" class="text-gray-400 dark:text-gray-500 shrink-0">→ {{ file.selectedManga.title }}</span>
|
||||||
<span class="text-gray-900 dark:text-gray-100">{{ file.filename }}</span>
|
</div>
|
||||||
<span v-if="file.selectedManga" class="ml-2 text-gray-500 dark:text-gray-400">
|
</div>
|
||||||
→ {{ file.selectedManga.title }}
|
</section>
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Error Files List -->
|
<!-- Fichiers en erreur -->
|
||||||
<div v-if="errorFiles.length > 0" class="mb-6">
|
<section v-if="errorFiles.length > 0" class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
<h4 class="text-sm font-medium text-gray-900 dark:text-gray-100 mb-3">
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-3">
|
||||||
Fichiers en erreur ({{ errorFiles.length }})
|
Erreurs ({{ errorFiles.length }})
|
||||||
</h4>
|
</h2>
|
||||||
<ul class="space-y-2">
|
<div class="divide-y divide-gray-100 dark:divide-gray-700/50">
|
||||||
<li
|
<div
|
||||||
v-for="file in errorFiles"
|
v-for="file in errorFiles"
|
||||||
:key="file.id"
|
:key="file.id"
|
||||||
class="flex items-start text-sm"
|
class="flex items-start gap-2 py-2.5 text-sm"
|
||||||
>
|
>
|
||||||
<svg class="flex-shrink-0 h-4 w-4 text-red-400 mr-2 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
|
<XCircleIcon class="flex-shrink-0 h-4 w-4 text-red-400 mt-0.5" />
|
||||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
<div>
|
<div>
|
||||||
<div class="text-gray-900 dark:text-gray-100">{{ file.filename }}</div>
|
<div class="text-gray-900 dark:text-gray-100">{{ file.filename }}</div>
|
||||||
<div class="text-red-600 dark:text-red-400 text-xs mt-1">{{ file.errorMessage }}</div>
|
<div class="text-red-600 dark:text-red-400 text-xs mt-0.5">{{ file.errorMessage }}</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</div>
|
||||||
</ul>
|
</div>
|
||||||
</div>
|
</section>
|
||||||
|
|
||||||
<!-- Actions -->
|
<!-- Actions -->
|
||||||
<div class="flex justify-center space-x-4 pt-6 border-t dark:border-gray-700">
|
<section class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
<button
|
<div class="flex gap-3">
|
||||||
@click="startNewImport"
|
<button
|
||||||
class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium"
|
@click="startNewImport"
|
||||||
>
|
class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 text-sm font-medium"
|
||||||
Nouvel import
|
>
|
||||||
</button>
|
Nouvel import
|
||||||
<button
|
</button>
|
||||||
@click="goToLibrary"
|
<button
|
||||||
class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded-md text-sm font-medium"
|
@click="goToLibrary"
|
||||||
>
|
class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 text-sm font-medium"
|
||||||
Aller à la bibliothèque
|
>
|
||||||
</button>
|
Aller à la bibliothèque
|
||||||
</div>
|
</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { CheckCircleIcon, XCircleIcon } from '@heroicons/vue/24/solid';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useNewImportStore } from '../../application/store/newImportStore';
|
import { useNewImportStore } from '../../application/store/newImportStore';
|
||||||
|
|||||||
@@ -1,116 +1,47 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="border rounded-lg p-4 cursor-pointer transition-all duration-200 hover:shadow-md"
|
class="border p-2.5 cursor-pointer transition-all duration-150"
|
||||||
:class="{
|
:class="isSelected
|
||||||
'border-blue-500 bg-blue-50 dark:bg-blue-900/20': isSelected,
|
? 'border-green-500 bg-green-50 dark:bg-green-900/20'
|
||||||
'border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-500': !isSelected
|
: 'border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600 bg-white dark:bg-gray-800'"
|
||||||
}"
|
@click="$emit('select-match', match)"
|
||||||
@click="$emit('select-match', match)"
|
>
|
||||||
>
|
<div class="flex gap-2.5">
|
||||||
<!-- Match Header with Score -->
|
<!-- Couverture -->
|
||||||
<div class="flex items-center justify-between mb-3">
|
<img
|
||||||
<div class="flex items-center space-x-2">
|
v-if="match.thumbnailUrl"
|
||||||
<div
|
:src="match.thumbnailUrl"
|
||||||
class="w-3 h-3 rounded-full"
|
:alt="match.title"
|
||||||
:class="{
|
class="w-12 h-16 object-cover shrink-0"
|
||||||
'bg-blue-500': isSelected,
|
/>
|
||||||
'bg-gray-300': !isSelected
|
<div
|
||||||
}"
|
v-else
|
||||||
></div>
|
class="w-12 h-16 bg-gray-100 dark:bg-gray-700 shrink-0 flex items-center justify-center"
|
||||||
<span class="text-sm font-medium text-gray-700 dark:text-gray-300">Score: {{ match.matchScore }}</span>
|
|
||||||
</div>
|
|
||||||
<div v-if="isSelected" class="text-blue-600">
|
|
||||||
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
|
|
||||||
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Manga Thumbnail -->
|
|
||||||
<div class="flex space-x-3">
|
|
||||||
<div class="flex-shrink-0">
|
|
||||||
<img
|
|
||||||
v-if="match.thumbnailUrl"
|
|
||||||
:src="match.thumbnailUrl"
|
|
||||||
:alt="match.title"
|
|
||||||
class="w-16 h-20 object-cover rounded border"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
v-else
|
|
||||||
class="w-16 h-20 bg-gray-200 dark:bg-gray-700 rounded border dark:border-gray-600 flex items-center justify-center"
|
|
||||||
>
|
|
||||||
<svg class="w-8 h-8 text-gray-400 dark:text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Manga Info -->
|
|
||||||
<div class="flex-1 min-w-0">
|
|
||||||
<h4 class="text-sm font-medium text-gray-900 dark:text-gray-100 truncate" :title="match.title">
|
|
||||||
{{ match.title }}
|
|
||||||
</h4>
|
|
||||||
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1 truncate" :title="match.slug">
|
|
||||||
{{ match.slug }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<!-- Alternative Slugs -->
|
|
||||||
<div v-if="match.alternativeSlugs && match.alternativeSlugs.length > 0" class="mt-2">
|
|
||||||
<p class="text-xs text-gray-400 dark:text-gray-500">Autres titres:</p>
|
|
||||||
<div class="flex flex-wrap gap-1 mt-1">
|
|
||||||
<span
|
|
||||||
v-for="altSlug in match.alternativeSlugs.slice(0, 2)"
|
|
||||||
:key="altSlug"
|
|
||||||
class="text-xs bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 px-2 py-1 rounded"
|
|
||||||
>
|
>
|
||||||
{{ altSlug }}
|
<PhotoIcon class="w-6 h-6 text-gray-400" />
|
||||||
</span>
|
</div>
|
||||||
<span
|
|
||||||
v-if="match.alternativeSlugs.length > 2"
|
|
||||||
class="text-xs text-gray-400 dark:text-gray-500"
|
|
||||||
>
|
|
||||||
+{{ match.alternativeSlugs.length - 2 }} autres
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Score Bar -->
|
<!-- Infos -->
|
||||||
<div class="mt-3">
|
<div class="flex-1 min-w-0 flex flex-col justify-between py-0.5">
|
||||||
<div class="flex items-center justify-between text-xs text-gray-500 dark:text-gray-400 mb-1">
|
<p class="text-xs font-medium text-gray-900 dark:text-gray-100 line-clamp-3 leading-snug" :title="match.title">
|
||||||
<span>Correspondance</span>
|
{{ match.title }}
|
||||||
<span>{{ match.matchScore }}%</span>
|
</p>
|
||||||
</div>
|
<div class="flex items-center justify-between mt-1">
|
||||||
<div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
|
<span class="text-xs text-gray-400 dark:text-gray-500">{{ match.matchScore }}%</span>
|
||||||
<div
|
<CheckCircleIcon v-if="isSelected" class="w-4 h-4 text-green-500 shrink-0" />
|
||||||
class="h-2 rounded-full transition-all duration-300"
|
</div>
|
||||||
:class="{
|
</div>
|
||||||
'bg-blue-500': isSelected,
|
</div>
|
||||||
'bg-gray-400': !isSelected
|
|
||||||
}"
|
|
||||||
:style="{ width: match.matchScore + '%' }"
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { CheckCircleIcon, PhotoIcon } from '@heroicons/vue/24/outline';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
match: {
|
match: { type: Object, required: true },
|
||||||
type: Object,
|
isSelected: { type: Boolean, default: false },
|
||||||
required: true
|
|
||||||
},
|
|
||||||
isSelected: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['select-match']);
|
const emit = defineEmits(['select-match']);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ const badgeText = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const badgeClasses = computed(() => {
|
const badgeClasses = computed(() => {
|
||||||
const baseClasses = 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium';
|
const baseClasses = 'inline-flex items-center px-2.5 py-0.5 text-xs font-medium';
|
||||||
|
|
||||||
if (props.isImporting || props.isAnalyzing) {
|
if (props.isImporting || props.isAnalyzing) {
|
||||||
return `${baseClasses} bg-blue-100 dark:bg-blue-900/40 text-blue-800 dark:text-blue-300`;
|
return `${baseClasses} bg-green-100 dark:bg-green-900/40 text-green-800 dark:text-green-300`;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (props.status) {
|
switch (props.status) {
|
||||||
@@ -58,7 +58,7 @@ const badgeClasses = computed(() => {
|
|||||||
case 'analyzed':
|
case 'analyzed':
|
||||||
return `${baseClasses} bg-yellow-100 dark:bg-yellow-900/40 text-yellow-800 dark:text-yellow-300`;
|
return `${baseClasses} bg-yellow-100 dark:bg-yellow-900/40 text-yellow-800 dark:text-yellow-300`;
|
||||||
case 'importing':
|
case 'importing':
|
||||||
return `${baseClasses} bg-blue-100 dark:bg-blue-900/40 text-blue-800 dark:text-blue-300`;
|
return `${baseClasses} bg-green-100 dark:bg-green-900/40 text-green-800 dark:text-green-300`;
|
||||||
case 'imported':
|
case 'imported':
|
||||||
return `${baseClasses} bg-green-100 dark:bg-green-900/40 text-green-800 dark:text-green-300`;
|
return `${baseClasses} bg-green-100 dark:bg-green-900/40 text-green-800 dark:text-green-300`;
|
||||||
case 'error':
|
case 'error':
|
||||||
|
|||||||
@@ -1,115 +1,103 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="overflow-y-auto h-full"><div class="container mx-auto px-4 py-8">
|
<div class="flex flex-col h-full">
|
||||||
<!-- Header -->
|
<Toolbar :config="toolbarConfig" />
|
||||||
<div class="mb-8">
|
|
||||||
<h1 class="text-3xl font-bold text-gray-900 dark:text-gray-100 mb-2">Import de Bibliothèque</h1>
|
<div class="overflow-y-auto flex-1">
|
||||||
<p class="text-gray-600 dark:text-gray-400">
|
<div class="px-6 py-8">
|
||||||
Importez vos fichiers CBZ/CBR dans votre bibliothèque Mangarr
|
|
||||||
</p>
|
<!-- Zone de dépôt -->
|
||||||
</div>
|
<section v-if="!store.hasFiles" class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-4">Fichiers</h2>
|
||||||
|
<FileUpload
|
||||||
|
label="Importer des fichiers CBZ/CBR"
|
||||||
|
accept=".cbz,.cbr"
|
||||||
|
:multiple="true"
|
||||||
|
description="Formats CBZ ou CBR uniquement"
|
||||||
|
@files-selected="store.addFiles($event)"
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Fichiers en cours -->
|
||||||
|
<template v-if="store.hasFiles && !store.allFilesProcessed">
|
||||||
|
<section class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
|
<div class="flex items-center justify-between mb-3">
|
||||||
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider">
|
||||||
|
{{ store.totalFiles }} fichier(s)
|
||||||
|
</h2>
|
||||||
|
<span class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
{{ store.importedCount }}/{{ store.totalFiles }}
|
||||||
|
<span v-if="store.errorCount > 0" class="text-red-500 ml-1">· {{ store.errorCount }} erreur(s)</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="bg-gray-200 dark:bg-gray-700 h-1.5 mb-4">
|
||||||
|
<div
|
||||||
|
class="bg-green-600 h-1.5 transition-all duration-300"
|
||||||
|
:style="{ width: store.progressPercentage + '%' }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="divide-y divide-gray-100 dark:divide-gray-700/50">
|
||||||
|
<FileImportCard
|
||||||
|
v-for="file in store.files"
|
||||||
|
:key="file.id"
|
||||||
|
:file="file"
|
||||||
|
:is-analyzing="store.analyzingFiles.has(file.id)"
|
||||||
|
:is-importing="store.importingFiles.has(file.id)"
|
||||||
|
@manga-selected="(manga) => store.setFileManga(file.id, manga)"
|
||||||
|
@chapter-number-selected="(n) => store.setFileChapterNumber(file.id, n)"
|
||||||
|
@volume-number-selected="(n) => store.setFileVolumeNumber(file.id, n)"
|
||||||
|
@import-file="() => importSingleFile(file.id)"
|
||||||
|
@retry-file="() => retryFile(file.id)"
|
||||||
|
@remove-file="() => store.removeFile(file.id)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Résultats -->
|
||||||
|
<ImportResults v-if="store.allFilesProcessed" />
|
||||||
|
|
||||||
<!-- Progress Bar (if files are being processed) -->
|
|
||||||
<div v-if="store.hasFiles && !store.allFilesProcessed" class="mb-8">
|
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm p-6">
|
|
||||||
<div class="flex items-center justify-between mb-2">
|
|
||||||
<span class="text-sm font-medium text-gray-700 dark:text-gray-300">Progression</span>
|
|
||||||
<span class="text-sm text-gray-500 dark:text-gray-400">{{ store.progressPercentage }}%</span>
|
|
||||||
</div>
|
|
||||||
<div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
|
|
||||||
<div
|
|
||||||
class="bg-blue-600 h-2 rounded-full transition-all duration-300"
|
|
||||||
:style="{ width: store.progressPercentage + '%' }"
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-between text-xs text-gray-500 dark:text-gray-400 mt-2">
|
|
||||||
<span>{{ store.importedCount }} importés</span>
|
|
||||||
<span>{{ store.errorCount }} erreurs</span>
|
|
||||||
<span>{{ store.totalFiles }} total</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<!-- File Upload Zone -->
|
|
||||||
<div v-if="!store.hasFiles || store.allFilesProcessed" class="mb-8">
|
|
||||||
<FileUpload
|
|
||||||
label="Importer des fichiers CBZ/CBR"
|
|
||||||
accept=".cbz,.cbr"
|
|
||||||
:multiple="true"
|
|
||||||
description="Formats CBZ ou CBR uniquement"
|
|
||||||
@files-selected="handleFilesSelected"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Files List -->
|
|
||||||
<div v-if="store.hasFiles" class="space-y-6">
|
|
||||||
<!-- Action Buttons -->
|
|
||||||
<div class="flex flex-wrap gap-4 mb-6">
|
|
||||||
<button
|
|
||||||
v-if="store.hasReadyFiles"
|
|
||||||
@click="importAllFiles"
|
|
||||||
:disabled="store.isLoading"
|
|
||||||
class="bg-green-600 hover:bg-green-700 disabled:bg-gray-400 text-white px-4 py-2 rounded-md font-medium"
|
|
||||||
>
|
|
||||||
<LoadingSpinner v-if="store.isLoading" class="w-4 h-4 mr-2" />
|
|
||||||
Importer tous les fichiers prêts ({{ store.readyCount }})
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
v-if="store.analyzedFiles.length > 0"
|
|
||||||
@click="autoSelectMatches"
|
|
||||||
class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md font-medium"
|
|
||||||
>
|
|
||||||
Sélection automatique
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
@click="clearAllFiles"
|
|
||||||
class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-md font-medium"
|
|
||||||
>
|
|
||||||
Effacer tout
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Files Grid -->
|
|
||||||
<div class="grid gap-6">
|
|
||||||
<FileImportCard
|
|
||||||
v-for="file in store.files"
|
|
||||||
:key="file.id"
|
|
||||||
:file="file"
|
|
||||||
:is-analyzing="store.analyzingFiles.has(file.id)"
|
|
||||||
:is-importing="store.importingFiles.has(file.id)"
|
|
||||||
@manga-selected="(manga) => store.setFileManga(file.id, manga)"
|
|
||||||
@chapter-number-selected="(chapterNumber) => store.setFileChapterNumber(file.id, chapterNumber)"
|
|
||||||
@volume-number-selected="(volumeNumber) => store.setFileVolumeNumber(file.id, volumeNumber)"
|
|
||||||
@import-file="() => importSingleFile(file.id)"
|
|
||||||
@retry-file="() => retryFile(file.id)"
|
|
||||||
@remove-file="() => store.removeFile(file.id)"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Results Summary (when all files are processed) -->
|
|
||||||
<div v-if="store.allFilesProcessed" class="mt-8">
|
|
||||||
<ImportResults />
|
|
||||||
</div>
|
|
||||||
</div></div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onUnmounted } from 'vue';
|
import { ArrowUpTrayIcon, SparklesIcon, TrashIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import { computed, onUnmounted } from 'vue';
|
||||||
import FileUpload from '../../../../shared/components/ui/FileUpload.vue';
|
import FileUpload from '../../../../shared/components/ui/FileUpload.vue';
|
||||||
import LoadingSpinner from '../../../../shared/components/ui/LoadingSpinner.vue';
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
||||||
import { useNewImportStore } from '../../application/store/newImportStore';
|
import { useNewImportStore } from '../../application/store/newImportStore';
|
||||||
import FileImportCard from '../components/FileImportCard.vue';
|
import FileImportCard from '../components/FileImportCard.vue';
|
||||||
import ImportResults from '../components/ImportResults.vue';
|
import ImportResults from '../components/ImportResults.vue';
|
||||||
|
|
||||||
const store = useNewImportStore();
|
const store = useNewImportStore();
|
||||||
|
|
||||||
// === EVENT HANDLERS ===
|
const toolbarConfig = computed(() => ({
|
||||||
|
leftSection: [
|
||||||
const handleFilesSelected = (files) => {
|
{ type: 'label', text: 'Import de bibliothèque', class: 'text-sm font-medium' },
|
||||||
store.addFiles(files);
|
],
|
||||||
};
|
rightSection: [
|
||||||
|
...(store.analyzedFiles.length > 0 ? [{
|
||||||
|
type: 'button',
|
||||||
|
icon: SparklesIcon,
|
||||||
|
label: 'Sélection auto',
|
||||||
|
onClick: () => store.autoSelectBestMatches(),
|
||||||
|
}] : []),
|
||||||
|
...(store.hasReadyFiles ? [{
|
||||||
|
type: 'button',
|
||||||
|
icon: ArrowUpTrayIcon,
|
||||||
|
label: `Importer (${store.readyCount})`,
|
||||||
|
onClick: importAllFiles,
|
||||||
|
disabled: store.isLoading,
|
||||||
|
}] : []),
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
icon: TrashIcon,
|
||||||
|
label: 'Effacer',
|
||||||
|
onClick: () => store.clearFiles(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
const importAllFiles = async () => {
|
const importAllFiles = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -135,19 +123,6 @@ const retryFile = async (fileId) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const autoSelectMatches = () => {
|
|
||||||
store.autoSelectBestMatches();
|
|
||||||
};
|
|
||||||
|
|
||||||
const clearAllFiles = () => {
|
|
||||||
if (confirm('Êtes-vous sûr de vouloir effacer tous les fichiers ?')) {
|
|
||||||
store.clearFiles();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// === LIFECYCLE ===
|
|
||||||
|
|
||||||
// Reset state when component unmounts
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
store.resetGlobalState();
|
store.resetGlobalState();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -40,7 +40,12 @@ export const useMangaStore = defineStore('manga', {
|
|||||||
|
|
||||||
// --- Add Manga State ---
|
// --- Add Manga State ---
|
||||||
addingManga: false,
|
addingManga: false,
|
||||||
addMangaError: null
|
addMangaError: null,
|
||||||
|
|
||||||
|
// --- Discover State ---
|
||||||
|
discoverResults: [],
|
||||||
|
loadingDiscover: false,
|
||||||
|
discoverError: null
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
@@ -170,6 +175,25 @@ export const useMangaStore = defineStore('manga', {
|
|||||||
this.loadingSearch = false;
|
this.loadingSearch = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// --- Discover Actions ---
|
||||||
|
async loadDiscoverRecommendations() {
|
||||||
|
if (this.loadingDiscover) return;
|
||||||
|
|
||||||
|
this.loadingDiscover = true;
|
||||||
|
this.discoverError = null;
|
||||||
|
this.discoverResults = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await mangaRepository.discoverManga();
|
||||||
|
this.discoverResults = data.items || [];
|
||||||
|
} catch (error) {
|
||||||
|
this.discoverError = error.message;
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this.loadingDiscover = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// --- Add Manga Actions ---
|
// --- Add Manga Actions ---
|
||||||
async createFromMangaDex(externalId) {
|
async createFromMangaDex(externalId) {
|
||||||
if (this.addingManga) return;
|
if (this.addingManga) return;
|
||||||
|
|||||||
@@ -104,6 +104,17 @@ export class ApiMangaRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async discoverManga() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/manga-discover');
|
||||||
|
if (!response.ok) throw new Error('Failed to fetch discover recommendations');
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('API Error:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async createFromMangaDex(externalId) {
|
async createFromMangaDex(externalId) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/mangas/create-from-mangadex', {
|
const response = await fetch('/api/mangas/create-from-mangadex', {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<tr class="border-t dark:border-gray-700 hover:bg-green-100 dark:hover:bg-green-900/20">
|
<tr class="border-t dark:border-gray-700 hover:bg-green-100 dark:hover:bg-green-900/20">
|
||||||
<td class="px-4 py-2 text-gray-900 dark:text-gray-100" :class="{ 'text-green-500 dark:text-green-400': chapter.isAvailable }">
|
<td class="px-4 py-2 text-gray-900 dark:text-gray-100" :class="{ 'text-green-500 dark:text-green-400': chapter.isAvailable }">
|
||||||
{{ String(chapter.number).padStart(2, '0') }}
|
<template v-if="chapter.isVolumeGroup">{{ chapter.volumeChaptersRange }}</template>
|
||||||
|
<template v-else>{{ String(chapter.number).padStart(2, '0') }}</template>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-2 w-full text-left text-gray-900 dark:text-gray-100">
|
<td class="px-4 py-2 w-full text-left text-gray-900 dark:text-gray-100">
|
||||||
<router-link
|
<router-link
|
||||||
@@ -13,9 +14,17 @@
|
|||||||
chapterId: chapter.id
|
chapterId: chapter.id
|
||||||
}
|
}
|
||||||
}">
|
}">
|
||||||
{{ chapter.title || 'Sans titre' }}
|
<template v-if="chapter.isVolumeGroup">
|
||||||
|
{{ chapter.volumeChapterCount > 1 ? 'Chapitres ' : 'Chapitre ' }}{{ chapter.volumeChaptersRange }}
|
||||||
|
</template>
|
||||||
|
<template v-else>{{ chapter.title || 'Sans titre' }}</template>
|
||||||
</router-link>
|
</router-link>
|
||||||
<span v-else class="text-gray-500 dark:text-gray-400">{{ chapter.title || 'Sans titre' }}</span>
|
<span v-else class="text-gray-500 dark:text-gray-400">
|
||||||
|
<template v-if="chapter.isVolumeGroup">
|
||||||
|
{{ chapter.volumeChapterCount > 1 ? 'Chapitres ' : 'Chapitre ' }}{{ chapter.volumeChaptersRange }}
|
||||||
|
</template>
|
||||||
|
<template v-else>{{ chapter.title || 'Sans titre' }}</template>
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-2 flex justify-end gap-2">
|
<td class="px-4 py-2 flex justify-end gap-2">
|
||||||
<button v-if="!chapter.isAvailable" @click="handleSearch" :class="buttonClass">
|
<button v-if="!chapter.isAvailable" @click="handleSearch" :class="buttonClass">
|
||||||
|
|||||||
@@ -1,172 +1,234 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="overflow-y-auto h-full">
|
<div class="flex flex-col h-full">
|
||||||
<div class="container mx-auto px-4 py-8">
|
<Toolbar :config="toolbarConfig" />
|
||||||
<!-- Barre de recherche -->
|
|
||||||
<div class="mb-8">
|
|
||||||
<div class="flex gap-4">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
v-model="searchQuery"
|
|
||||||
@keyup.enter="performSearch"
|
|
||||||
placeholder="Rechercher un manga..."
|
|
||||||
class="flex-1 px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500" />
|
|
||||||
<button
|
|
||||||
@click="performSearch"
|
|
||||||
class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
|
|
||||||
Rechercher
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- État de chargement -->
|
<div class="overflow-y-auto flex-1">
|
||||||
<div v-if="loading" class="text-center py-8">
|
<div class="px-6 py-8">
|
||||||
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"></div>
|
|
||||||
<p class="mt-4 text-gray-600 dark:text-gray-400">Recherche en cours...</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Message d'erreur -->
|
<!-- Recherche -->
|
||||||
<div v-if="error" class="bg-red-100 dark:bg-red-900/20 border border-red-400 dark:border-red-700 text-red-700 dark:text-red-400 px-4 py-3 rounded relative mb-6">
|
<section class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
{{ error }}
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-4">Recherche</h2>
|
||||||
</div>
|
<input
|
||||||
|
type="text"
|
||||||
|
v-model="searchQuery"
|
||||||
|
@keyup.enter="performSearch"
|
||||||
|
placeholder="Rechercher un manga..."
|
||||||
|
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500" />
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- Résultats de recherche -->
|
<!-- État de chargement -->
|
||||||
<div v-if="searchResults.length > 0" class="border-t border-gray-200 dark:border-gray-700">
|
<section v-if="loading" class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
<div
|
<div class="flex items-center gap-3 text-gray-600 dark:text-gray-400">
|
||||||
v-for="manga in searchResults"
|
<div class="animate-spin rounded-full h-5 w-5 border-b-2 border-green-600"></div>
|
||||||
:key="manga.externalId"
|
<span class="text-sm">Recherche en cours...</span>
|
||||||
class="flex items-center gap-4 px-4 py-3 hover:bg-gray-50 dark:hover:bg-gray-700/40 transition-colors border-b border-gray-100 dark:border-gray-700 cursor-pointer"
|
</div>
|
||||||
@click="openMangaModal(manga)">
|
</section>
|
||||||
<img
|
|
||||||
:src="manga.thumbnailUrl || manga.imageUrl || '/placeholder-cover.png'"
|
|
||||||
alt=""
|
|
||||||
class="h-36 w-24 object-cover flex-shrink-0 self-start"
|
|
||||||
referrerpolicy="no-referrer" />
|
|
||||||
<div class="flex-1 min-w-0">
|
|
||||||
<p class="text-xl font-semibold text-gray-900 dark:text-gray-100">{{ manga.title }}</p>
|
|
||||||
<p v-if="manga.description" class="text-sm text-gray-600 dark:text-gray-300 mt-2 line-clamp-4">{{ manga.description }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p v-else-if="!loading && searchQuery" class="text-center text-gray-600 dark:text-gray-400">Aucun résultat trouvé</p>
|
|
||||||
|
|
||||||
<!-- Modal de confirmation -->
|
<!-- Message d'erreur -->
|
||||||
<Dialog :open="isModalOpen" @close="closeModal" class="relative z-50">
|
<section v-if="error" class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
<div class="fixed inset-0 bg-gray-500 dark:bg-gray-900 bg-opacity-75 dark:bg-opacity-80 transition-opacity" aria-hidden="true" />
|
<p class="text-sm text-red-600 dark:text-red-400">{{ error }}</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
<div class="fixed inset-0 flex items-center justify-center p-4">
|
<!-- Résultats -->
|
||||||
<DialogPanel class="w-full max-w-lg bg-white dark:bg-gray-800 rounded-xl shadow-xl p-6">
|
<section v-if="searchResults.length > 0" class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
<DialogTitle class="text-lg mb-4 text-gray-900 dark:text-gray-100"> Ajouter à la bibliothèque </DialogTitle>
|
<div class="flex items-center justify-between mb-4">
|
||||||
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider">Résultats</h2>
|
||||||
<div v-if="selectedManga">
|
<span class="text-xs text-gray-500 dark:text-gray-400">{{ searchResults.length }} manga(s)</span>
|
||||||
<div class="flex gap-4">
|
</div>
|
||||||
|
<div class="divide-y divide-gray-100 dark:divide-gray-700/50">
|
||||||
|
<div
|
||||||
|
v-for="manga in searchResults"
|
||||||
|
:key="manga.externalId"
|
||||||
|
class="flex items-start gap-4 py-3 hover:bg-gray-50 dark:hover:bg-gray-700/40 transition-colors cursor-pointer px-2"
|
||||||
|
@click="openMangaModal(manga)">
|
||||||
<img
|
<img
|
||||||
:src="selectedManga.imageUrl || '/placeholder-cover.png'"
|
:src="manga.thumbnailUrl || manga.imageUrl || '/placeholder-cover.png'"
|
||||||
:alt="selectedManga.title"
|
alt=""
|
||||||
class="h-48 w-32 object-cover" />
|
class="h-36 w-24 object-cover flex-shrink-0"
|
||||||
|
referrerpolicy="no-referrer" />
|
||||||
<div class="flex-1 min-w-0">
|
<div class="flex-1 min-w-0">
|
||||||
<h4 class="text-lg text-gray-900 dark:text-gray-100">{{ selectedManga.title }}</h4>
|
<p class="text-sm font-semibold text-gray-900 dark:text-gray-100">{{ manga.title }}</p>
|
||||||
<p class="mt-2 text-gray-700 dark:text-gray-300">
|
<p v-if="manga.description" class="text-sm text-gray-600 dark:text-gray-300 mt-2 line-clamp-4">{{ manga.description }}</p>
|
||||||
{{ truncatedDescription }}
|
</div>
|
||||||
</p>
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Aucun résultat -->
|
||||||
|
<section v-else-if="hasSearched && !loading" class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
|
<p class="text-sm text-gray-500 dark:text-gray-400 text-center">Aucun résultat trouvé</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal de détail -->
|
||||||
|
<Dialog :open="isModalOpen" @close="closeModal" class="relative z-50">
|
||||||
|
<div class="fixed inset-0 bg-gray-900/70 dark:bg-gray-900/80 transition-opacity" aria-hidden="true" />
|
||||||
|
<div class="fixed inset-0 flex items-center justify-center p-4">
|
||||||
|
<DialogPanel v-if="selectedManga" class="w-full max-w-2xl bg-white dark:bg-gray-800 shadow-xl overflow-hidden flex flex-col max-h-[90vh]">
|
||||||
|
|
||||||
|
<!-- En-tête avec couverture -->
|
||||||
|
<div class="flex gap-0 border-b border-gray-200 dark:border-gray-700">
|
||||||
|
<img
|
||||||
|
:src="selectedManga.imageUrl || selectedManga.thumbnailUrl || '/placeholder-cover.png'"
|
||||||
|
:alt="selectedManga.title"
|
||||||
|
class="h-64 w-44 object-cover flex-shrink-0"
|
||||||
|
referrerpolicy="no-referrer" />
|
||||||
|
<div class="flex-1 min-w-0 p-6 flex flex-col justify-between">
|
||||||
|
<div>
|
||||||
|
<DialogTitle class="text-base font-semibold text-gray-900 dark:text-gray-100 leading-snug">
|
||||||
|
{{ selectedManga.title }}
|
||||||
|
</DialogTitle>
|
||||||
|
<div class="mt-3 space-y-1.5">
|
||||||
|
<p v-if="selectedManga.author" class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">Auteur</span>
|
||||||
|
<span class="ml-2 text-gray-700 dark:text-gray-200">{{ selectedManga.author }}</span>
|
||||||
|
</p>
|
||||||
|
<p v-if="selectedManga.publicationYear" class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">Publication</span>
|
||||||
|
<span class="ml-2 text-gray-700 dark:text-gray-200">{{ selectedManga.publicationYear }}</span>
|
||||||
|
</p>
|
||||||
|
<p v-if="selectedManga.status" class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">Statut</span>
|
||||||
|
<span class="ml-2 text-gray-700 dark:text-gray-200">{{ selectedManga.status }}</span>
|
||||||
|
</p>
|
||||||
|
<p v-if="selectedManga.rating" class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">Note</span>
|
||||||
|
<span class="ml-2 text-gray-700 dark:text-gray-200">{{ selectedManga.rating.toFixed(2) }} / 10</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="selectedManga.genres?.length" class="flex flex-wrap gap-1.5 mt-4">
|
||||||
|
<span
|
||||||
|
v-for="genre in selectedManga.genres"
|
||||||
|
:key="genre"
|
||||||
|
class="text-xs px-2 py-0.5 bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300">
|
||||||
|
{{ genre }}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-6 flex justify-end gap-3">
|
<!-- Description -->
|
||||||
|
<div class="px-6 py-4 overflow-y-auto flex-1">
|
||||||
|
<h3 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-2">Description</h3>
|
||||||
|
<p v-if="selectedManga.description" class="text-sm text-gray-600 dark:text-gray-300 leading-relaxed">
|
||||||
|
{{ selectedManga.description }}
|
||||||
|
</p>
|
||||||
|
<p v-else class="text-sm text-gray-400 dark:text-gray-500 italic">Aucune description disponible.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Actions -->
|
||||||
|
<div class="px-6 py-4 border-t border-gray-200 dark:border-gray-700 flex justify-end gap-3">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@click="closeModal"
|
@click="closeModal"
|
||||||
class="px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 dark:bg-gray-800">
|
class="text-sm text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors px-4 py-2">
|
||||||
Annuler
|
Annuler
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@click="addManga"
|
@click="addManga"
|
||||||
:disabled="adding"
|
:disabled="adding"
|
||||||
class="px-4 py-2 rounded-lg bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed inline-flex items-center">
|
class="bg-green-600 hover:bg-green-700 disabled:bg-gray-400 disabled:cursor-not-allowed text-white px-4 py-2 font-medium transition-colors inline-flex items-center gap-2">
|
||||||
<span v-if="adding" class="mr-2">
|
<ArrowPathIcon v-if="adding" class="h-4 w-4 animate-spin" />
|
||||||
<ArrowPathIcon class="h-5 w-5 animate-spin" />
|
{{ adding ? 'Ajout en cours...' : 'Ajouter à la bibliothèque' }}
|
||||||
</span>
|
|
||||||
{{ adding ? 'Ajout en cours...' : 'Ajouter' }}
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</DialogPanel>
|
</DialogPanel>
|
||||||
</div>
|
</div>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { Dialog, DialogPanel, DialogTitle } from '@headlessui/vue';
|
import { Dialog, DialogPanel, DialogTitle } from '@headlessui/vue';
|
||||||
import { ArrowPathIcon } from '@heroicons/vue/24/solid';
|
import { ArrowPathIcon, MagnifyingGlassIcon } from '@heroicons/vue/24/outline';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
||||||
import { useMangaStore } from '../../application/store/mangaStore';
|
import { useMangaStore } from '../../application/store/mangaStore';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const mangaStore = useMangaStore();
|
const mangaStore = useMangaStore();
|
||||||
|
|
||||||
const searchQuery = ref('');
|
const searchQuery = ref('');
|
||||||
const isModalOpen = ref(false);
|
const hasSearched = ref(false);
|
||||||
const selectedManga = ref(null);
|
const isModalOpen = ref(false);
|
||||||
|
const selectedManga = ref(null);
|
||||||
|
|
||||||
// Récupération des états du store
|
const { searchResults, loadingSearch: loading, searchError: error, addingManga: adding } = storeToRefs(mangaStore);
|
||||||
const { searchResults, loadingSearch: loading, searchError: error, addingManga: adding } = storeToRefs(mangaStore);
|
|
||||||
|
|
||||||
const truncatedDescription = computed(() => {
|
const toolbarConfig = computed(() => ({
|
||||||
if (!selectedManga.value?.description) return '';
|
leftSection: [
|
||||||
return selectedManga.value.description.length > 500
|
{ type: 'label', text: 'Ajouter un manga', class: 'text-sm font-medium' },
|
||||||
? selectedManga.value.description.slice(0, 500) + '...'
|
],
|
||||||
: selectedManga.value.description;
|
rightSection: [
|
||||||
});
|
{
|
||||||
|
type: 'button',
|
||||||
|
icon: MagnifyingGlassIcon,
|
||||||
|
label: 'Rechercher',
|
||||||
|
onClick: performSearch,
|
||||||
|
disabled: !searchQuery.value.trim() || loading.value,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
// Effectuer la recherche au chargement si un paramètre q est présent
|
let debounceTimer = null;
|
||||||
onMounted(() => {
|
watch(searchQuery, newVal => {
|
||||||
const queryParam = route.query.q;
|
clearTimeout(debounceTimer);
|
||||||
if (queryParam) {
|
if (newVal.trim().length > 3) {
|
||||||
searchQuery.value = queryParam;
|
debounceTimer = setTimeout(performSearch, 500);
|
||||||
performSearch();
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Nettoyer la recherche et les résultats lors du démontage du composant
|
onMounted(() => {
|
||||||
onBeforeUnmount(() => {
|
const queryParam = route.query.q;
|
||||||
searchQuery.value = '';
|
if (queryParam) {
|
||||||
mangaStore.clearSearchResults();
|
searchQuery.value = queryParam;
|
||||||
});
|
performSearch();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const performSearch = async () => {
|
onBeforeUnmount(() => {
|
||||||
if (!searchQuery.value.trim()) return;
|
clearTimeout(debounceTimer);
|
||||||
try {
|
searchQuery.value = '';
|
||||||
await mangaStore.searchMangaDex(searchQuery.value);
|
mangaStore.clearSearchResults();
|
||||||
} catch (e) {
|
});
|
||||||
console.error('Erreur de recherche:', e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const openMangaModal = manga => {
|
const performSearch = async () => {
|
||||||
selectedManga.value = manga;
|
if (!searchQuery.value.trim()) return;
|
||||||
isModalOpen.value = true;
|
try {
|
||||||
};
|
await mangaStore.searchMangaDex(searchQuery.value);
|
||||||
|
hasSearched.value = true;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Erreur de recherche:', e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const closeModal = () => {
|
const openMangaModal = manga => {
|
||||||
isModalOpen.value = false;
|
selectedManga.value = manga;
|
||||||
selectedManga.value = null;
|
isModalOpen.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const addManga = async () => {
|
const closeModal = () => {
|
||||||
if (!selectedManga.value) return;
|
isModalOpen.value = false;
|
||||||
|
selectedManga.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
const addManga = async () => {
|
||||||
await mangaStore.createFromMangaDex(selectedManga.value.externalId);
|
if (!selectedManga.value) return;
|
||||||
router.push('/manga');
|
try {
|
||||||
} catch (e) {
|
await mangaStore.createFromMangaDex(selectedManga.value.externalId);
|
||||||
console.error("Erreur d'ajout:", e);
|
router.push('/manga');
|
||||||
} finally {
|
} catch (e) {
|
||||||
closeModal();
|
console.error("Erreur d'ajout:", e);
|
||||||
}
|
} finally {
|
||||||
};
|
closeModal();
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
192
assets/vue/app/domain/manga/presentation/pages/DiscoverPage.vue
Normal file
192
assets/vue/app/domain/manga/presentation/pages/DiscoverPage.vue
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex flex-col h-full">
|
||||||
|
<Toolbar :config="toolbarConfig" />
|
||||||
|
|
||||||
|
<div class="overflow-y-auto flex-1">
|
||||||
|
<div class="px-6 py-8">
|
||||||
|
|
||||||
|
<!-- État de chargement -->
|
||||||
|
<section v-if="loading" class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
|
<div class="flex items-center gap-3 text-gray-600 dark:text-gray-400">
|
||||||
|
<div class="animate-spin rounded-full h-5 w-5 border-b-2 border-green-600"></div>
|
||||||
|
<span class="text-sm">Chargement des recommandations...</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Message d'erreur -->
|
||||||
|
<section v-else-if="error" class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
|
<p class="text-sm text-red-600 dark:text-red-400">{{ error }}</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Résultats -->
|
||||||
|
<section v-else-if="discoverResults.length > 0" class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
|
<div class="flex items-center justify-between mb-4">
|
||||||
|
<h2 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider">Recommandations</h2>
|
||||||
|
<span class="text-xs text-gray-500 dark:text-gray-400">{{ discoverResults.length }} manga(s)</span>
|
||||||
|
</div>
|
||||||
|
<div class="divide-y divide-gray-100 dark:divide-gray-700/50">
|
||||||
|
<div
|
||||||
|
v-for="manga in discoverResults"
|
||||||
|
:key="manga.externalId"
|
||||||
|
class="flex items-start gap-4 py-3 hover:bg-gray-50 dark:hover:bg-gray-700/40 transition-colors cursor-pointer px-2"
|
||||||
|
@click="openMangaModal(manga)">
|
||||||
|
<img
|
||||||
|
:src="manga.thumbnailUrl || manga.imageUrl || '/placeholder-cover.png'"
|
||||||
|
alt=""
|
||||||
|
class="h-36 w-24 object-cover flex-shrink-0"
|
||||||
|
referrerpolicy="no-referrer" />
|
||||||
|
<div class="flex-1 min-w-0">
|
||||||
|
<p class="text-sm font-semibold text-gray-900 dark:text-gray-100">{{ manga.title }}</p>
|
||||||
|
<p v-if="manga.description" class="text-sm text-gray-600 dark:text-gray-300 mt-2 line-clamp-4">{{ manga.description }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Collection locale vide -->
|
||||||
|
<section v-else-if="!loading" class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
|
<p class="text-sm text-gray-500 dark:text-gray-400 text-center">Ajoutez des manga pour obtenir des recommandations.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal de détail -->
|
||||||
|
<Dialog :open="isModalOpen" @close="closeModal" class="relative z-50">
|
||||||
|
<div class="fixed inset-0 bg-gray-900/70 dark:bg-gray-900/80 transition-opacity" aria-hidden="true" />
|
||||||
|
<div class="fixed inset-0 flex items-center justify-center p-4">
|
||||||
|
<DialogPanel v-if="selectedManga" class="w-full max-w-2xl bg-white dark:bg-gray-800 shadow-xl overflow-hidden flex flex-col max-h-[90vh]">
|
||||||
|
|
||||||
|
<!-- En-tête avec couverture -->
|
||||||
|
<div class="flex gap-0 border-b border-gray-200 dark:border-gray-700">
|
||||||
|
<img
|
||||||
|
:src="selectedManga.imageUrl || selectedManga.thumbnailUrl || '/placeholder-cover.png'"
|
||||||
|
:alt="selectedManga.title"
|
||||||
|
class="h-64 w-44 object-cover flex-shrink-0"
|
||||||
|
referrerpolicy="no-referrer" />
|
||||||
|
<div class="flex-1 min-w-0 p-6 flex flex-col justify-between">
|
||||||
|
<div>
|
||||||
|
<DialogTitle class="text-base font-semibold text-gray-900 dark:text-gray-100 leading-snug">
|
||||||
|
{{ selectedManga.title }}
|
||||||
|
</DialogTitle>
|
||||||
|
<div class="mt-3 space-y-1.5">
|
||||||
|
<p v-if="selectedManga.author" class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">Auteur</span>
|
||||||
|
<span class="ml-2 text-gray-700 dark:text-gray-200">{{ selectedManga.author }}</span>
|
||||||
|
</p>
|
||||||
|
<p v-if="selectedManga.publicationYear" class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">Publication</span>
|
||||||
|
<span class="ml-2 text-gray-700 dark:text-gray-200">{{ selectedManga.publicationYear }}</span>
|
||||||
|
</p>
|
||||||
|
<p v-if="selectedManga.status" class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">Statut</span>
|
||||||
|
<span class="ml-2 text-gray-700 dark:text-gray-200">{{ selectedManga.status }}</span>
|
||||||
|
</p>
|
||||||
|
<p v-if="selectedManga.rating" class="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">Note</span>
|
||||||
|
<span class="ml-2 text-gray-700 dark:text-gray-200">{{ selectedManga.rating.toFixed(2) }} / 10</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="selectedManga.genres?.length" class="flex flex-wrap gap-1.5 mt-4">
|
||||||
|
<span
|
||||||
|
v-for="genre in selectedManga.genres"
|
||||||
|
:key="genre"
|
||||||
|
class="text-xs px-2 py-0.5 bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300">
|
||||||
|
{{ genre }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Description -->
|
||||||
|
<div class="px-6 py-4 overflow-y-auto flex-1">
|
||||||
|
<h3 class="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-2">Description</h3>
|
||||||
|
<p v-if="selectedManga.description" class="text-sm text-gray-600 dark:text-gray-300 leading-relaxed">
|
||||||
|
{{ selectedManga.description }}
|
||||||
|
</p>
|
||||||
|
<p v-else class="text-sm text-gray-400 dark:text-gray-500 italic">Aucune description disponible.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Actions -->
|
||||||
|
<div class="px-6 py-4 border-t border-gray-200 dark:border-gray-700 flex justify-end gap-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
@click="closeModal"
|
||||||
|
class="text-sm text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors px-4 py-2">
|
||||||
|
Annuler
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
@click="addManga"
|
||||||
|
:disabled="adding"
|
||||||
|
class="bg-green-600 hover:bg-green-700 disabled:bg-gray-400 disabled:cursor-not-allowed text-white px-4 py-2 font-medium transition-colors inline-flex items-center gap-2">
|
||||||
|
<ArrowPathIcon v-if="adding" class="h-4 w-4 animate-spin" />
|
||||||
|
{{ adding ? 'Ajout en cours...' : 'Ajouter à la bibliothèque' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</DialogPanel>
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { Dialog, DialogPanel, DialogTitle } from '@headlessui/vue';
|
||||||
|
import { ArrowPathIcon, ArrowPathRoundedSquareIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
||||||
|
import { useMangaStore } from '../../application/store/mangaStore';
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const mangaStore = useMangaStore();
|
||||||
|
|
||||||
|
const isModalOpen = ref(false);
|
||||||
|
const selectedManga = ref(null);
|
||||||
|
|
||||||
|
const { discoverResults, loadingDiscover: loading, discoverError: error, addingManga: adding } = storeToRefs(mangaStore);
|
||||||
|
|
||||||
|
const toolbarConfig = computed(() => ({
|
||||||
|
leftSection: [
|
||||||
|
{ type: 'label', text: 'Découvrir', class: 'text-sm font-medium' },
|
||||||
|
],
|
||||||
|
rightSection: [
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
icon: ArrowPathRoundedSquareIcon,
|
||||||
|
label: 'Actualiser',
|
||||||
|
onClick: () => mangaStore.loadDiscoverRecommendations(),
|
||||||
|
disabled: loading.value,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
mangaStore.loadDiscoverRecommendations();
|
||||||
|
});
|
||||||
|
|
||||||
|
const openMangaModal = manga => {
|
||||||
|
selectedManga.value = manga;
|
||||||
|
isModalOpen.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeModal = () => {
|
||||||
|
isModalOpen.value = false;
|
||||||
|
selectedManga.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const addManga = async () => {
|
||||||
|
if (!selectedManga.value) return;
|
||||||
|
try {
|
||||||
|
await mangaStore.createFromMangaDex(selectedManga.value.externalId);
|
||||||
|
router.push('/manga');
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Erreur d'ajout:", e);
|
||||||
|
} finally {
|
||||||
|
closeModal();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -1,15 +1,26 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="infinite-reader" ref="containerRef">
|
<div class="infinite-reader" ref="containerRef">
|
||||||
<div v-for="(page, index) in pages" :key="index" class="page-wrapper" :data-page-index="index">
|
<div v-for="(page, index) in pages" :key="index"
|
||||||
<ReaderPage
|
class="page-wrapper" :data-page-index="index">
|
||||||
v-if="isPageInWindow(index) && page?.url"
|
|
||||||
|
<!-- Pas d'URL : spinner de chargement -->
|
||||||
|
<div v-if="!page?.url" class="loading">
|
||||||
|
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Hors de la zone de rendu : placeholder dimensionné -->
|
||||||
|
<div v-else-if="!mountedPageIndices.has(index)"
|
||||||
|
class="page-placeholder"
|
||||||
|
:style="{ height: getPlaceholderHeight(page) + 'px' }" />
|
||||||
|
|
||||||
|
<!-- Dans la zone : composant complet -->
|
||||||
|
<ReaderPage v-else
|
||||||
:page-data="page"
|
:page-data="page"
|
||||||
:page-number="index + 1"
|
:page-number="index + 1"
|
||||||
:zoom="zoom"
|
:zoom="zoom"
|
||||||
:double-page-mode="doublePageMode"
|
:double-page-mode="doublePageMode"
|
||||||
loading="eager"
|
:window-width="windowWidth"
|
||||||
/>
|
loading="lazy" />
|
||||||
<div v-else class="page-placeholder" :style="getPlaceholderStyle(page)" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Bouton flottant pour revenir en haut -->
|
<!-- Bouton flottant pour revenir en haut -->
|
||||||
@@ -38,29 +49,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
|
import { nextTick, onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
||||||
import { useHeaderStore } from '../../../../shared/stores/headerStore';
|
import { useHeaderStore } from '../../../../shared/stores/headerStore';
|
||||||
import ReaderPage from './ReaderPage.vue';
|
import ReaderPage from './ReaderPage.vue';
|
||||||
|
|
||||||
const WINDOW_SIZE = 3;
|
|
||||||
const currentVisibleIndex = ref(0); // initialisé via prop initialPage dans onMounted
|
|
||||||
|
|
||||||
const isPageInWindow = (index) => Math.abs(index - currentVisibleIndex.value) <= WINDOW_SIZE;
|
|
||||||
|
|
||||||
const getPlaceholderStyle = (page) => {
|
|
||||||
if (page?.dimensions?.width && page?.dimensions?.height) {
|
|
||||||
const maxW = windowWidth.value < 1200
|
|
||||||
? windowWidth.value * 0.95
|
|
||||||
: 1200;
|
|
||||||
return {
|
|
||||||
aspectRatio: `${page.dimensions.width} / ${page.dimensions.height}`,
|
|
||||||
width: '100%',
|
|
||||||
maxWidth: `${Math.min(page.dimensions.width, maxW)}px`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return { height: '800px', width: '100%' };
|
|
||||||
};
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
pages: {
|
pages: {
|
||||||
type: Array,
|
type: Array,
|
||||||
@@ -73,10 +65,6 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
doublePageMode: {
|
doublePageMode: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
|
||||||
initialPage: {
|
|
||||||
type: Number,
|
|
||||||
default: 0
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -85,6 +73,8 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
const headerStore = useHeaderStore();
|
const headerStore = useHeaderStore();
|
||||||
const containerRef = ref(null);
|
const containerRef = ref(null);
|
||||||
const observer = ref(null);
|
const observer = ref(null);
|
||||||
|
const visibilityObserver = ref(null);
|
||||||
|
const mountedPageIndices = reactive(new Set());
|
||||||
const windowWidth = ref(window.innerWidth);
|
const windowWidth = ref(window.innerWidth);
|
||||||
|
|
||||||
// État unique pour tous les boutons flottants avec timer de 3 secondes
|
// État unique pour tous les boutons flottants avec timer de 3 secondes
|
||||||
@@ -96,34 +86,54 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
let scrollDirection = 'down';
|
let scrollDirection = 'down';
|
||||||
|
|
||||||
const observeIntersection = entries => {
|
const observeIntersection = entries => {
|
||||||
const intersectingIndices = entries
|
entries.forEach(entry => {
|
||||||
.filter(e => e.isIntersecting)
|
if (entry.isIntersecting) {
|
||||||
.map(e => parseInt(e.target.getAttribute('data-page-index')));
|
const pageIndex = parseInt(entry.target.getAttribute('data-page-index'));
|
||||||
|
emit('pageVisible', pageIndex);
|
||||||
if (intersectingIndices.length > 0) {
|
}
|
||||||
const minIdx = Math.min(...intersectingIndices);
|
});
|
||||||
currentVisibleIndex.value = minIdx;
|
|
||||||
emit('pageVisible', minIdx);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const setupIntersectionObserver = () => {
|
// Calcul de la hauteur du placeholder — miroir exact du maxWidth de ReaderPage, zoom inclus
|
||||||
if (observer.value) {
|
const getPlaceholderHeight = (page) => {
|
||||||
observer.value.disconnect();
|
const dims = page?.dimensions;
|
||||||
}
|
if (!dims?.width || !dims?.height) return Math.round(800 * props.zoom);
|
||||||
|
const displayWidth = windowWidth.value < 1200
|
||||||
|
? Math.min(dims.width, windowWidth.value * 0.95)
|
||||||
|
: Math.min(dims.width, 1200);
|
||||||
|
return Math.round((dims.height / dims.width) * displayWidth * props.zoom);
|
||||||
|
};
|
||||||
|
|
||||||
|
const setupObservers = () => {
|
||||||
|
observer.value?.disconnect();
|
||||||
|
visibilityObserver.value?.disconnect();
|
||||||
|
|
||||||
observer.value = new IntersectionObserver(observeIntersection, {
|
observer.value = new IntersectionObserver(observeIntersection, {
|
||||||
root: null,
|
root: null,
|
||||||
threshold: 0.5
|
threshold: 0.5
|
||||||
});
|
});
|
||||||
|
|
||||||
nextTick(() => {
|
visibilityObserver.value = new IntersectionObserver(
|
||||||
const pageElements = containerRef.value?.querySelectorAll('.page-wrapper');
|
(entries) => {
|
||||||
if (pageElements) {
|
entries.forEach(entry => {
|
||||||
pageElements.forEach(element => {
|
const idx = parseInt(entry.target.getAttribute('data-page-index'));
|
||||||
observer.value.observe(element);
|
if (entry.isIntersecting) {
|
||||||
|
mountedPageIndices.add(idx);
|
||||||
|
} else {
|
||||||
|
mountedPageIndices.delete(idx);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
{ root: null, rootMargin: '1000px 0px', threshold: 0 }
|
||||||
|
);
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
const els = containerRef.value?.querySelectorAll('.page-wrapper');
|
||||||
|
els?.forEach((el, i) => {
|
||||||
|
el.setAttribute('data-page-index', i);
|
||||||
|
observer.value.observe(el);
|
||||||
|
visibilityObserver.value.observe(el);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -207,21 +217,16 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
|
|
||||||
// Fonction pour revenir en haut de la page
|
// Fonction pour revenir en haut de la page
|
||||||
const scrollToTop = () => {
|
const scrollToTop = () => {
|
||||||
console.log('scrollToTop appelée'); // Debug
|
|
||||||
|
|
||||||
// Réinitialiser le timer lors du clic
|
// Réinitialiser le timer lors du clic
|
||||||
resetButtonsTimer();
|
resetButtonsTimer();
|
||||||
|
|
||||||
// Stratégie 1: Scroll sur le conteneur direct
|
// Stratégie 1: Scroll sur le conteneur direct
|
||||||
if (containerRef.value) {
|
if (containerRef.value) {
|
||||||
console.log('containerRef trouvé, scrollTop actuel:', containerRef.value.scrollTop); // Debug
|
|
||||||
|
|
||||||
if (containerRef.value.scrollTop > 0) {
|
if (containerRef.value.scrollTop > 0) {
|
||||||
containerRef.value.scrollTo({
|
containerRef.value.scrollTo({
|
||||||
top: 0,
|
top: 0,
|
||||||
behavior: 'smooth'
|
behavior: 'smooth'
|
||||||
});
|
});
|
||||||
console.log('Scroll sur containerRef effectué'); // Debug
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,7 +236,6 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
while (currentElement) {
|
while (currentElement) {
|
||||||
const styles = window.getComputedStyle(currentElement);
|
const styles = window.getComputedStyle(currentElement);
|
||||||
if (styles.overflowY === 'auto' || styles.overflowY === 'scroll' || currentElement.scrollTop > 0) {
|
if (styles.overflowY === 'auto' || styles.overflowY === 'scroll' || currentElement.scrollTop > 0) {
|
||||||
console.log('Conteneur avec scroll trouvé:', currentElement.className, 'scrollTop:', currentElement.scrollTop); // Debug
|
|
||||||
currentElement.scrollTo({
|
currentElement.scrollTo({
|
||||||
top: 0,
|
top: 0,
|
||||||
behavior: 'smooth'
|
behavior: 'smooth'
|
||||||
@@ -242,7 +246,6 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stratégie 3: Scroll sur la fenêtre entière
|
// Stratégie 3: Scroll sur la fenêtre entière
|
||||||
console.log('Scroll sur window, scrollY actuel:', window.scrollY); // Debug
|
|
||||||
window.scrollTo({
|
window.scrollTo({
|
||||||
top: 0,
|
top: 0,
|
||||||
behavior: 'smooth'
|
behavior: 'smooth'
|
||||||
@@ -258,7 +261,8 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
watch(
|
watch(
|
||||||
() => props.pages,
|
() => props.pages,
|
||||||
() => {
|
() => {
|
||||||
setupIntersectionObserver();
|
mountedPageIndices.clear();
|
||||||
|
setupObservers();
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
@@ -277,8 +281,7 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
currentVisibleIndex.value = props.initialPage;
|
setupObservers();
|
||||||
setupIntersectionObserver();
|
|
||||||
|
|
||||||
// Activer l'auto-hide du header si la largeur < 1200px
|
// Activer l'auto-hide du header si la largeur < 1200px
|
||||||
if (windowWidth.value < 1200) {
|
if (windowWidth.value < 1200) {
|
||||||
@@ -298,9 +301,8 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (observer.value) {
|
observer.value?.disconnect();
|
||||||
observer.value.disconnect();
|
visibilityObserver.value?.disconnect();
|
||||||
}
|
|
||||||
|
|
||||||
// Désactiver l'auto-hide du header en quittant
|
// Désactiver l'auto-hide du header en quittant
|
||||||
headerStore.disableAutoHide();
|
headerStore.disableAutoHide();
|
||||||
@@ -335,25 +337,34 @@ import ReaderPage from './ReaderPage.vue';
|
|||||||
}
|
}
|
||||||
|
|
||||||
.page-placeholder {
|
.page-placeholder {
|
||||||
@apply flex justify-center;
|
@apply w-full;
|
||||||
background: transparent;
|
max-width: 1200px;
|
||||||
|
min-height: 400px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loading,
|
||||||
.error {
|
.error {
|
||||||
@apply text-red-500 text-xl bg-red-500/10 rounded-lg flex items-center justify-center min-h-[400px];
|
@apply flex items-center justify-center min-h-[400px];
|
||||||
width: 95vw;
|
/* Largeur adaptative selon la taille d'écran */
|
||||||
|
width: 95vw; /* Mobile : 95% de la largeur */
|
||||||
}
|
}
|
||||||
|
|
||||||
@screen sm {
|
@screen sm {
|
||||||
|
.loading,
|
||||||
.error {
|
.error {
|
||||||
width: 80vw;
|
width: 80vw; /* Tablette : 80% de la largeur */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@screen lg {
|
@screen lg {
|
||||||
|
.loading,
|
||||||
.error {
|
.error {
|
||||||
width: 70vw;
|
width: 70vw; /* Desktop : 70% de la largeur */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
@apply text-red-500 text-xl bg-red-500/10 rounded-lg;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
:alt="`Page ${pageNumber} (Double page)`"
|
:alt="`Page ${pageNumber} (Double page)`"
|
||||||
class="page-image rotated"
|
class="page-image rotated"
|
||||||
:style="doublePageRotatedStyle"
|
:style="doublePageRotatedStyle"
|
||||||
:loading="loading"
|
|
||||||
@load="handleImageLoad"
|
@load="handleImageLoad"
|
||||||
ref="imageRef" />
|
ref="imageRef" />
|
||||||
<div class="rotation-hint">
|
<div class="rotation-hint">
|
||||||
@@ -34,7 +33,6 @@
|
|||||||
:alt="`Page ${pageNumber} (Double page)`"
|
:alt="`Page ${pageNumber} (Double page)`"
|
||||||
class="page-image scrollable"
|
class="page-image scrollable"
|
||||||
:style="doublePageScrollStyle"
|
:style="doublePageScrollStyle"
|
||||||
:loading="loading"
|
|
||||||
@load="handleImageLoad"
|
@load="handleImageLoad"
|
||||||
ref="imageRef" />
|
ref="imageRef" />
|
||||||
</div>
|
</div>
|
||||||
@@ -54,7 +52,6 @@
|
|||||||
:alt="`Page ${pageNumber}`"
|
:alt="`Page ${pageNumber}`"
|
||||||
class="page-image"
|
class="page-image"
|
||||||
:style="imageStyle"
|
:style="imageStyle"
|
||||||
:loading="loading"
|
|
||||||
@load="handleImageLoad"
|
@load="handleImageLoad"
|
||||||
ref="imageRef" />
|
ref="imageRef" />
|
||||||
</div>
|
</div>
|
||||||
@@ -82,29 +79,28 @@ import { useReaderStore } from '../../application/store/readerStore';
|
|||||||
default: 'rotate', // 'rotate', 'scroll', 'normal'
|
default: 'rotate', // 'rotate', 'scroll', 'normal'
|
||||||
validator: (value) => ['rotate', 'scroll', 'normal'].includes(value)
|
validator: (value) => ['rotate', 'scroll', 'normal'].includes(value)
|
||||||
},
|
},
|
||||||
loading: {
|
windowWidth: {
|
||||||
type: String,
|
type: Number,
|
||||||
default: 'lazy',
|
default: null
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const store = useReaderStore();
|
const store = useReaderStore();
|
||||||
|
|
||||||
// En mode single : zoom via la propriété CSS `zoom` (affecte le layout → scrollbars naturelles)
|
// zoom via la propriété CSS `zoom` dans les deux modes (affecte le layout → pas de chevauchement en mode scroll)
|
||||||
// En mode infinite : zoom via transform: scale (pas d'impact layout souhaité)
|
|
||||||
const containerStyle = computed(() => {
|
const containerStyle = computed(() => {
|
||||||
if (store.readingMode === 'single') {
|
return { zoom: props.zoom };
|
||||||
return { zoom: props.zoom };
|
|
||||||
}
|
|
||||||
return { transform: `scale(${props.zoom})` };
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const imageRef = ref(null);
|
const imageRef = ref(null);
|
||||||
const scrollContainerRef = ref(null);
|
const scrollContainerRef = ref(null);
|
||||||
const naturalWidth = ref(0);
|
const naturalWidth = ref(0);
|
||||||
const naturalHeight = ref(0);
|
const naturalHeight = ref(0);
|
||||||
const windowWidth = ref(window.innerWidth);
|
const localWindowWidth = ref(window.innerWidth);
|
||||||
const isMobile = computed(() => windowWidth.value < 768);
|
const effectiveWindowWidth = computed(() =>
|
||||||
|
props.windowWidth !== null ? props.windowWidth : localWindowWidth.value
|
||||||
|
);
|
||||||
|
const isMobile = computed(() => effectiveWindowWidth.value < 768);
|
||||||
const imageLoaded = ref(false);
|
const imageLoaded = ref(false);
|
||||||
|
|
||||||
const imageSource = computed(() => {
|
const imageSource = computed(() => {
|
||||||
@@ -123,17 +119,13 @@ import { useReaderStore } from '../../application/store/readerStore';
|
|||||||
// Utiliser d'abord les dimensions de l'API si disponibles
|
// Utiliser d'abord les dimensions de l'API si disponibles
|
||||||
if (props.pageData?.dimensions?.width && props.pageData?.dimensions?.height) {
|
if (props.pageData?.dimensions?.width && props.pageData?.dimensions?.height) {
|
||||||
const ratio = props.pageData.dimensions.width / props.pageData.dimensions.height;
|
const ratio = props.pageData.dimensions.width / props.pageData.dimensions.height;
|
||||||
const isDouble = ratio > threshold;
|
return ratio > threshold;
|
||||||
console.log(`API Dimensions - Page ${props.pageNumber}: ${props.pageData.dimensions.width}x${props.pageData.dimensions.height}, ratio: ${ratio.toFixed(2)}, isDouble: ${isDouble}`);
|
|
||||||
return isDouble;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback sur les dimensions naturelles de l'image (seulement si l'image est chargée)
|
// Fallback sur les dimensions naturelles de l'image (seulement si l'image est chargée)
|
||||||
if (imageLoaded.value && naturalWidth.value && naturalHeight.value) {
|
if (imageLoaded.value && naturalWidth.value && naturalHeight.value) {
|
||||||
const ratio = naturalWidth.value / naturalHeight.value;
|
const ratio = naturalWidth.value / naturalHeight.value;
|
||||||
const isDouble = ratio > threshold;
|
return ratio > threshold;
|
||||||
console.log(`Natural Dimensions - Page ${props.pageNumber}: ${naturalWidth.value}x${naturalHeight.value}, ratio: ${ratio.toFixed(2)}, isDouble: ${isDouble}`);
|
|
||||||
return isDouble;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -144,7 +136,6 @@ import { useReaderStore } from '../../application/store/readerStore';
|
|||||||
naturalWidth.value = imageRef.value.naturalWidth;
|
naturalWidth.value = imageRef.value.naturalWidth;
|
||||||
naturalHeight.value = imageRef.value.naturalHeight;
|
naturalHeight.value = imageRef.value.naturalHeight;
|
||||||
imageLoaded.value = true;
|
imageLoaded.value = true;
|
||||||
console.log(`Image loaded - Page ${props.pageNumber}: ${naturalWidth.value}x${naturalHeight.value}`);
|
|
||||||
|
|
||||||
// Positionner le scroll à droite si c'est le mode scroll
|
// Positionner le scroll à droite si c'est le mode scroll
|
||||||
if (props.doublePageMode === 'scroll' && scrollContainerRef.value) {
|
if (props.doublePageMode === 'scroll' && scrollContainerRef.value) {
|
||||||
@@ -195,7 +186,7 @@ import { useReaderStore } from '../../application/store/readerStore';
|
|||||||
|
|
||||||
if (!width || !height) return null;
|
if (!width || !height) return null;
|
||||||
|
|
||||||
const availableWidth = windowWidth.value;
|
const availableWidth = effectiveWindowWidth.value;
|
||||||
|
|
||||||
// Si la largeur disponible est < 1200px : utiliser 95% de la largeur
|
// Si la largeur disponible est < 1200px : utiliser 95% de la largeur
|
||||||
if (availableWidth < 1200) {
|
if (availableWidth < 1200) {
|
||||||
@@ -244,7 +235,7 @@ import { useReaderStore } from '../../application/store/readerStore';
|
|||||||
if (!width || !height) return {};
|
if (!width || !height) return {};
|
||||||
|
|
||||||
// En mode rotation : maximiser l'utilisation de l'espace
|
// En mode rotation : maximiser l'utilisation de l'espace
|
||||||
const availableWidth = windowWidth.value;
|
const availableWidth = effectiveWindowWidth.value;
|
||||||
const availableHeight = window.innerHeight - 100; // Laisser un peu d'espace pour les contrôles
|
const availableHeight = window.innerHeight - 100; // Laisser un peu d'espace pour les contrôles
|
||||||
|
|
||||||
// Après rotation, la largeur originale devient la hauteur affichée
|
// Après rotation, la largeur originale devient la hauteur affichée
|
||||||
@@ -294,20 +285,18 @@ import { useReaderStore } from '../../application/store/readerStore';
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Gestion du redimensionnement de la fenêtre
|
let ownResizeHandler = null;
|
||||||
const handleResize = () => {
|
|
||||||
windowWidth.value = window.innerWidth;
|
|
||||||
};
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (imageRef.value && imageRef.value.complete) {
|
if (props.windowWidth === null) {
|
||||||
handleImageLoad();
|
ownResizeHandler = () => { localWindowWidth.value = window.innerWidth; };
|
||||||
|
window.addEventListener('resize', ownResizeHandler, { passive: true });
|
||||||
}
|
}
|
||||||
window.addEventListener('resize', handleResize);
|
if (imageRef.value?.complete) handleImageLoad();
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
window.removeEventListener('resize', handleResize);
|
if (ownResizeHandler) window.removeEventListener('resize', ownResizeHandler);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,15 @@ export const useContentSourceStore = defineStore('contentSource', {
|
|||||||
importing: false,
|
importing: false,
|
||||||
exporting: false,
|
exporting: false,
|
||||||
importError: null,
|
importError: null,
|
||||||
exportError: null
|
exportError: null,
|
||||||
|
|
||||||
|
// Health check state
|
||||||
|
checkingHealth: false,
|
||||||
|
checkHealthError: null,
|
||||||
|
|
||||||
|
// Delete state
|
||||||
|
deleting: false,
|
||||||
|
deleteError: null,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
@@ -168,12 +176,64 @@ export const useContentSourceStore = defineStore('contentSource', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Delete a source
|
||||||
|
async deleteSource(id) {
|
||||||
|
if (this.deleting) return;
|
||||||
|
|
||||||
|
this.deleting = true;
|
||||||
|
this.deleteError = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await contentSourceRepository.delete(id);
|
||||||
|
this.sources = this.sources.filter(source => source.id !== id);
|
||||||
|
if (this.currentSource && this.currentSource.id === id) {
|
||||||
|
this.currentSource = null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.deleteError = error.message;
|
||||||
|
console.error('Erreur lors de la suppression de la source:', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this.deleting = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Clear current source
|
// Clear current source
|
||||||
clearCurrentSource() {
|
clearCurrentSource() {
|
||||||
this.currentSource = null;
|
this.currentSource = null;
|
||||||
this.currentSourceError = null;
|
this.currentSourceError = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Check all scrapers health
|
||||||
|
async checkAllHealth() {
|
||||||
|
if (this.checkingHealth) return;
|
||||||
|
|
||||||
|
this.checkingHealth = true;
|
||||||
|
this.checkHealthError = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await contentSourceRepository.checkAllHealth();
|
||||||
|
} catch (error) {
|
||||||
|
this.checkHealthError = error.message;
|
||||||
|
console.error('Erreur lors du health check:', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this.checkingHealth = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Update health status of a single source (called from Mercure)
|
||||||
|
updateSourceHealth(sourceId, status, error = null) {
|
||||||
|
const index = this.sources.findIndex(s => s.id === sourceId);
|
||||||
|
if (index !== -1) {
|
||||||
|
this.sources[index] = {
|
||||||
|
...this.sources[index],
|
||||||
|
healthStatus: status,
|
||||||
|
healthLastError: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Clear errors
|
// Clear errors
|
||||||
clearErrors() {
|
clearErrors() {
|
||||||
this.sourcesError = null;
|
this.sourcesError = null;
|
||||||
@@ -181,6 +241,7 @@ export const useContentSourceStore = defineStore('contentSource', {
|
|||||||
this.saveError = null;
|
this.saveError = null;
|
||||||
this.importError = null;
|
this.importError = null;
|
||||||
this.exportError = null;
|
this.exportError = null;
|
||||||
|
this.checkHealthError = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export const ScraperHealthStatus = {
|
||||||
|
UNKNOWN: 'unknown',
|
||||||
|
OK: 'ok',
|
||||||
|
KO: 'ko',
|
||||||
|
TESTING: 'testing',
|
||||||
|
};
|
||||||
@@ -82,6 +82,28 @@ export class ApiContentSourceRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Déclenche le test de santé de tous les scrapers
|
||||||
|
*/
|
||||||
|
async checkAllHealth() {
|
||||||
|
try {
|
||||||
|
await this.apiClient.post('/scraping/check-all-health', {});
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error.response?.data?.message || 'Erreur lors du lancement du health check');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supprime une source de contenu
|
||||||
|
*/
|
||||||
|
async delete(id) {
|
||||||
|
try {
|
||||||
|
await this.apiClient.delete(`/content-sources/${id}`);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error.response?.data?.message || 'Erreur lors de la suppression de la source');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teste une configuration de scraper
|
* Teste une configuration de scraper
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
@click="$emit('edit', source)"
|
@click="$emit('edit', source)"
|
||||||
class="bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-700 p-6 hover:shadow-lg transition-shadow duration-200 cursor-pointer">
|
class="bg-white dark:bg-gray-800 shadow-md border border-gray-200 dark:border-gray-700 p-6 hover:shadow-lg transition-shadow duration-200 cursor-pointer">
|
||||||
<!-- Header avec URL et icône externe -->
|
<!-- Header avec URL et icône externe -->
|
||||||
<div class="flex items-center justify-between mb-4">
|
<div class="flex items-center justify-between mb-4">
|
||||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white truncate" :title="source.cleanBaseUrl">
|
<h3 class="text-lg font-semibold text-gray-900 dark:text-white truncate" :title="source.cleanBaseUrl">
|
||||||
@@ -20,16 +20,24 @@
|
|||||||
<!-- Badge type de scraping -->
|
<!-- Badge type de scraping -->
|
||||||
<span
|
<span
|
||||||
:class="getScrapingTypeBadgeClass(source.scrapingType)"
|
:class="getScrapingTypeBadgeClass(source.scrapingType)"
|
||||||
class="px-2 py-1 text-xs font-medium rounded-md">
|
class="px-2 py-1 text-xs font-medium">
|
||||||
{{ source.scrapingType?.toLowerCase() || 'N/A' }}
|
{{ source.scrapingType?.toLowerCase() || 'N/A' }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<!-- Badge orientation basé sur les sélecteurs -->
|
<!-- Badge orientation basé sur les sélecteurs -->
|
||||||
<span
|
<span
|
||||||
:class="getOrientationBadgeClass(source)"
|
:class="getOrientationBadgeClass(source)"
|
||||||
class="px-2 py-1 text-xs font-medium rounded-md">
|
class="px-2 py-1 text-xs font-medium">
|
||||||
{{ getOrientation(source) }}
|
{{ getOrientation(source) }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
<!-- Badge health status -->
|
||||||
|
<span
|
||||||
|
:class="getHealthBadgeClass(source.healthStatus)"
|
||||||
|
class="px-2 py-1 text-xs font-medium"
|
||||||
|
:title="source.healthLastError || ''">
|
||||||
|
{{ getHealthLabel(source.healthStatus) }}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@@ -39,6 +47,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ArrowTopRightOnSquareIcon } from '@heroicons/vue/24/outline';
|
import { ArrowTopRightOnSquareIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import { ScraperHealthStatus } from '../../domain/model/ScraperHealthStatus';
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
source: {
|
source: {
|
||||||
@@ -86,4 +95,26 @@ const getOrientationBadgeClass = (source) => {
|
|||||||
return 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300';
|
return 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getHealthLabel = (status) => {
|
||||||
|
switch (status) {
|
||||||
|
case ScraperHealthStatus.OK: return '✓ ok';
|
||||||
|
case ScraperHealthStatus.KO: return '✗ ko';
|
||||||
|
case ScraperHealthStatus.TESTING: return '⟳ test';
|
||||||
|
default: return '? unknown';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getHealthBadgeClass = (status) => {
|
||||||
|
switch (status) {
|
||||||
|
case ScraperHealthStatus.OK:
|
||||||
|
return 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300';
|
||||||
|
case ScraperHealthStatus.KO:
|
||||||
|
return 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300';
|
||||||
|
case ScraperHealthStatus.TESTING:
|
||||||
|
return 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300';
|
||||||
|
default:
|
||||||
|
return 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-400';
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
<template>
|
||||||
|
<TransitionRoot as="template" :show="isOpen">
|
||||||
|
<Dialog as="div" class="relative z-50" @close="closeModal">
|
||||||
|
<TransitionChild
|
||||||
|
as="template"
|
||||||
|
enter="ease-out duration-300"
|
||||||
|
enter-from="opacity-0"
|
||||||
|
enter-to="opacity-100"
|
||||||
|
leave="ease-in duration-200"
|
||||||
|
leave-from="opacity-100"
|
||||||
|
leave-to="opacity-0"
|
||||||
|
>
|
||||||
|
<div class="fixed inset-0 bg-gray-500 dark:bg-gray-900 bg-opacity-75 dark:bg-opacity-80 transition-opacity" />
|
||||||
|
</TransitionChild>
|
||||||
|
|
||||||
|
<div class="fixed inset-0 z-10 overflow-y-auto">
|
||||||
|
<div class="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
|
||||||
|
<TransitionChild
|
||||||
|
as="template"
|
||||||
|
enter="ease-out duration-300"
|
||||||
|
enter-from="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||||
|
enter-to="opacity-100 translate-y-0 sm:scale-100"
|
||||||
|
leave="ease-in duration-200"
|
||||||
|
leave-from="opacity-100 translate-y-0 sm:scale-100"
|
||||||
|
leave-to="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||||
|
>
|
||||||
|
<DialogPanel class="relative transform overflow-hidden rounded-lg bg-white dark:bg-gray-800 px-6 pb-6 pt-6 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg">
|
||||||
|
<div class="mb-6">
|
||||||
|
<DialogTitle as="h3" class="text-lg font-semibold leading-6 text-gray-900 dark:text-gray-100">
|
||||||
|
Supprimer la source de contenu
|
||||||
|
</DialogTitle>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Error state -->
|
||||||
|
<div v-if="error" class="mb-6 bg-red-100 dark:bg-red-900/20 border border-red-400 dark:border-red-700 text-red-700 dark:text-red-400 px-4 py-3 rounded">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Warning message -->
|
||||||
|
<div class="mb-6">
|
||||||
|
<div class="flex items-center mb-4">
|
||||||
|
<ExclamationTriangleIcon class="h-6 w-6 text-red-500 mr-3" />
|
||||||
|
<span class="text-sm font-medium text-gray-900 dark:text-gray-100">Action irréversible</span>
|
||||||
|
</div>
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
|
||||||
|
Êtes-vous sûr de vouloir supprimer la source <strong>{{ source?.baseUrl }}</strong> ?
|
||||||
|
</p>
|
||||||
|
<div class="bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-700 rounded-md p-4">
|
||||||
|
<div class="flex">
|
||||||
|
<ExclamationTriangleIcon class="h-5 w-5 text-yellow-400" />
|
||||||
|
<div class="ml-3">
|
||||||
|
<h3 class="text-sm font-medium text-yellow-800 dark:text-yellow-300">
|
||||||
|
Attention
|
||||||
|
</h3>
|
||||||
|
<div class="mt-2 text-sm text-yellow-700 dark:text-yellow-400">
|
||||||
|
<p>Cette source ne pourra plus être utilisée pour le scraping des chapitres.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Action buttons -->
|
||||||
|
<div class="mt-6 flex justify-end space-x-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex justify-center rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 shadow-sm hover:bg-gray-50 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
|
||||||
|
@click="closeModal"
|
||||||
|
:disabled="isLoading"
|
||||||
|
>
|
||||||
|
Annuler
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex justify-center rounded-md border border-transparent bg-red-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
@click="confirmDelete"
|
||||||
|
:disabled="isLoading"
|
||||||
|
>
|
||||||
|
<ArrowPathIcon v-if="isLoading" class="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
{{ isLoading ? 'Suppression...' : 'Supprimer définitivement' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</DialogPanel>
|
||||||
|
</TransitionChild>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
</TransitionRoot>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { Dialog, DialogPanel, DialogTitle, TransitionChild, TransitionRoot } from '@headlessui/vue';
|
||||||
|
import { ArrowPathIcon, ExclamationTriangleIcon } from '@heroicons/vue/24/outline';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
isOpen: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
source: {
|
||||||
|
type: Object,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
isLoading: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits(['close', 'confirm']);
|
||||||
|
|
||||||
|
const closeModal = () => {
|
||||||
|
emit('close');
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmDelete = () => {
|
||||||
|
emit('confirm');
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -1,17 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700">
|
<div>
|
||||||
<!-- Header -->
|
|
||||||
<div class="bg-gray-50 dark:bg-gray-700 px-6 py-4 border-b border-gray-200 dark:border-gray-600 rounded-t-lg">
|
|
||||||
<div class="flex items-center space-x-2">
|
|
||||||
<Cog6ToothIcon class="w-5 h-5 text-gray-600 dark:text-gray-400" />
|
|
||||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white">
|
|
||||||
{{ isEditing ? 'Edit Scrapper Configuration' : 'New Scrapper Configuration' }}
|
|
||||||
</h2>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Form -->
|
<!-- Form -->
|
||||||
<form @submit.prevent="handleSubmit" class="p-6 space-y-6">
|
<form @submit.prevent="handleSubmit" class="space-y-6">
|
||||||
<!-- Base URL -->
|
<!-- Base URL -->
|
||||||
<div>
|
<div>
|
||||||
<label for="baseUrl" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
<label for="baseUrl" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
@@ -22,25 +12,12 @@
|
|||||||
v-model="form.baseUrl"
|
v-model="form.baseUrl"
|
||||||
type="url"
|
type="url"
|
||||||
required
|
required
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
||||||
placeholder="https://example.com" />
|
placeholder="https://example.com" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Image Selector -->
|
|
||||||
<div>
|
|
||||||
<label for="imageSelector" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
|
||||||
Image Selector
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
id="imageSelector"
|
|
||||||
v-model="form.imageSelector"
|
|
||||||
type="text"
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
|
||||||
placeholder=".reading-content .page-break img" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Chapter URL Format -->
|
<!-- Chapter URL Format -->
|
||||||
<div>
|
<div class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
<label for="chapterUrlFormat" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
<label for="chapterUrlFormat" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
Chapter URL Format <span class="text-gray-500">({slug}, {chapterNumber})</span>
|
Chapter URL Format <span class="text-gray-500">({slug}, {chapterNumber})</span>
|
||||||
</label>
|
</label>
|
||||||
@@ -49,132 +26,132 @@
|
|||||||
v-model="form.chapterUrlFormat"
|
v-model="form.chapterUrlFormat"
|
||||||
type="text"
|
type="text"
|
||||||
required
|
required
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
||||||
placeholder="https://example.com/manga/{slug}-{chapterNumber}/" />
|
placeholder="https://example.com/manga/{slug}-{chapterNumber}/" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Next Page Selector -->
|
<!-- Selectors -->
|
||||||
<div>
|
<div class="border-t border-gray-200 dark:border-gray-700 pt-6 space-y-4">
|
||||||
<label for="nextPageSelector" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
<div>
|
||||||
Next Page Selector <span class="text-gray-500">(let empty if vertical reader)</span>
|
<label for="imageSelector" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
</label>
|
Image Selector
|
||||||
<input
|
</label>
|
||||||
id="nextPageSelector"
|
<input
|
||||||
v-model="form.nextPageSelector"
|
id="imageSelector"
|
||||||
type="text"
|
v-model="form.imageSelector"
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
type="text"
|
||||||
placeholder=".next-page" />
|
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
||||||
|
placeholder=".reading-content .page-break img" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="nextPageSelector" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
|
Next Page Selector <span class="text-gray-500">(laisser vide si lecteur vertical)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="nextPageSelector"
|
||||||
|
v-model="form.nextPageSelector"
|
||||||
|
type="text"
|
||||||
|
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
||||||
|
placeholder=".next-page" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="chapterSelector" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
|
Chapter Selector <span class="text-gray-500">(requis pour le scraping Javascript)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="chapterSelector"
|
||||||
|
v-model="form.chapterSelector"
|
||||||
|
type="text"
|
||||||
|
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
||||||
|
placeholder=".chapter-selector" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Chapter Selector -->
|
<!-- Scraping Type + Token -->
|
||||||
<div>
|
<div class="border-t border-gray-200 dark:border-gray-700 pt-6 space-y-4">
|
||||||
<label for="chapterSelector" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
<div>
|
||||||
Chapter Selector <span class="text-gray-500">(required for Javascript scraping)</span>
|
<label for="scrapingType" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
</label>
|
Scraping Type
|
||||||
<input
|
</label>
|
||||||
id="chapterSelector"
|
<select
|
||||||
v-model="form.chapterSelector"
|
id="scrapingType"
|
||||||
type="text"
|
v-model="form.scrapingType"
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
required
|
||||||
placeholder=".chapter-selector" />
|
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
|
||||||
</div>
|
<option value="html">HTML</option>
|
||||||
|
<option value="javascript">Javascript</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Scraping Type -->
|
<div>
|
||||||
<div>
|
<label for="token" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
<label for="scrapingType" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
Token
|
||||||
Scraping Type
|
</label>
|
||||||
</label>
|
<input
|
||||||
<select
|
id="token"
|
||||||
id="scrapingType"
|
v-model="form.token"
|
||||||
v-model="form.scrapingType"
|
type="text"
|
||||||
required
|
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
|
placeholder="Optional authentication token" />
|
||||||
<option value="html">HTML</option>
|
</div>
|
||||||
<option value="javascript">Javascript</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Token (optionnel) -->
|
|
||||||
<div>
|
|
||||||
<label for="token" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
|
||||||
Token
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
id="token"
|
|
||||||
v-model="form.token"
|
|
||||||
type="text"
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
|
||||||
placeholder="Optional authentication token" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Submit Button -->
|
|
||||||
<div class="flex justify-end">
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
:disabled="saving"
|
|
||||||
class="px-6 py-2 bg-green-600 hover:bg-green-700 disabled:bg-green-400 text-white font-medium rounded-md transition-colors duration-200 flex items-center space-x-2">
|
|
||||||
<ArrowPathIcon v-if="saving" class="w-4 h-4 animate-spin" />
|
|
||||||
<span>{{ isEditing ? 'Update Configuration' : 'Create Configuration' }}</span>
|
|
||||||
<PencilSquareIcon v-if="!saving" class="w-4 h-4" />
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Error message -->
|
<!-- Error message -->
|
||||||
<div v-if="error" class="text-red-600 dark:text-red-400 text-sm">
|
<div v-if="error" class="border-t border-gray-200 dark:border-gray-700 pt-6 text-red-600 dark:text-red-400 text-sm">
|
||||||
{{ error }}
|
{{ error }}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- Test Configuration Section -->
|
<!-- Test Configuration Section -->
|
||||||
<div class="border-t border-gray-200 dark:border-gray-600 p-6 bg-gray-50 dark:bg-gray-700 rounded-b-lg">
|
<div class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
|
||||||
<div class="flex items-center space-x-2 mb-4">
|
<div class="flex items-center space-x-2 mb-6">
|
||||||
<WrenchScrewdriverIcon class="w-5 h-5 text-gray-600 dark:text-gray-400" />
|
<WrenchScrewdriverIcon class="w-5 h-5 text-gray-600 dark:text-gray-400" />
|
||||||
<h3 class="text-lg font-medium text-gray-900 dark:text-white">Test Configuration</h3>
|
<h3 class="text-sm font-medium text-gray-900 dark:text-white">Configuration de test (health check)</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
||||||
<div>
|
<div>
|
||||||
<label for="testMangaSlug" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
<label for="testSlug" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
Manga Slug
|
Manga Slug <span class="text-gray-500">(enregistré)</span>
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
id="testMangaSlug"
|
id="testSlug"
|
||||||
v-model="testData.mangaSlug"
|
v-model="form.testSlug"
|
||||||
type="text"
|
type="text"
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
||||||
placeholder="manga-slug" />
|
placeholder="manga-slug" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="testChapterNumber" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
<label for="testChapterNumber" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
Chapter Number
|
Numéro de chapitre <span class="text-gray-500">(enregistré)</span>
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
id="testChapterNumber"
|
id="testChapterNumber"
|
||||||
v-model="testData.chapterNumber"
|
v-model="form.testChapterNumber"
|
||||||
type="number"
|
type="number"
|
||||||
step="0.1"
|
step="0.1"
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white"
|
||||||
placeholder="1" />
|
placeholder="1" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Preview de l'URL qui sera testée -->
|
<!-- Preview URL -->
|
||||||
<div v-if="generatedTestUrl" class="mb-4 p-3 bg-blue-50 dark:bg-blue-900 border border-blue-200 dark:border-blue-700 rounded-md">
|
<div v-if="generatedTestUrl" class="mb-4 border-t border-gray-200 dark:border-gray-700 pt-4">
|
||||||
<div class="text-sm text-blue-800 dark:text-blue-200">
|
<p class="text-xs text-gray-500 dark:text-gray-400 mb-1">URL qui sera testée</p>
|
||||||
<strong>URL qui sera testée :</strong>
|
<code class="text-xs text-gray-700 dark:text-gray-300 break-all">{{ generatedTestUrl }}</code>
|
||||||
<div class="mt-1 font-mono text-xs break-all">{{ generatedTestUrl }}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@click="testConfiguration"
|
@click="testConfiguration"
|
||||||
:disabled="testing || !canTest"
|
:disabled="testing || !canTest"
|
||||||
class="w-full px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium rounded-md transition-colors duration-200 flex items-center justify-center space-x-2">
|
class="w-full px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium transition-colors duration-200 flex items-center justify-center space-x-2">
|
||||||
<ArrowPathIcon v-if="testing" class="w-4 h-4 animate-spin" />
|
<ArrowPathIcon v-if="testing" class="w-4 h-4 animate-spin" />
|
||||||
<PlayIcon v-else class="w-4 h-4" />
|
<PlayIcon v-else class="w-4 h-4" />
|
||||||
<span>Test Configuration</span>
|
<span>Tester maintenant</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -183,8 +160,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import {
|
import {
|
||||||
ArrowPathIcon,
|
ArrowPathIcon,
|
||||||
Cog6ToothIcon,
|
|
||||||
PencilSquareIcon,
|
|
||||||
PlayIcon,
|
PlayIcon,
|
||||||
WrenchScrewdriverIcon
|
WrenchScrewdriverIcon
|
||||||
} from '@heroicons/vue/24/outline';
|
} from '@heroicons/vue/24/outline';
|
||||||
@@ -216,12 +191,9 @@ const form = ref({
|
|||||||
nextPageSelector: '',
|
nextPageSelector: '',
|
||||||
chapterSelector: '',
|
chapterSelector: '',
|
||||||
scrapingType: 'html',
|
scrapingType: 'html',
|
||||||
token: ''
|
token: '',
|
||||||
});
|
testSlug: '',
|
||||||
|
testChapterNumber: '',
|
||||||
const testData = ref({
|
|
||||||
mangaSlug: '',
|
|
||||||
chapterNumber: ''
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const testing = ref(false);
|
const testing = ref(false);
|
||||||
@@ -229,20 +201,19 @@ const testing = ref(false);
|
|||||||
const canTest = computed(() => {
|
const canTest = computed(() => {
|
||||||
return form.value.baseUrl &&
|
return form.value.baseUrl &&
|
||||||
form.value.chapterUrlFormat &&
|
form.value.chapterUrlFormat &&
|
||||||
testData.value.mangaSlug &&
|
form.value.testSlug &&
|
||||||
testData.value.chapterNumber;
|
form.value.testChapterNumber;
|
||||||
});
|
});
|
||||||
|
|
||||||
const generatedTestUrl = computed(() => {
|
const generatedTestUrl = computed(() => {
|
||||||
if (!form.value.chapterUrlFormat || !testData.value.mangaSlug || !testData.value.chapterNumber) {
|
if (!form.value.chapterUrlFormat || !form.value.testSlug || !form.value.testChapterNumber) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return form.value.chapterUrlFormat
|
return form.value.chapterUrlFormat
|
||||||
.replace('{slug}', testData.value.mangaSlug)
|
.replace('{slug}', form.value.testSlug)
|
||||||
.replace('{chapterNumber}', testData.value.chapterNumber);
|
.replace('{chapterNumber}', form.value.testChapterNumber);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize form with source data if editing, clear if creating new
|
|
||||||
watch(() => props.source, (newSource) => {
|
watch(() => props.source, (newSource) => {
|
||||||
if (newSource) {
|
if (newSource) {
|
||||||
form.value = {
|
form.value = {
|
||||||
@@ -252,10 +223,11 @@ watch(() => props.source, (newSource) => {
|
|||||||
nextPageSelector: newSource.nextPageSelector || '',
|
nextPageSelector: newSource.nextPageSelector || '',
|
||||||
chapterSelector: newSource.chapterSelector || '',
|
chapterSelector: newSource.chapterSelector || '',
|
||||||
scrapingType: (newSource.scrapingType || 'html').toLowerCase(),
|
scrapingType: (newSource.scrapingType || 'html').toLowerCase(),
|
||||||
token: newSource.token || ''
|
token: newSource.token || '',
|
||||||
|
testSlug: newSource.testSlug || '',
|
||||||
|
testChapterNumber: newSource.testChapterNumber ?? '',
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// Reset form when no source (creating new)
|
|
||||||
form.value = {
|
form.value = {
|
||||||
baseUrl: '',
|
baseUrl: '',
|
||||||
imageSelector: '',
|
imageSelector: '',
|
||||||
@@ -263,7 +235,9 @@ watch(() => props.source, (newSource) => {
|
|||||||
nextPageSelector: '',
|
nextPageSelector: '',
|
||||||
chapterSelector: '',
|
chapterSelector: '',
|
||||||
scrapingType: 'html',
|
scrapingType: 'html',
|
||||||
token: ''
|
token: '',
|
||||||
|
testSlug: '',
|
||||||
|
testChapterNumber: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, { immediate: true });
|
}, { immediate: true });
|
||||||
@@ -272,14 +246,17 @@ const handleSubmit = () => {
|
|||||||
emit('submit', { ...form.value });
|
emit('submit', { ...form.value });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
defineExpose({ submitForm: handleSubmit });
|
||||||
|
|
||||||
const testConfiguration = async () => {
|
const testConfiguration = async () => {
|
||||||
testing.value = true;
|
testing.value = true;
|
||||||
try {
|
try {
|
||||||
await emit('test', {
|
await emit('test', {
|
||||||
configuration: { ...form.value },
|
configuration: { ...form.value },
|
||||||
testData: {
|
testData: {
|
||||||
...testData.value,
|
mangaSlug: form.value.testSlug,
|
||||||
testUrl: generatedTestUrl.value
|
chapterNumber: form.value.testChapterNumber,
|
||||||
|
testUrl: generatedTestUrl.value,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -3,72 +3,54 @@
|
|||||||
<Toolbar :config="toolbarConfig" />
|
<Toolbar :config="toolbarConfig" />
|
||||||
|
|
||||||
<div class="overflow-y-auto flex-1">
|
<div class="overflow-y-auto flex-1">
|
||||||
<div class="container mx-auto px-4 py-6">
|
<div class="px-6 py-8">
|
||||||
<!-- Header -->
|
|
||||||
<div class="mb-8">
|
|
||||||
<h1 class="text-3xl font-bold text-gray-900 dark:text-white mb-2">
|
|
||||||
Scrapper Configurations
|
|
||||||
</h1>
|
|
||||||
<p class="text-gray-600 dark:text-gray-400">
|
|
||||||
Gérez les configurations de scraping pour les différentes sources de manga
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Loading State -->
|
<!-- Loading State -->
|
||||||
<div v-if="loadingSources" class="flex justify-center py-12">
|
<div v-if="loadingSources" class="flex justify-center py-12">
|
||||||
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500"></div>
|
<div class="animate-spin h-12 w-12 border-b-2 border-blue-500"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Error State -->
|
<!-- Error State -->
|
||||||
<div v-else-if="sourcesError" class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 rounded-lg p-4 mb-6">
|
<div v-else-if="sourcesError" class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 p-4 mb-6">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<ExclamationTriangleIcon class="w-5 h-5 text-red-400 mr-2" />
|
<ExclamationTriangleIcon class="w-5 h-5 text-red-400 mr-2" />
|
||||||
<p class="text-red-800 dark:text-red-200">{{ sourcesError }}</p>
|
<p class="text-red-800 dark:text-red-200">{{ sourcesError }}</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
@click="contentSourceStore.loadSources()"
|
@click="contentSourceStore.loadSources()"
|
||||||
class="mt-3 px-4 py-2 bg-red-600 text-white rounded hover:bg-red-700">
|
class="mt-3 px-4 py-2 bg-red-600 text-white hover:bg-red-700">
|
||||||
Réessayer
|
Réessayer
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Debug Info (temporary) -->
|
|
||||||
<div v-if="!loadingSources && !sourcesError && sources.length === 0" class="bg-blue-50 dark:bg-blue-900 border border-blue-200 dark:border-blue-700 rounded-lg p-4 mb-6">
|
|
||||||
<p class="text-blue-800 dark:text-blue-200">Aucune source trouvée. Rechargement en cours...</p>
|
|
||||||
<button
|
|
||||||
@click="contentSourceStore.loadSources()"
|
|
||||||
class="mt-2 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">
|
|
||||||
Actualiser
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Sources Grid -->
|
<!-- Sources Grid -->
|
||||||
<div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
<section v-else class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
<!-- Existing Sources -->
|
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
<ContentSourceCard
|
<!-- Existing Sources -->
|
||||||
v-for="source in sources"
|
<ContentSourceCard
|
||||||
:key="source.id"
|
v-for="source in sources"
|
||||||
:source="source"
|
:key="source.id"
|
||||||
@edit="editSource"
|
:source="source"
|
||||||
@open-link="openSourceLink" />
|
@edit="editSource"
|
||||||
|
@open-link="openSourceLink" />
|
||||||
|
|
||||||
<!-- Add New Configuration Card -->
|
<!-- Add New Configuration Card -->
|
||||||
<div
|
<div
|
||||||
@click="addNewSource"
|
@click="addNewSource"
|
||||||
class="bg-gray-50 dark:bg-gray-700 border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-6 hover:border-gray-400 dark:hover:border-gray-500 transition-colors cursor-pointer flex flex-col items-center justify-center h-full">
|
class="bg-gray-50 dark:bg-gray-700 border-2 border-dashed border-gray-300 dark:border-gray-600 p-6 hover:border-gray-400 dark:hover:border-gray-500 transition-colors cursor-pointer flex flex-col items-center justify-center h-full">
|
||||||
<PlusIcon class="w-8 h-8 text-gray-400 dark:text-gray-500 mb-3" />
|
<PlusIcon class="w-8 h-8 text-gray-400 dark:text-gray-500 mb-3" />
|
||||||
<span class="text-lg font-medium text-gray-600 dark:text-gray-400 mb-2">
|
<span class="text-lg font-medium text-gray-600 dark:text-gray-400 mb-2">
|
||||||
Add New Configuration
|
Add New Configuration
|
||||||
</span>
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</section>
|
||||||
|
|
||||||
<!-- Import/Export Success Messages -->
|
<!-- Import/Export Success Messages -->
|
||||||
<div v-if="showImportSuccess" class="fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg">
|
<div v-if="showImportSuccess" class="fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 shadow-lg">
|
||||||
Configuration importée avec succès !
|
Configuration importée avec succès !
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="showExportSuccess" class="fixed bottom-4 right-4 bg-blue-500 text-white px-4 py-2 rounded-lg shadow-lg">
|
<div v-if="showExportSuccess" class="fixed bottom-4 right-4 bg-blue-500 text-white px-4 py-2 shadow-lg">
|
||||||
Configuration exportée !
|
Configuration exportée !
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -76,12 +58,12 @@
|
|||||||
|
|
||||||
<!-- Import Modal -->
|
<!-- Import Modal -->
|
||||||
<div v-if="showImportModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
|
<div v-if="showImportModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
|
<div class="bg-white dark:bg-gray-800 shadow-xl w-full max-w-md">
|
||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
<h3 class="text-lg font-semibold mb-4">Importer des configurations</h3>
|
<h3 class="text-lg font-semibold mb-4">Importer des configurations</h3>
|
||||||
<textarea
|
<textarea
|
||||||
v-model="importData"
|
v-model="importData"
|
||||||
class="w-full h-40 p-3 border border-gray-300 dark:border-gray-600 rounded-md dark:bg-gray-700 dark:text-white"
|
class="w-full h-40 p-3 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-white"
|
||||||
placeholder="Collez ici le JSON des configurations à importer..."></textarea>
|
placeholder="Collez ici le JSON des configurations à importer..."></textarea>
|
||||||
|
|
||||||
<div class="flex justify-end space-x-3 mt-4">
|
<div class="flex justify-end space-x-3 mt-4">
|
||||||
@@ -93,7 +75,7 @@
|
|||||||
<button
|
<button
|
||||||
@click="handleImport"
|
@click="handleImport"
|
||||||
:disabled="importing || !importData.trim()"
|
:disabled="importing || !importData.trim()"
|
||||||
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white rounded-md">
|
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white">
|
||||||
{{ importing ? 'Import...' : 'Importer' }}
|
{{ importing ? 'Import...' : 'Importer' }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -109,10 +91,11 @@ import {
|
|||||||
ArrowPathIcon,
|
ArrowPathIcon,
|
||||||
ArrowUpTrayIcon,
|
ArrowUpTrayIcon,
|
||||||
ExclamationTriangleIcon,
|
ExclamationTriangleIcon,
|
||||||
|
HeartIcon,
|
||||||
PlusIcon
|
PlusIcon
|
||||||
} from '@heroicons/vue/24/outline';
|
} from '@heroicons/vue/24/outline';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { computed, onMounted, ref } from 'vue';
|
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
||||||
import { useContentSourceStore } from '../../application/store/contentSourceStore';
|
import { useContentSourceStore } from '../../application/store/contentSourceStore';
|
||||||
@@ -126,9 +109,13 @@ const {
|
|||||||
loadingSources,
|
loadingSources,
|
||||||
sourcesError,
|
sourcesError,
|
||||||
importing,
|
importing,
|
||||||
exporting
|
exporting,
|
||||||
|
checkingHealth,
|
||||||
} = storeToRefs(contentSourceStore);
|
} = storeToRefs(contentSourceStore);
|
||||||
|
|
||||||
|
// Mercure — écoute des mises à jour health
|
||||||
|
let mercureEventSource = null;
|
||||||
|
|
||||||
// Local state
|
// Local state
|
||||||
const showImportModal = ref(false);
|
const showImportModal = ref(false);
|
||||||
const showExportSuccess = ref(false);
|
const showExportSuccess = ref(false);
|
||||||
@@ -138,40 +125,45 @@ const importData = ref('');
|
|||||||
// Load sources on mount and clear current source
|
// Load sources on mount and clear current source
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
contentSourceStore.clearCurrentSource(); // Clear any previously loaded source
|
contentSourceStore.clearCurrentSource();
|
||||||
contentSourceStore.clearErrors(); // Clear any previous errors
|
contentSourceStore.clearErrors();
|
||||||
await contentSourceStore.loadSources();
|
await contentSourceStore.loadSources();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur lors du chargement des sources:', error);
|
console.error('Erreur lors du chargement des sources:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Écoute Mercure pour les mises à jour de health status
|
||||||
|
const url = new URL('/.well-known/mercure', window.location.href);
|
||||||
|
sources.value.forEach(source => {
|
||||||
|
url.searchParams.append('topic', `scrapers/health/${source.id}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
mercureEventSource = new EventSource(url.toString());
|
||||||
|
mercureEventSource.onmessage = (event) => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(event.data);
|
||||||
|
contentSourceStore.updateSourceHealth(data.sourceId, data.status, data.error);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Erreur parsing Mercure event:', e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
mercureEventSource?.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Toolbar configuration
|
// Toolbar configuration
|
||||||
const toolbarConfig = computed(() => ({
|
const toolbarConfig = computed(() => ({
|
||||||
leftSection: [
|
leftSection: [
|
||||||
{
|
{ type: 'label', text: 'Scrapers', class: 'text-sm font-medium' },
|
||||||
icon: ArrowPathIcon,
|
|
||||||
label: 'Actualiser',
|
|
||||||
type: 'button',
|
|
||||||
onClick: () => contentSourceStore.loadSources(),
|
|
||||||
active: loadingSources.value
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
rightSection: [
|
rightSection: [
|
||||||
{
|
{ type: 'button', icon: ArrowPathIcon, label: 'Actualiser', onClick: () => contentSourceStore.loadSources(), disabled: loadingSources.value },
|
||||||
icon: ArrowDownTrayIcon,
|
{ type: 'button', icon: HeartIcon, label: 'Tester tous', onClick: handleCheckAllHealth, disabled: checkingHealth.value },
|
||||||
label: 'Exporter',
|
{ type: 'button', icon: ArrowDownTrayIcon, label: 'Exporter', onClick: handleExport, disabled: exporting.value },
|
||||||
type: 'button',
|
{ type: 'button', icon: ArrowUpTrayIcon, label: 'Importer', onClick: () => showImportModal.value = true },
|
||||||
onClick: handleExport,
|
],
|
||||||
disabled: exporting.value
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: ArrowUpTrayIcon,
|
|
||||||
label: 'Importer',
|
|
||||||
type: 'button',
|
|
||||||
onClick: () => showImportModal.value = true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@@ -190,6 +182,14 @@ const openSourceLink = (url) => {
|
|||||||
window.open(url, '_blank');
|
window.open(url, '_blank');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function handleCheckAllHealth() {
|
||||||
|
try {
|
||||||
|
await contentSourceStore.checkAllHealth();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur lors du health check:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleExport() {
|
async function handleExport() {
|
||||||
try {
|
try {
|
||||||
const exportData = await contentSourceStore.exportSources();
|
const exportData = await contentSourceStore.exportSources();
|
||||||
|
|||||||
@@ -3,43 +3,36 @@
|
|||||||
<Toolbar :config="toolbarConfig" />
|
<Toolbar :config="toolbarConfig" />
|
||||||
|
|
||||||
<div class="overflow-y-auto flex-1">
|
<div class="overflow-y-auto flex-1">
|
||||||
<div class="container mx-auto px-4 py-6">
|
<div class="px-6 py-8">
|
||||||
<!-- Back Navigation -->
|
<section class="border-t border-gray-200 dark:border-gray-700 pt-6">
|
||||||
<div class="mb-6">
|
<!-- Loading State -->
|
||||||
<button
|
<div v-if="loadingCurrentSource" class="flex justify-center py-12">
|
||||||
@click="goBack"
|
<div class="animate-spin h-12 w-12 border-b-2 border-blue-500"></div>
|
||||||
class="flex items-center space-x-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200 transition-colors">
|
|
||||||
<ArrowLeftIcon class="w-5 h-5" />
|
|
||||||
<span>Retour aux configurations</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Loading State -->
|
|
||||||
<div v-if="loadingCurrentSource" class="flex justify-center py-12">
|
|
||||||
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Error State -->
|
|
||||||
<div v-else-if="currentSourceError" class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 rounded-lg p-4 mb-6">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<ExclamationTriangleIcon class="w-5 h-5 text-red-400 mr-2" />
|
|
||||||
<p class="text-red-800 dark:text-red-200">{{ currentSourceError }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Form -->
|
<!-- Error State -->
|
||||||
<div v-else class="max-w-4xl mx-auto">
|
<div v-else-if="currentSourceError" class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 p-4 mb-6">
|
||||||
<ContentSourceForm
|
<div class="flex items-center">
|
||||||
:source="currentSource"
|
<ExclamationTriangleIcon class="w-5 h-5 text-red-400 mr-2" />
|
||||||
:saving="saving"
|
<p class="text-red-800 dark:text-red-200">{{ currentSourceError }}</p>
|
||||||
:error="saveError"
|
</div>
|
||||||
@submit="handleSubmit"
|
</div>
|
||||||
@test="handleTest" />
|
|
||||||
</div>
|
<!-- Form -->
|
||||||
|
<div v-else>
|
||||||
|
<ContentSourceForm
|
||||||
|
ref="formRef"
|
||||||
|
:source="currentSource"
|
||||||
|
:saving="saving"
|
||||||
|
:error="saveError"
|
||||||
|
@submit="handleSubmit"
|
||||||
|
@test="handleTest" />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- Test Results Modal -->
|
<!-- Test Results Modal -->
|
||||||
<div v-if="showTestResults" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
|
<div v-if="showTestResults" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-4xl max-h-[80vh] overflow-hidden">
|
<div class="bg-white dark:bg-gray-800 shadow-xl w-full max-w-4xl max-h-[80vh] overflow-hidden">
|
||||||
<div class="p-6 border-b border-gray-200 dark:border-gray-600">
|
<div class="p-6 border-b border-gray-200 dark:border-gray-600">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<h3 class="text-lg font-semibold">Résultats du test</h3>
|
<h3 class="text-lg font-semibold">Résultats du test</h3>
|
||||||
@@ -54,7 +47,7 @@
|
|||||||
<div class="p-6 overflow-y-auto">
|
<div class="p-6 overflow-y-auto">
|
||||||
<!-- Loading state during test -->
|
<!-- Loading state during test -->
|
||||||
<div v-if="testingConfiguration" class="flex items-center justify-center py-8">
|
<div v-if="testingConfiguration" class="flex items-center justify-center py-8">
|
||||||
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500 mr-3"></div>
|
<div class="animate-spin h-8 w-8 border-b-2 border-blue-500 mr-3"></div>
|
||||||
<span class="text-gray-600">Test en cours...</span>
|
<span class="text-gray-600">Test en cours...</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -65,7 +58,7 @@
|
|||||||
<span class="font-medium">Test réussi !</span>
|
<span class="font-medium">Test réussi !</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-green-50 dark:bg-green-900 border border-green-200 dark:border-green-700 rounded-lg p-4">
|
<div class="bg-green-50 dark:bg-green-900 border border-green-200 dark:border-green-700 p-4">
|
||||||
<div class="grid grid-cols-2 gap-4 text-sm">
|
<div class="grid grid-cols-2 gap-4 text-sm">
|
||||||
<div>
|
<div>
|
||||||
<span class="font-medium text-green-800 dark:text-green-200">URL testée:</span>
|
<span class="font-medium text-green-800 dark:text-green-200">URL testée:</span>
|
||||||
@@ -92,10 +85,11 @@
|
|||||||
<img
|
<img
|
||||||
:src="imageUrl"
|
:src="imageUrl"
|
||||||
:alt="`Image ${index + 1}`"
|
:alt="`Image ${index + 1}`"
|
||||||
class="w-full h-32 object-cover rounded border border-gray-200 dark:border-gray-600"
|
class="w-full h-32 object-cover border border-gray-200 dark:border-gray-600"
|
||||||
|
referrerpolicy="no-referrer"
|
||||||
@error="handleImageError"
|
@error="handleImageError"
|
||||||
@load="handleImageLoad" />
|
@load="handleImageLoad" />
|
||||||
<div class="absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-30 transition-opacity rounded flex items-center justify-center">
|
<div class="absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-30 transition-opacity flex items-center justify-center">
|
||||||
<span class="text-white opacity-0 group-hover:opacity-100 text-sm font-medium">
|
<span class="text-white opacity-0 group-hover:opacity-100 text-sm font-medium">
|
||||||
Page {{ index + 1 }}
|
Page {{ index + 1 }}
|
||||||
</span>
|
</span>
|
||||||
@@ -107,7 +101,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="bg-yellow-50 dark:bg-yellow-900 border border-yellow-200 dark:border-yellow-700 rounded-lg p-4">
|
<div v-else class="bg-yellow-50 dark:bg-yellow-900 border border-yellow-200 dark:border-yellow-700 p-4">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<ExclamationTriangleIcon class="w-5 h-5 text-yellow-400 mr-2" />
|
<ExclamationTriangleIcon class="w-5 h-5 text-yellow-400 mr-2" />
|
||||||
<p class="text-yellow-800 dark:text-yellow-200">
|
<p class="text-yellow-800 dark:text-yellow-200">
|
||||||
@@ -125,7 +119,7 @@
|
|||||||
<span class="font-medium">Test échoué</span>
|
<span class="font-medium">Test échoué</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 rounded-lg p-4 mb-4">
|
<div class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 p-4 mb-4">
|
||||||
<div class="text-sm text-red-800 dark:text-red-200">
|
<div class="text-sm text-red-800 dark:text-red-200">
|
||||||
<div><strong>URL testée:</strong> {{ testResults.testedUrl || 'N/A' }}</div>
|
<div><strong>URL testée:</strong> {{ testResults.testedUrl || 'N/A' }}</div>
|
||||||
<div><strong>Type de scraping:</strong> {{ testResults.scrapingType || 'N/A' }}</div>
|
<div><strong>Type de scraping:</strong> {{ testResults.scrapingType || 'N/A' }}</div>
|
||||||
@@ -138,14 +132,14 @@
|
|||||||
<div
|
<div
|
||||||
v-for="(error, index) in testResults.errors"
|
v-for="(error, index) in testResults.errors"
|
||||||
:key="index"
|
:key="index"
|
||||||
class="bg-red-100 dark:bg-red-800 border-l-4 border-red-400 p-4 rounded">
|
class="bg-red-100 dark:bg-red-800 border-l-4 border-red-400 p-4">
|
||||||
<div class="flex items-start">
|
<div class="flex items-start">
|
||||||
<div class="flex-shrink-0">
|
<div class="flex-shrink-0">
|
||||||
<ExclamationTriangleIcon class="w-5 h-5 text-red-400" />
|
<ExclamationTriangleIcon class="w-5 h-5 text-red-400" />
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-3 flex-1">
|
<div class="ml-3 flex-1">
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
<span class="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-red-200 text-red-800 dark:bg-red-700 dark:text-red-200 mr-2">
|
<span class="inline-flex items-center px-2 py-1 text-xs font-medium bg-red-200 text-red-800 dark:bg-red-700 dark:text-red-200 mr-2">
|
||||||
{{ formatErrorType(error.type) }}
|
{{ formatErrorType(error.type) }}
|
||||||
</span>
|
</span>
|
||||||
<span class="text-sm font-medium text-red-800 dark:text-red-200">
|
<span class="text-sm font-medium text-red-800 dark:text-red-200">
|
||||||
@@ -155,7 +149,7 @@
|
|||||||
<p class="text-sm text-red-700 dark:text-red-300 mb-2">
|
<p class="text-sm text-red-700 dark:text-red-300 mb-2">
|
||||||
{{ error.message }}
|
{{ error.message }}
|
||||||
</p>
|
</p>
|
||||||
<div class="bg-red-50 dark:bg-red-900 rounded p-2">
|
<div class="bg-red-50 dark:bg-red-900 p-2">
|
||||||
<p class="text-xs text-red-600 dark:text-red-400">
|
<p class="text-xs text-red-600 dark:text-red-400">
|
||||||
<strong>Suggestion :</strong> {{ error.suggestion }}
|
<strong>Suggestion :</strong> {{ error.suggestion }}
|
||||||
</p>
|
</p>
|
||||||
@@ -166,7 +160,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Generic Error -->
|
<!-- Generic Error -->
|
||||||
<div v-else-if="testResults.error" class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 rounded p-3">
|
<div v-else-if="testResults.error" class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 p-3">
|
||||||
<code class="text-sm text-red-800 dark:text-red-200">
|
<code class="text-sm text-red-800 dark:text-red-200">
|
||||||
{{ testResults.error }}
|
{{ testResults.error }}
|
||||||
</code>
|
</code>
|
||||||
@@ -177,11 +171,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Success Message -->
|
<!-- Success Message -->
|
||||||
<div v-if="showSuccessMessage" class="fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg">
|
<div v-if="showSuccessMessage" class="fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 shadow-lg">
|
||||||
Configuration {{ isEditing ? 'mise à jour' : 'créée' }} avec succès !
|
Configuration {{ isEditing ? 'mise à jour' : 'créée' }} avec succès !
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Delete Modal -->
|
||||||
|
<ContentSourceDeleteModal
|
||||||
|
:is-open="isDeleteModalOpen"
|
||||||
|
:source="currentSource"
|
||||||
|
:is-loading="isDeleting"
|
||||||
|
:error="deleteError"
|
||||||
|
@close="isDeleteModalOpen = false"
|
||||||
|
@confirm="confirmDeleteSource" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -190,6 +193,8 @@ import {
|
|||||||
ArrowLeftIcon,
|
ArrowLeftIcon,
|
||||||
CheckCircleIcon,
|
CheckCircleIcon,
|
||||||
ExclamationTriangleIcon,
|
ExclamationTriangleIcon,
|
||||||
|
PencilSquareIcon,
|
||||||
|
TrashIcon,
|
||||||
XCircleIcon,
|
XCircleIcon,
|
||||||
XMarkIcon
|
XMarkIcon
|
||||||
} from '@heroicons/vue/24/outline';
|
} from '@heroicons/vue/24/outline';
|
||||||
@@ -199,6 +204,7 @@ import { useRoute, useRouter } from 'vue-router';
|
|||||||
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
||||||
import { useContentSourceStore } from '../../application/store/contentSourceStore';
|
import { useContentSourceStore } from '../../application/store/contentSourceStore';
|
||||||
import { ApiContentSourceRepository } from '../../infrastructure/api/apiContentSourceRepository';
|
import { ApiContentSourceRepository } from '../../infrastructure/api/apiContentSourceRepository';
|
||||||
|
import ContentSourceDeleteModal from '../components/ContentSourceDeleteModal.vue';
|
||||||
import ContentSourceForm from '../components/ContentSourceForm.vue';
|
import ContentSourceForm from '../components/ContentSourceForm.vue';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -214,11 +220,17 @@ const {
|
|||||||
saveError
|
saveError
|
||||||
} = storeToRefs(contentSourceStore);
|
} = storeToRefs(contentSourceStore);
|
||||||
|
|
||||||
|
// Form ref
|
||||||
|
const formRef = ref(null);
|
||||||
|
|
||||||
// Local state
|
// Local state
|
||||||
const showTestResults = ref(false);
|
const showTestResults = ref(false);
|
||||||
const showSuccessMessage = ref(false);
|
const showSuccessMessage = ref(false);
|
||||||
const testResults = ref({});
|
const testResults = ref({});
|
||||||
const testingConfiguration = ref(false);
|
const testingConfiguration = ref(false);
|
||||||
|
const isDeleteModalOpen = ref(false);
|
||||||
|
const isDeleting = ref(false);
|
||||||
|
const deleteError = ref(null);
|
||||||
|
|
||||||
const isEditing = computed(() => !!route.params.id);
|
const isEditing = computed(() => !!route.params.id);
|
||||||
|
|
||||||
@@ -233,16 +245,19 @@ onMounted(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Toolbar configuration
|
// Toolbar configuration
|
||||||
const toolbarConfig = {
|
const toolbarConfig = computed(() => ({
|
||||||
leftSection: [],
|
leftSection: [
|
||||||
rightSection: []
|
{ type: 'button', icon: ArrowLeftIcon, label: 'Retour', onClick: () => router.push({ name: 'scrapper-configurations' }) },
|
||||||
};
|
{ type: 'divider' },
|
||||||
|
{ type: 'label', text: isEditing.value ? 'Modifier la configuration' : 'Nouvelle configuration', class: 'text-sm font-medium' },
|
||||||
|
],
|
||||||
|
rightSection: [
|
||||||
|
...(isEditing.value ? [{ type: 'button', icon: TrashIcon, label: 'Supprimer', onClick: () => { isDeleteModalOpen.value = true; }, class: 'text-red-600 hover:text-red-700' }, { type: 'divider' }] : []),
|
||||||
|
{ type: 'button', icon: PencilSquareIcon, label: isEditing.value ? 'Mettre à jour' : 'Créer', onClick: () => formRef.value?.submitForm(), disabled: saving.value },
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
const goBack = () => {
|
|
||||||
router.push({ name: 'scrapper-configurations' });
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSubmit = async (formData) => {
|
const handleSubmit = async (formData) => {
|
||||||
try {
|
try {
|
||||||
if (isEditing.value) {
|
if (isEditing.value) {
|
||||||
@@ -279,6 +294,11 @@ const handleTest = async ({ configuration, testData }) => {
|
|||||||
testResults.value = {};
|
testResults.value = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Persister testSlug + testChapterNumber avant de lancer le test
|
||||||
|
if (isEditing.value) {
|
||||||
|
await contentSourceStore.updateSource(route.params.id, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
// Préparer les données selon le format de l'API
|
// Préparer les données selon le format de l'API
|
||||||
const testConfiguration = {
|
const testConfiguration = {
|
||||||
baseUrl: configuration.baseUrl,
|
baseUrl: configuration.baseUrl,
|
||||||
@@ -323,6 +343,21 @@ const handleImageLoad = (event) => {
|
|||||||
event.target.style.display = 'block';
|
event.target.style.display = 'block';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const confirmDeleteSource = async () => {
|
||||||
|
isDeleting.value = true;
|
||||||
|
deleteError.value = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await contentSourceStore.deleteSource(route.params.id);
|
||||||
|
isDeleteModalOpen.value = false;
|
||||||
|
await router.push({ name: 'scrapper-configurations' });
|
||||||
|
} catch (error) {
|
||||||
|
deleteError.value = error.message;
|
||||||
|
} finally {
|
||||||
|
isDeleting.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const formatErrorType = (type) => {
|
const formatErrorType = (type) => {
|
||||||
const typeMap = {
|
const typeMap = {
|
||||||
'selector_error': 'Erreur sélecteur',
|
'selector_error': 'Erreur sélecteur',
|
||||||
|
|||||||
110
assets/vue/app/domain/system/application/store/logsStore.js
Normal file
110
assets/vue/app/domain/system/application/store/logsStore.js
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import { defineStore } from 'pinia';
|
||||||
|
import { ApiJobRepository } from '../../../activity/infrastructure/api/ApiJobRepository';
|
||||||
|
|
||||||
|
const jobRepository = new ApiJobRepository();
|
||||||
|
|
||||||
|
// Statuts disponibles par filtre
|
||||||
|
const STATUS_MAP = {
|
||||||
|
failed: ['failed'],
|
||||||
|
completed: ['completed'],
|
||||||
|
all: ['failed', 'completed'],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useLogsStore = defineStore('logs', {
|
||||||
|
state: () => ({
|
||||||
|
logs: [],
|
||||||
|
loading: false,
|
||||||
|
error: null,
|
||||||
|
currentPage: 1,
|
||||||
|
totalPages: 0,
|
||||||
|
total: 0,
|
||||||
|
limit: 50,
|
||||||
|
hasNextPage: false,
|
||||||
|
hasPreviousPage: false,
|
||||||
|
sortBy: 'createdAt',
|
||||||
|
sortOrder: 'DESC',
|
||||||
|
statusFilter: 'failed', // 'failed' | 'completed' | 'all'
|
||||||
|
}),
|
||||||
|
|
||||||
|
getters: {
|
||||||
|
isLoading: state => state.loading,
|
||||||
|
hasError: state => !!state.error,
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
async loadLogs(page = null) {
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const collection = await jobRepository.getJobs({
|
||||||
|
page: page || this.currentPage,
|
||||||
|
limit: this.limit,
|
||||||
|
sortBy: this.sortBy,
|
||||||
|
sortOrder: this.sortOrder,
|
||||||
|
status: STATUS_MAP[this.statusFilter],
|
||||||
|
type: 'scraping_job',
|
||||||
|
});
|
||||||
|
|
||||||
|
this.logs = collection.items;
|
||||||
|
this.currentPage = collection.page;
|
||||||
|
this.total = collection.total;
|
||||||
|
this.hasNextPage = collection.hasNextPage;
|
||||||
|
this.hasPreviousPage = collection.hasPreviousPage;
|
||||||
|
this.totalPages = Math.ceil(this.total / this.limit);
|
||||||
|
} catch (error) {
|
||||||
|
this.error = error.message;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async goToPage(page) {
|
||||||
|
if (page >= 1 && page <= this.totalPages && page !== this.currentPage) {
|
||||||
|
this.currentPage = page;
|
||||||
|
await this.loadLogs(page);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateSort(sortBy, sortOrder) {
|
||||||
|
this.sortBy = sortBy;
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
this.currentPage = 1;
|
||||||
|
await this.loadLogs(1);
|
||||||
|
},
|
||||||
|
|
||||||
|
async setStatusFilter(filter) {
|
||||||
|
this.statusFilter = filter;
|
||||||
|
this.currentPage = 1;
|
||||||
|
await this.loadLogs(1);
|
||||||
|
},
|
||||||
|
|
||||||
|
async deleteLog(id) {
|
||||||
|
try {
|
||||||
|
await jobRepository.deleteJob(id);
|
||||||
|
this.logs = this.logs.filter(log => log.id !== id);
|
||||||
|
this.total = Math.max(0, this.total - 1);
|
||||||
|
this.totalPages = Math.ceil(this.total / this.limit);
|
||||||
|
} catch (error) {
|
||||||
|
this.error = error.message;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async deleteAllLogs() {
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await jobRepository.deleteJobs({
|
||||||
|
status: STATUS_MAP[this.statusFilter].join(','),
|
||||||
|
type: 'scraping_job',
|
||||||
|
});
|
||||||
|
await this.loadLogs(1);
|
||||||
|
} catch (error) {
|
||||||
|
this.error = error.message;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { defineStore } from 'pinia';
|
||||||
|
import { ApiStatusRepository } from '../../infrastructure/api/ApiStatusRepository';
|
||||||
|
|
||||||
|
const statusRepository = new ApiStatusRepository();
|
||||||
|
|
||||||
|
export const useStatusStore = defineStore('system-status', {
|
||||||
|
state: () => ({
|
||||||
|
status: null,
|
||||||
|
loading: false,
|
||||||
|
error: null,
|
||||||
|
}),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
async loadStatus() {
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
try {
|
||||||
|
this.status = await statusRepository.getStatus();
|
||||||
|
} catch (e) {
|
||||||
|
this.error = e.message ?? 'Erreur lors du chargement du statut système';
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
export class ApiStatusRepository {
|
||||||
|
async getStatus() {
|
||||||
|
const response = await fetch('/api/system/status', {
|
||||||
|
headers: { Accept: 'application/json' },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Erreur HTTP ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<StatusCard title="Chapitres" :icon="DocumentTextIcon">
|
||||||
|
<div class="flex items-baseline gap-2 mb-3">
|
||||||
|
<span class="text-3xl font-bold text-gray-900 dark:text-white">{{ status.totalChapters }}</span>
|
||||||
|
<span class="text-sm text-gray-500">total</span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-1 flex justify-between text-xs text-gray-500">
|
||||||
|
<span>{{ status.downloadedChapters }} téléchargés</span>
|
||||||
|
<span>{{ downloadedPercent }}%</span>
|
||||||
|
</div>
|
||||||
|
<div class="w-full h-2 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden">
|
||||||
|
<div
|
||||||
|
class="h-full bg-green-500 rounded-full transition-all"
|
||||||
|
:style="{ width: downloadedPercent + '%' }" />
|
||||||
|
</div>
|
||||||
|
<p class="mt-1 text-xs text-gray-400">{{ status.pendingChapters }} en attente</p>
|
||||||
|
</StatusCard>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { DocumentTextIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import StatusCard from './StatusCard.vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
status: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const downloadedPercent = computed(() => {
|
||||||
|
if (!props.status.totalChapters) return 0;
|
||||||
|
return Math.round((props.status.downloadedChapters / props.status.totalChapters) * 100);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
<template>
|
||||||
|
<StatusCard title="Jobs" :icon="CpuChipIcon">
|
||||||
|
<!-- Onglets -->
|
||||||
|
<div class="flex gap-1 mb-3 border-b border-gray-200 dark:border-gray-700">
|
||||||
|
<button
|
||||||
|
v-for="tab in tabs"
|
||||||
|
:key="tab.key"
|
||||||
|
@click="activeTab = tab.key"
|
||||||
|
class="px-3 py-1.5 text-xs font-medium transition-colors"
|
||||||
|
:class="activeTab === tab.key
|
||||||
|
? 'border-b-2 border-blue-500 text-blue-600 dark:text-blue-400'
|
||||||
|
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'">
|
||||||
|
{{ tab.label }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Contenu -->
|
||||||
|
<template v-if="activeTab === 'global'">
|
||||||
|
<div class="grid grid-cols-2 gap-2">
|
||||||
|
<Metric label="Total" :value="status.totalJobs" />
|
||||||
|
<Metric label="En cours" :value="status.inProgressJobs" color="blue" />
|
||||||
|
<Metric label="Terminés" :value="status.completedJobs" color="green" />
|
||||||
|
<Metric label="En attente" :value="status.pendingJobs" color="yellow" />
|
||||||
|
<Metric label="Échoués" :value="status.failedJobs" color="red" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else-if="activeTab === '24h'">
|
||||||
|
<div class="grid grid-cols-2 gap-2">
|
||||||
|
<Metric label="Total" :value="status.totalJobsLast24h" />
|
||||||
|
<Metric label="Terminés" :value="status.completedJobsLast24h" color="green" />
|
||||||
|
<Metric label="Échoués" :value="status.failedJobsLast24h" color="red" />
|
||||||
|
<div class="col-span-2">
|
||||||
|
<p class="text-xs text-gray-500 mb-1">Taux de succès</p>
|
||||||
|
<span class="text-xl font-bold" :class="rateColor(status.successRateLast24h)">
|
||||||
|
{{ status.successRateLast24h }}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<div class="grid grid-cols-2 gap-2">
|
||||||
|
<Metric label="Total" :value="status.totalJobsLast7d" />
|
||||||
|
<Metric label="Terminés" :value="status.completedJobsLast7d" color="green" />
|
||||||
|
<Metric label="Échoués" :value="status.failedJobsLast7d" color="red" />
|
||||||
|
<div class="col-span-2">
|
||||||
|
<p class="text-xs text-gray-500 mb-1">Taux de succès</p>
|
||||||
|
<span class="text-xl font-bold" :class="rateColor(status.successRateLast7d)">
|
||||||
|
{{ status.successRateLast7d }}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</StatusCard>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { CpuChipIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import StatusCard from './StatusCard.vue';
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
status: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const activeTab = ref('global');
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
|
{ key: 'global', label: 'Global' },
|
||||||
|
{ key: '24h', label: '24h' },
|
||||||
|
{ key: '7j', label: '7 jours' },
|
||||||
|
];
|
||||||
|
|
||||||
|
function rateColor(rate) {
|
||||||
|
if (rate >= 80) return 'text-green-600 dark:text-green-400';
|
||||||
|
if (rate >= 50) return 'text-yellow-600 dark:text-yellow-400';
|
||||||
|
return 'text-red-600 dark:text-red-400';
|
||||||
|
}
|
||||||
|
|
||||||
|
const Metric = {
|
||||||
|
props: {
|
||||||
|
label: String,
|
||||||
|
value: Number,
|
||||||
|
color: { type: String, default: 'gray' },
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<div>
|
||||||
|
<p class="text-xs text-gray-500">{{ label }}</p>
|
||||||
|
<p class="text-lg font-semibold"
|
||||||
|
:class="{
|
||||||
|
'text-gray-900 dark:text-white': color === 'gray',
|
||||||
|
'text-green-600 dark:text-green-400': color === 'green',
|
||||||
|
'text-red-600 dark:text-red-400': color === 'red',
|
||||||
|
'text-yellow-600 dark:text-yellow-400': color === 'yellow',
|
||||||
|
'text-blue-600 dark:text-blue-400': color === 'blue',
|
||||||
|
}">{{ value }}</p>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
</script>
|
||||||
131
assets/vue/app/domain/system/presentation/components/LogItem.vue
Normal file
131
assets/vue/app/domain/system/presentation/components/LogItem.vue
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
<template>
|
||||||
|
<div class="border-t border-gray-200 dark:border-gray-700 py-4 px-6">
|
||||||
|
<!-- Ligne 1 : Titre manga + chapitre + badge statut + date + bouton supprimer -->
|
||||||
|
<div class="flex items-start justify-between gap-4">
|
||||||
|
<div class="flex items-baseline gap-2 min-w-0">
|
||||||
|
<span class="font-semibold text-gray-900 dark:text-gray-100 truncate">
|
||||||
|
{{ log.context?.mangaTitle ?? 'Manga inconnu' }}
|
||||||
|
</span>
|
||||||
|
<span class="text-gray-400 dark:text-gray-500 text-sm shrink-0">•</span>
|
||||||
|
<span class="text-sm text-gray-600 dark:text-gray-400 shrink-0">
|
||||||
|
Chapitre {{ log.context?.chapterNumber ?? '?' }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
:class="[
|
||||||
|
'px-1.5 py-0.5 text-xs font-medium shrink-0',
|
||||||
|
log.status === 'completed'
|
||||||
|
? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400'
|
||||||
|
: 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400'
|
||||||
|
]">
|
||||||
|
{{ log.status === 'completed' ? 'Terminé' : 'Échec' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-3 shrink-0">
|
||||||
|
<span class="text-xs text-gray-400 dark:text-gray-500">{{ formattedDate }}</span>
|
||||||
|
<button
|
||||||
|
@click="$emit('delete', log.id)"
|
||||||
|
class="text-gray-400 hover:text-red-500 dark:text-gray-500 dark:hover:text-red-400 transition-colors"
|
||||||
|
title="Supprimer ce log">
|
||||||
|
<TrashIcon class="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Ligne 2 : Source + slug + durée -->
|
||||||
|
<div class="flex items-center justify-between mt-1 gap-4">
|
||||||
|
<div class="flex items-center gap-3 min-w-0 text-sm text-gray-500 dark:text-gray-400">
|
||||||
|
<!-- Domaine de la source (lien vers la page d'édition) -->
|
||||||
|
<RouterLink
|
||||||
|
v-if="source"
|
||||||
|
:to="{ name: 'scrapper-edit', params: { id: source.id } }"
|
||||||
|
class="flex items-center gap-1 hover:text-blue-500 dark:hover:text-blue-400 transition-colors shrink-0">
|
||||||
|
<GlobeAltIcon class="w-3.5 h-3.5" />
|
||||||
|
<span class="font-mono">{{ cleanDomain }}</span>
|
||||||
|
</RouterLink>
|
||||||
|
<span v-else class="font-mono shrink-0">
|
||||||
|
ID {{ log.context?.sourceId ?? '-' }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<!-- Badge type de scraping -->
|
||||||
|
<span
|
||||||
|
v-if="source?.scrapingType"
|
||||||
|
:class="[
|
||||||
|
'px-1.5 py-0.5 text-xs font-medium shrink-0',
|
||||||
|
source.scrapingType === 'Javascript'
|
||||||
|
? 'bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400'
|
||||||
|
: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400'
|
||||||
|
]">
|
||||||
|
{{ source.scrapingType }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<!-- Slug utilisé -->
|
||||||
|
<span v-if="log.context?.slug" class="truncate text-gray-400 dark:text-gray-500">
|
||||||
|
slug : <span class="font-mono">{{ log.context.slug }}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span v-if="duration !== null" class="text-xs text-gray-400 dark:text-gray-500 shrink-0">
|
||||||
|
{{ duration }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Ligne 3 : Message d'erreur -->
|
||||||
|
<div v-if="log.error" class="mt-2">
|
||||||
|
<p
|
||||||
|
:class="[
|
||||||
|
'text-sm font-mono text-red-600 dark:text-red-400',
|
||||||
|
!expanded && isLong ? 'line-clamp-1' : ''
|
||||||
|
]">
|
||||||
|
↳ {{ log.error }}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
v-if="isLong"
|
||||||
|
@click="expanded = !expanded"
|
||||||
|
class="mt-1 text-xs text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors">
|
||||||
|
{{ expanded ? 'voir moins' : 'voir plus' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { GlobeAltIcon, TrashIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
import { RouterLink } from 'vue-router';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
log: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
source: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
defineEmits(['delete']);
|
||||||
|
|
||||||
|
const expanded = ref(false);
|
||||||
|
|
||||||
|
const isLong = computed(() => props.log.error && props.log.error.length > 120);
|
||||||
|
|
||||||
|
const cleanDomain = computed(() => {
|
||||||
|
if (!props.source?.baseUrl) return null;
|
||||||
|
return props.source.baseUrl.replace(/^(https?:\/\/)?(www\.)?/, '').replace(/\/+$/, '');
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedDate = computed(() => {
|
||||||
|
if (!props.log.createdAt) return '';
|
||||||
|
const d = new Date(props.log.createdAt);
|
||||||
|
const pad = n => String(n).padStart(2, '0');
|
||||||
|
return `${pad(d.getDate())}/${pad(d.getMonth() + 1)}/${d.getFullYear()} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const duration = computed(() => {
|
||||||
|
if (!props.log.startedAt || !props.log.completedAt) return null;
|
||||||
|
const ms = new Date(props.log.completedAt) - new Date(props.log.startedAt);
|
||||||
|
if (ms < 0) return null;
|
||||||
|
return `${(ms / 1000).toLocaleString('fr-FR', { maximumFractionDigits: 1 })}s`;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<template>
|
||||||
|
<StatusCard title="Mangas" :icon="BookOpenIcon">
|
||||||
|
<div class="flex items-baseline gap-2 mb-3">
|
||||||
|
<span class="text-3xl font-bold text-gray-900 dark:text-white">{{ status.totalMangas }}</span>
|
||||||
|
<span class="text-sm text-gray-500">total</span>
|
||||||
|
<span class="ml-auto text-sm text-blue-600 dark:text-blue-400">{{ status.monitoredMangas }} suivis</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<span
|
||||||
|
v-for="(count, label) in status.mangasByStatus"
|
||||||
|
:key="label"
|
||||||
|
class="px-2 py-0.5 text-xs rounded-full border border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-400">
|
||||||
|
{{ label }}: {{ count }}
|
||||||
|
</span>
|
||||||
|
<span v-if="!hasStatuses" class="text-xs text-gray-400">Aucun statut disponible</span>
|
||||||
|
</div>
|
||||||
|
</StatusCard>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { BookOpenIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import StatusCard from './StatusCard.vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
status: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasStatuses = computed(() => Object.keys(props.status.mangasByStatus ?? {}).length > 0);
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<template>
|
||||||
|
<StatusCard title="Sources" :icon="GlobeAltIcon">
|
||||||
|
<div class="flex items-baseline gap-2 mb-3">
|
||||||
|
<span class="text-3xl font-bold text-gray-900 dark:text-white">{{ status.totalSources }}</span>
|
||||||
|
<span class="text-sm text-gray-500">sources configurées</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<span
|
||||||
|
v-for="(count, health) in status.sourcesByHealth"
|
||||||
|
:key="health"
|
||||||
|
class="px-2 py-0.5 text-xs rounded-full"
|
||||||
|
:class="healthBadgeClass(health)">
|
||||||
|
{{ health }}: {{ count }}
|
||||||
|
</span>
|
||||||
|
<span v-if="!hasSources" class="text-xs text-gray-400">Aucune source</span>
|
||||||
|
</div>
|
||||||
|
</StatusCard>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { GlobeAltIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import StatusCard from './StatusCard.vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
status: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasSources = computed(() => Object.keys(props.status.sourcesByHealth ?? {}).length > 0);
|
||||||
|
|
||||||
|
function healthBadgeClass(health) {
|
||||||
|
switch (health) {
|
||||||
|
case 'healthy': return 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200';
|
||||||
|
case 'unhealthy': return 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200';
|
||||||
|
default: return 'bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<div class="bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg p-4">
|
||||||
|
<div class="flex items-center gap-2 mb-3">
|
||||||
|
<component :is="icon" v-if="icon" class="w-5 h-5 text-blue-500 shrink-0" />
|
||||||
|
<h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300">{{ title }}</h3>
|
||||||
|
</div>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
defineProps({
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
type: [Object, Function],
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<template>
|
||||||
|
<StatusCard title="Stockage" :icon="CircleStackIcon">
|
||||||
|
<div class="flex items-baseline gap-2 mb-3">
|
||||||
|
<span class="text-3xl font-bold text-gray-900 dark:text-white">{{ status.storageUsedHuman }}</span>
|
||||||
|
<span class="text-sm text-gray-500">utilisés</span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-1 flex justify-between text-xs text-gray-500">
|
||||||
|
<span>{{ status.storageFreeHuman }} libres</span>
|
||||||
|
<span>{{ usedPercent }}%</span>
|
||||||
|
</div>
|
||||||
|
<div class="w-full h-2 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden">
|
||||||
|
<div
|
||||||
|
class="h-full rounded-full transition-all"
|
||||||
|
:class="usedPercent > 90 ? 'bg-red-500' : 'bg-blue-500'"
|
||||||
|
:style="{ width: usedPercent + '%' }" />
|
||||||
|
</div>
|
||||||
|
<p class="mt-1 text-xs text-gray-400">Total : {{ status.storageTotalHuman }}</p>
|
||||||
|
<p class="mt-1 text-xs text-gray-400 truncate" :title="status.storagePath">{{ status.storagePath }}</p>
|
||||||
|
</StatusCard>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { CircleStackIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import StatusCard from './StatusCard.vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
status: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const diskUsedBytes = computed(() => props.status.storageTotalBytes - props.status.storageFreeBytes);
|
||||||
|
|
||||||
|
const usedPercent = computed(() => {
|
||||||
|
if (!props.status.storageTotalBytes) return 0;
|
||||||
|
return Math.round((diskUsedBytes.value / props.status.storageTotalBytes) * 100);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<template>
|
||||||
|
<StatusCard title="Informations système" :icon="ServerIcon">
|
||||||
|
<dl class="space-y-2">
|
||||||
|
<div class="flex justify-between text-sm">
|
||||||
|
<dt class="text-gray-500">Version PHP</dt>
|
||||||
|
<dd class="font-medium text-gray-900 dark:text-white">{{ status.phpVersion }}</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-between text-sm">
|
||||||
|
<dt class="text-gray-500">Généré le</dt>
|
||||||
|
<dd class="font-medium text-gray-900 dark:text-white">{{ formattedDate }}</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</StatusCard>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { ServerIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import StatusCard from './StatusCard.vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
status: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedDate = computed(() => {
|
||||||
|
if (!props.status.generatedAt) return '';
|
||||||
|
return new Date(props.status.generatedAt).toLocaleString('fr-FR');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
165
assets/vue/app/domain/system/presentation/pages/LogsPage.vue
Normal file
165
assets/vue/app/domain/system/presentation/pages/LogsPage.vue
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex flex-col h-full">
|
||||||
|
<Toolbar :config="toolbarConfig" />
|
||||||
|
|
||||||
|
<div class="overflow-y-auto flex-1">
|
||||||
|
<section class="border-t border-gray-200 dark:border-gray-700">
|
||||||
|
<!-- Loading -->
|
||||||
|
<div v-if="isLoading" class="flex justify-center py-12">
|
||||||
|
<div class="animate-spin h-10 w-10 border-b-2 border-blue-500 rounded-full"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Error -->
|
||||||
|
<div v-else-if="hasError" class="px-6 py-8">
|
||||||
|
<div class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 p-4">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<ExclamationCircleIcon class="w-5 h-5 text-red-400 mr-2 shrink-0" />
|
||||||
|
<p class="text-red-800 dark:text-red-200">{{ error }}</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
@click="logsStore.loadLogs()"
|
||||||
|
class="mt-3 px-4 py-2 bg-red-600 text-white hover:bg-red-700">
|
||||||
|
Réessayer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Empty -->
|
||||||
|
<div v-else-if="!isLoading && logs.length === 0" class="flex flex-col items-center justify-center py-20 text-gray-400 dark:text-gray-500">
|
||||||
|
<ExclamationCircleIcon class="w-12 h-12 mb-3" />
|
||||||
|
<p class="text-base">Aucune erreur de scraping</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- List -->
|
||||||
|
<template v-else>
|
||||||
|
<LogItem
|
||||||
|
v-for="log in logs"
|
||||||
|
:key="log.id"
|
||||||
|
:log="log"
|
||||||
|
:source="getSource(log)"
|
||||||
|
@delete="handleDelete" />
|
||||||
|
</template>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Pagination -->
|
||||||
|
<Pagination
|
||||||
|
v-if="totalPages > 1"
|
||||||
|
:current-page="currentPage"
|
||||||
|
:total-pages="totalPages"
|
||||||
|
:total="total"
|
||||||
|
:limit="limit"
|
||||||
|
:has-next-page="hasNextPage"
|
||||||
|
:has-previous-page="hasPreviousPage"
|
||||||
|
@page-change="logsStore.goToPage" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ArrowPathIcon, ExclamationCircleIcon, TrashIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import { BarsArrowDownIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
import { computed, onMounted } from 'vue';
|
||||||
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
||||||
|
import Pagination from '../../../../shared/components/ui/Pagination.vue';
|
||||||
|
import { useContentSourceStore } from '../../../setting/application/store/contentSourceStore';
|
||||||
|
import { useLogsStore } from '../../application/store/logsStore';
|
||||||
|
import LogItem from '../components/LogItem.vue';
|
||||||
|
|
||||||
|
const logsStore = useLogsStore();
|
||||||
|
const contentSourceStore = useContentSourceStore();
|
||||||
|
const { sources } = storeToRefs(contentSourceStore);
|
||||||
|
|
||||||
|
const {
|
||||||
|
logs,
|
||||||
|
loading: isLoading,
|
||||||
|
error,
|
||||||
|
currentPage,
|
||||||
|
totalPages,
|
||||||
|
total,
|
||||||
|
limit,
|
||||||
|
hasNextPage,
|
||||||
|
hasPreviousPage,
|
||||||
|
sortBy,
|
||||||
|
sortOrder,
|
||||||
|
statusFilter,
|
||||||
|
} = storeToRefs(logsStore);
|
||||||
|
|
||||||
|
const hasError = computed(() => !!error.value);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
logsStore.loadLogs();
|
||||||
|
contentSourceStore.loadSources();
|
||||||
|
});
|
||||||
|
|
||||||
|
function getSource(log) {
|
||||||
|
const sourceId = log.context?.sourceId;
|
||||||
|
if (!sourceId) return null;
|
||||||
|
// eslint-disable-next-line eqeqeq
|
||||||
|
return sources.value.find(s => s.id == sourceId) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSortSelected = (by, order) => sortBy.value === by && sortOrder.value === order;
|
||||||
|
|
||||||
|
const STATUS_FILTERS = [
|
||||||
|
{ key: 'failed', label: 'Échecs' },
|
||||||
|
{ key: 'completed', label: 'Terminés' },
|
||||||
|
{ key: 'all', label: 'Tous' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const toolbarConfig = computed(() => ({
|
||||||
|
leftSection: [
|
||||||
|
{ type: 'label', text: 'Logs', class: 'text-sm font-medium' },
|
||||||
|
{ type: 'label', text: `(${total.value})`, class: 'text-sm text-gray-400' },
|
||||||
|
],
|
||||||
|
rightSection: [
|
||||||
|
...STATUS_FILTERS.map(f => ({
|
||||||
|
type: 'button',
|
||||||
|
label: f.label,
|
||||||
|
active: statusFilter.value === f.key,
|
||||||
|
onClick: () => logsStore.setStatusFilter(f.key),
|
||||||
|
})),
|
||||||
|
{ type: 'divider' },
|
||||||
|
{
|
||||||
|
type: 'dropdown',
|
||||||
|
icon: BarsArrowDownIcon,
|
||||||
|
label: 'Trier',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
label: 'Plus récent',
|
||||||
|
isSelected: isSortSelected('createdAt', 'DESC'),
|
||||||
|
onClick: () => logsStore.updateSort('createdAt', 'DESC'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Plus ancien',
|
||||||
|
isSelected: isSortSelected('createdAt', 'ASC'),
|
||||||
|
onClick: () => logsStore.updateSort('createdAt', 'ASC'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
icon: ArrowPathIcon,
|
||||||
|
label: 'Rafraîchir',
|
||||||
|
disabled: isLoading.value,
|
||||||
|
onClick: () => logsStore.loadLogs(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
icon: TrashIcon,
|
||||||
|
label: 'Tout supprimer',
|
||||||
|
disabled: isLoading.value || total.value === 0,
|
||||||
|
onClick: handleDeleteAll,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
|
async function handleDelete(id) {
|
||||||
|
await logsStore.deleteLog(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDeleteAll() {
|
||||||
|
if (!confirm('Supprimer tous les logs d\'erreur ? Cette action est irréversible.')) return;
|
||||||
|
await logsStore.deleteAllLogs();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex flex-col h-full">
|
||||||
|
<Toolbar :config="toolbarConfig" />
|
||||||
|
|
||||||
|
<div class="overflow-y-auto flex-1">
|
||||||
|
<!-- Loading -->
|
||||||
|
<div v-if="loading" class="flex justify-center py-12">
|
||||||
|
<div class="animate-spin h-10 w-10 border-b-2 border-blue-500 rounded-full"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Error -->
|
||||||
|
<div v-else-if="error" class="px-6 py-8">
|
||||||
|
<div class="bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 p-4 rounded">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<ExclamationCircleIcon class="w-5 h-5 text-red-400 mr-2 shrink-0" />
|
||||||
|
<p class="text-red-800 dark:text-red-200">{{ error }}</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
@click="statusStore.loadStatus()"
|
||||||
|
class="mt-3 px-4 py-2 bg-red-600 text-white hover:bg-red-700 rounded">
|
||||||
|
Réessayer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Données -->
|
||||||
|
<div v-else-if="status" class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 p-4">
|
||||||
|
<MangasStatusCard :status="status" />
|
||||||
|
<ChaptersStatusCard :status="status" />
|
||||||
|
<JobsStatusCard :status="status" />
|
||||||
|
<StorageStatusCard :status="status" />
|
||||||
|
<SourcesStatusCard :status="status" />
|
||||||
|
<SystemInfoCard :status="status" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ArrowPathIcon, ExclamationCircleIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
import { computed, onMounted } from 'vue';
|
||||||
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
||||||
|
import { useStatusStore } from '../../application/store/statusStore';
|
||||||
|
import ChaptersStatusCard from '../components/ChaptersStatusCard.vue';
|
||||||
|
import JobsStatusCard from '../components/JobsStatusCard.vue';
|
||||||
|
import MangasStatusCard from '../components/MangasStatusCard.vue';
|
||||||
|
import SourcesStatusCard from '../components/SourcesStatusCard.vue';
|
||||||
|
import StorageStatusCard from '../components/StorageStatusCard.vue';
|
||||||
|
import SystemInfoCard from '../components/SystemInfoCard.vue';
|
||||||
|
|
||||||
|
const statusStore = useStatusStore();
|
||||||
|
const { status, loading, error } = storeToRefs(statusStore);
|
||||||
|
|
||||||
|
onMounted(() => statusStore.loadStatus());
|
||||||
|
|
||||||
|
const toolbarConfig = computed(() => ({
|
||||||
|
leftSection: [
|
||||||
|
{ type: 'label', text: 'Statut système', class: 'text-sm font-medium' },
|
||||||
|
],
|
||||||
|
rightSection: [
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
icon: ArrowPathIcon,
|
||||||
|
label: 'Rafraîchir',
|
||||||
|
disabled: loading.value,
|
||||||
|
onClick: () => statusStore.loadStatus(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
</script>
|
||||||
@@ -3,30 +3,17 @@ import ActivityPage from '../domain/activity/presentation/pages/ActivityPage.vue
|
|||||||
import ConversionPage from '../domain/conversion/presentation/pages/ConversionPage.vue';
|
import ConversionPage from '../domain/conversion/presentation/pages/ConversionPage.vue';
|
||||||
import NewImportPage from '../domain/import/presentation/pages/NewImportPage.vue';
|
import NewImportPage from '../domain/import/presentation/pages/NewImportPage.vue';
|
||||||
import AddManga from '../domain/manga/presentation/pages/AddManga.vue';
|
import AddManga from '../domain/manga/presentation/pages/AddManga.vue';
|
||||||
|
import DiscoverPage from '../domain/manga/presentation/pages/DiscoverPage.vue';
|
||||||
import HomePage from '../domain/manga/presentation/pages/HomePage.vue';
|
import HomePage from '../domain/manga/presentation/pages/HomePage.vue';
|
||||||
import MangaDetails from '../domain/manga/presentation/pages/MangaDetails.vue';
|
import MangaDetails from '../domain/manga/presentation/pages/MangaDetails.vue';
|
||||||
import ChapterPage from '../domain/reader/presentation/pages/ChapterPage.vue';
|
import ChapterPage from '../domain/reader/presentation/pages/ChapterPage.vue';
|
||||||
import ScrapperConfigurations from '../domain/setting/presentation/pages/ScrapperConfigurations.vue';
|
import ScrapperConfigurations from '../domain/setting/presentation/pages/ScrapperConfigurations.vue';
|
||||||
import ScrapperEdit from '../domain/setting/presentation/pages/ScrapperEdit.vue';
|
import ScrapperEdit from '../domain/setting/presentation/pages/ScrapperEdit.vue';
|
||||||
import UserPreferencesPage from '../domain/setting/presentation/pages/UserPreferencesPage.vue';
|
import UserPreferencesPage from '../domain/setting/presentation/pages/UserPreferencesPage.vue';
|
||||||
|
import LogsPage from '../domain/system/presentation/pages/LogsPage.vue';
|
||||||
|
import StatusPage from '../domain/system/presentation/pages/StatusPage.vue';
|
||||||
import Layout from '../shared/components/layout/Layout.vue';
|
import Layout from '../shared/components/layout/Layout.vue';
|
||||||
|
|
||||||
// Placeholder component for new routes
|
|
||||||
const PlaceholderComponent = {
|
|
||||||
props: {
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
template: `
|
|
||||||
<div class="container mx-auto px-4 py-8">
|
|
||||||
<h1 class="text-2xl font-bold mb-4">{{ title }}</h1>
|
|
||||||
<p class="text-gray-600">Cette fonctionnalité sera bientôt disponible.</p>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
};
|
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
@@ -64,18 +51,10 @@ const routes = [
|
|||||||
name: 'import',
|
name: 'import',
|
||||||
component: NewImportPage
|
component: NewImportPage
|
||||||
},
|
},
|
||||||
// Pages placeholder avec chargement différé
|
|
||||||
{
|
|
||||||
path: '/manga/import',
|
|
||||||
name: 'manga-import',
|
|
||||||
component: PlaceholderComponent,
|
|
||||||
props: { title: 'Import de bibliothèque' }
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/manga/discover',
|
path: '/manga/discover',
|
||||||
name: 'discover',
|
name: 'discover',
|
||||||
component: PlaceholderComponent,
|
component: DiscoverPage
|
||||||
props: { title: 'Découvrir' }
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/convert',
|
path: '/convert',
|
||||||
@@ -90,21 +69,7 @@ const routes = [
|
|||||||
// Paramètres
|
// Paramètres
|
||||||
{
|
{
|
||||||
path: '/settings',
|
path: '/settings',
|
||||||
name: 'settings',
|
redirect: '/settings/scrappers',
|
||||||
component: PlaceholderComponent,
|
|
||||||
props: { title: 'Paramètres' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/settings/general',
|
|
||||||
name: 'settings-general',
|
|
||||||
component: PlaceholderComponent,
|
|
||||||
props: { title: 'Paramètres généraux' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/settings/folders',
|
|
||||||
name: 'settings-folders',
|
|
||||||
component: PlaceholderComponent,
|
|
||||||
props: { title: 'Gestion des dossiers' }
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/settings/scrappers',
|
path: '/settings/scrappers',
|
||||||
@@ -129,34 +94,18 @@ const routes = [
|
|||||||
// Système
|
// Système
|
||||||
{
|
{
|
||||||
path: '/system',
|
path: '/system',
|
||||||
name: 'system',
|
redirect: '/system/status',
|
||||||
component: PlaceholderComponent,
|
|
||||||
props: { title: 'Système' }
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/system/status',
|
path: '/system/status',
|
||||||
name: 'system-status',
|
name: 'system-status',
|
||||||
component: PlaceholderComponent,
|
component: StatusPage,
|
||||||
props: { title: 'Status du système' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/system/backup',
|
|
||||||
name: 'system-backup',
|
|
||||||
component: PlaceholderComponent,
|
|
||||||
props: { title: 'Sauvegarde' }
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/system/logs',
|
path: '/system/logs',
|
||||||
name: 'system-logs',
|
name: 'system-logs',
|
||||||
component: PlaceholderComponent,
|
component: LogsPage,
|
||||||
props: { title: 'Journaux système' }
|
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: '/system/updates',
|
|
||||||
name: 'system-updates',
|
|
||||||
component: PlaceholderComponent,
|
|
||||||
props: { title: 'Mises à jour' }
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -78,11 +78,9 @@ import MenuGroup from './sidebar/MenuGroup.vue';
|
|||||||
{
|
{
|
||||||
icon: Cog6ToothIcon,
|
icon: Cog6ToothIcon,
|
||||||
text: 'Paramètres',
|
text: 'Paramètres',
|
||||||
to: '/settings',
|
to: '/settings/scrappers',
|
||||||
id: 'settings',
|
id: 'settings',
|
||||||
subItems: [
|
subItems: [
|
||||||
{ icon: null, text: 'Général', to: '/settings/general' },
|
|
||||||
{ icon: null, text: 'Dossiers', to: '/settings/folders' },
|
|
||||||
{ icon: null, text: 'Scrappers', to: '/settings/scrappers' },
|
{ icon: null, text: 'Scrappers', to: '/settings/scrappers' },
|
||||||
{ icon: null, text: 'UI', to: '/settings/ui' }
|
{ icon: null, text: 'UI', to: '/settings/ui' }
|
||||||
]
|
]
|
||||||
@@ -90,13 +88,11 @@ import MenuGroup from './sidebar/MenuGroup.vue';
|
|||||||
{
|
{
|
||||||
icon: ComputerDesktopIcon,
|
icon: ComputerDesktopIcon,
|
||||||
text: 'Système',
|
text: 'Système',
|
||||||
to: '/system',
|
to: '/system/status',
|
||||||
id: 'system',
|
id: 'system',
|
||||||
subItems: [
|
subItems: [
|
||||||
{ icon: null, text: 'Status', to: '/system/status' },
|
{ icon: null, text: 'Status', to: '/system/status' },
|
||||||
{ icon: null, text: 'Backup', to: '/system/backup' },
|
|
||||||
{ icon: null, text: 'Logs', to: '/system/logs' },
|
{ icon: null, text: 'Logs', to: '/system/logs' },
|
||||||
{ icon: null, text: 'Updates', to: '/system/updates' }
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,35 +1,23 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="file-upload">
|
<div class="file-upload">
|
||||||
<label :for="inputId" class="block text-sm font-medium text-gray-700 mb-2">
|
<label :for="inputId" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
{{ label }}
|
{{ label }}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md"
|
class="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 dark:border-gray-600 border-dashed "
|
||||||
:class="{ 'border-green-500 bg-green-50': isDragOver, 'hover:border-gray-400': !isDragOver }"
|
:class="{ 'border-green-500 bg-green-50 dark:bg-green-900/20': isDragOver, 'hover:border-gray-400': !isDragOver }"
|
||||||
@drop.prevent="handleDrop"
|
@drop.prevent="handleDrop"
|
||||||
@dragover.prevent="isDragOver = true"
|
@dragover.prevent="isDragOver = true"
|
||||||
@dragleave.prevent="isDragOver = false"
|
@dragleave.prevent="isDragOver = false"
|
||||||
>
|
>
|
||||||
<div class="space-y-1 text-center">
|
<div class="space-y-1 text-center">
|
||||||
<svg
|
<ArrowUpTrayIcon class="mx-auto h-12 w-12 text-gray-400 dark:text-gray-500" />
|
||||||
class="mx-auto h-12 w-12 text-gray-400"
|
|
||||||
stroke="currentColor"
|
|
||||||
fill="none"
|
|
||||||
viewBox="0 0 48 48"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02"
|
|
||||||
stroke-width="2"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
|
|
||||||
<div class="flex text-sm text-gray-600">
|
<div class="flex text-sm text-gray-600">
|
||||||
<label
|
<label
|
||||||
:for="inputId"
|
:for="inputId"
|
||||||
class="relative cursor-pointer bg-white rounded-md font-medium text-green-600 hover:text-green-500"
|
class="relative cursor-pointer font-medium text-green-600 hover:text-green-500"
|
||||||
>
|
>
|
||||||
<span>Sélectionner des fichiers</span>
|
<span>Sélectionner des fichiers</span>
|
||||||
<input
|
<input
|
||||||
@@ -50,8 +38,8 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div v-if="selectedFiles.length > 0" class="mt-4">
|
<div v-if="selectedFiles.length > 0" class="mt-4">
|
||||||
<h4 class="text-sm font-medium text-gray-700 mb-2">Fichiers sélectionnés :</h4>
|
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Fichiers sélectionnés :</h4>
|
||||||
<ul class="text-xs text-gray-600 space-y-1">
|
<ul class="text-xs text-gray-600 dark:text-gray-400 space-y-1">
|
||||||
<li v-for="file in selectedFiles" :key="file.name" class="flex justify-between items-center">
|
<li v-for="file in selectedFiles" :key="file.name" class="flex justify-between items-center">
|
||||||
<span class="truncate">{{ file.name }}</span>
|
<span class="truncate">{{ file.name }}</span>
|
||||||
<span class="text-gray-400">{{ formatFileSize(file.size) }}</span>
|
<span class="text-gray-400">{{ formatFileSize(file.size) }}</span>
|
||||||
@@ -64,6 +52,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { ArrowUpTrayIcon } from '@heroicons/vue/24/outline';
|
||||||
import { ref, computed, watch } from 'vue';
|
import { ref, computed, watch } from 'vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|||||||
@@ -34,5 +34,6 @@ api_platform:
|
|||||||
- '%kernel.project_dir%/src/Domain/Reader/Infrastructure/ApiPlatform/Resource'
|
- '%kernel.project_dir%/src/Domain/Reader/Infrastructure/ApiPlatform/Resource'
|
||||||
- '%kernel.project_dir%/src/Domain/Conversion/Infrastructure/ApiPlatform/Resource'
|
- '%kernel.project_dir%/src/Domain/Conversion/Infrastructure/ApiPlatform/Resource'
|
||||||
- '%kernel.project_dir%/src/Domain/Shared/Infrastructure/ApiPlatform/Resource'
|
- '%kernel.project_dir%/src/Domain/Shared/Infrastructure/ApiPlatform/Resource'
|
||||||
|
- '%kernel.project_dir%/src/Domain/System/Infrastructure/ApiPlatform/Resource'
|
||||||
patch_formats:
|
patch_formats:
|
||||||
json: ['application/merge-patch+json']
|
json: ['application/merge-patch+json']
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ framework:
|
|||||||
command.bus:
|
command.bus:
|
||||||
middleware:
|
middleware:
|
||||||
- validation
|
- validation
|
||||||
- doctrine_transaction
|
|
||||||
event.bus:
|
event.bus:
|
||||||
default_middleware: allow_no_handlers
|
default_middleware: allow_no_handlers
|
||||||
|
|
||||||
|
|||||||
@@ -180,6 +180,13 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: messenger.message_handler, bus: command.bus }
|
- { name: messenger.message_handler, bus: command.bus }
|
||||||
|
|
||||||
|
# Scraper Health Check
|
||||||
|
App\Domain\Scraping\Domain\Contract\Repository\ContentSourceForHealthCheckInterface:
|
||||||
|
alias: App\Domain\Setting\Infrastructure\Persistence\Repository\DoctrineContentSourceForHealthCheckRepository
|
||||||
|
|
||||||
|
App\Domain\Scraping\Domain\Contract\Repository\ContentSourceHealthRepositoryInterface:
|
||||||
|
alias: App\Domain\Setting\Infrastructure\Persistence\Repository\DoctrineContentSourceForHealthCheckRepository
|
||||||
|
|
||||||
# Import Domain Services
|
# Import Domain Services
|
||||||
App\Domain\Import\Infrastructure\Service\FilenameAnalyzer: ~
|
App\Domain\Import\Infrastructure\Service\FilenameAnalyzer: ~
|
||||||
|
|
||||||
@@ -193,3 +200,12 @@ services:
|
|||||||
# Import Domain API Platform Services
|
# Import Domain API Platform Services
|
||||||
App\Domain\Import\Infrastructure\ApiPlatform\State\Processor\AnalyzeFilenameStateProcessor: ~
|
App\Domain\Import\Infrastructure\ApiPlatform\State\Processor\AnalyzeFilenameStateProcessor: ~
|
||||||
App\Domain\Import\Infrastructure\ApiPlatform\State\Processor\ImportFileStateProcessor: ~
|
App\Domain\Import\Infrastructure\ApiPlatform\State\Processor\ImportFileStateProcessor: ~
|
||||||
|
|
||||||
|
# System Domain
|
||||||
|
App\Domain\System\Domain\Contract\Repository\SystemStatusRepositoryInterface:
|
||||||
|
alias: App\Domain\System\Infrastructure\Persistence\Repository\DoctrineSystemStatusRepository
|
||||||
|
|
||||||
|
App\Domain\System\Application\QueryHandler\GetSystemStatusQueryHandler:
|
||||||
|
arguments:
|
||||||
|
$mangaDataPath: '%env(resolve:MANGA_DATA_PATH)%'
|
||||||
|
$imagesStoragePath: '%kernel.project_dir%/public/images'
|
||||||
|
|||||||
41
migrations/Version20260315221706.php
Normal file
41
migrations/Version20260315221706.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20260315221706 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE content_source ADD test_slug VARCHAR(255) DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE content_source ADD test_chapter_number DOUBLE PRECISION DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE content_source ADD health_status VARCHAR(20) DEFAULT \'unknown\' NOT NULL');
|
||||||
|
$this->addSql('ALTER TABLE content_source ADD health_last_tested_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE content_source ADD health_last_error TEXT DEFAULT NULL');
|
||||||
|
$this->addSql('COMMENT ON COLUMN content_source.health_last_tested_at IS \'(DC2Type:datetime_immutable)\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('CREATE SCHEMA public');
|
||||||
|
$this->addSql('ALTER TABLE content_source DROP test_slug');
|
||||||
|
$this->addSql('ALTER TABLE content_source DROP test_chapter_number');
|
||||||
|
$this->addSql('ALTER TABLE content_source DROP health_status');
|
||||||
|
$this->addSql('ALTER TABLE content_source DROP health_last_tested_at');
|
||||||
|
$this->addSql('ALTER TABLE content_source DROP health_last_error');
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/Domain/Manga/Application/Query/DiscoverManga.php
Normal file
7
src/Domain/Manga/Application/Query/DiscoverManga.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Manga\Application\Query;
|
||||||
|
|
||||||
|
readonly class DiscoverManga
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Manga\Application\QueryHandler;
|
||||||
|
|
||||||
|
use App\Domain\Manga\Application\Query\DiscoverManga;
|
||||||
|
use App\Domain\Manga\Application\Response\MangaSearchItem;
|
||||||
|
use App\Domain\Manga\Application\Response\MangaSearchResponse;
|
||||||
|
use App\Domain\Manga\Domain\Contract\Provider\MangaProviderInterface;
|
||||||
|
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
|
||||||
|
use App\Domain\Manga\Domain\Model\Manga;
|
||||||
|
|
||||||
|
readonly class DiscoverMangaHandler
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private MangaRepositoryInterface $mangaRepository,
|
||||||
|
private MangaProviderInterface $mangaProvider
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(DiscoverManga $query): MangaSearchResponse
|
||||||
|
{
|
||||||
|
$localMangas = $this->mangaRepository->findAll(page: 1, limit: 1000);
|
||||||
|
|
||||||
|
$ownedExternalIds = [];
|
||||||
|
$mangasWithRating = [];
|
||||||
|
foreach ($localMangas as $manga) {
|
||||||
|
if (!$manga->getExternalId()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$ownedExternalIds[] = $manga->getExternalId()->getValue();
|
||||||
|
$mangasWithRating[] = $manga;
|
||||||
|
}
|
||||||
|
|
||||||
|
usort($mangasWithRating, fn ($a, $b) => ($b->getRating() ?? 0) <=> ($a->getRating() ?? 0));
|
||||||
|
$sourceIds = array_map(
|
||||||
|
fn (Manga $m) => $m->getExternalId()->getValue(),
|
||||||
|
array_slice($mangasWithRating, 0, 5)
|
||||||
|
);
|
||||||
|
|
||||||
|
$collection = $this->mangaProvider->discover($sourceIds);
|
||||||
|
|
||||||
|
$recommendations = array_values(array_filter(
|
||||||
|
$collection->getItems(),
|
||||||
|
fn (Manga $m) => $m->getExternalId() === null
|
||||||
|
|| !in_array($m->getExternalId()->getValue(), $ownedExternalIds, true)
|
||||||
|
));
|
||||||
|
|
||||||
|
return new MangaSearchResponse(
|
||||||
|
array_map(
|
||||||
|
fn (Manga $manga, int $index) => new MangaSearchItem(
|
||||||
|
id: $index,
|
||||||
|
externalId: $manga->getExternalId()->getValue(),
|
||||||
|
title: $manga->getTitle()->getValue(),
|
||||||
|
slug: $manga->getSlug()->getValue(),
|
||||||
|
description: $manga->getDescription(),
|
||||||
|
author: $manga->getAuthor(),
|
||||||
|
publicationYear: $manga->getPublicationYear(),
|
||||||
|
genres: $manga->getGenres(),
|
||||||
|
status: $manga->getStatus(),
|
||||||
|
imageUrl: $manga->getImageUrl(),
|
||||||
|
thumbnailUrl: $manga->getImageUrls()?->getThumbnail(),
|
||||||
|
rating: $manga->getRating()
|
||||||
|
),
|
||||||
|
$recommendations,
|
||||||
|
array_keys($recommendations)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,18 +23,60 @@ readonly class GetMangaChaptersHandler
|
|||||||
throw new MangaNotFoundException();
|
throw new MangaNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$chapters = $this->mangaRepository->findChapters(
|
$allChapters = $this->mangaRepository->findAllChapters(
|
||||||
mangaId: $query->mangaId,
|
mangaId: $query->mangaId,
|
||||||
page: $query->page,
|
sortOrder: 'asc'
|
||||||
limit: $query->limit,
|
|
||||||
sortOrder: $query->sortOrder
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$total = $this->mangaRepository->countChapters($query->mangaId);
|
$grouped = $this->groupChapters($allChapters);
|
||||||
|
|
||||||
|
if ($query->sortOrder === 'desc') {
|
||||||
|
usort($grouped, fn (ChapterResponse $a, ChapterResponse $b) => $b->number <=> $a->number);
|
||||||
|
}
|
||||||
|
|
||||||
|
$total = count($grouped);
|
||||||
|
$offset = ($query->page - 1) * $query->limit;
|
||||||
|
$paginatedChapters = array_slice($grouped, $offset, $query->limit);
|
||||||
|
|
||||||
return new ChapterListResponse(
|
return new ChapterListResponse(
|
||||||
chapters: array_map(
|
chapters: $paginatedChapters,
|
||||||
fn (Chapter $chapter) => new ChapterResponse(
|
total: $total,
|
||||||
|
page: $query->page,
|
||||||
|
limit: $query->limit
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param Chapter[] $chapters */
|
||||||
|
private function groupChapters(array $chapters): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
$currentGroup = [];
|
||||||
|
$currentPagesDir = null;
|
||||||
|
$currentVolume = null;
|
||||||
|
|
||||||
|
foreach ($chapters as $chapter) {
|
||||||
|
$pagesDir = $chapter->getPagesDirectory();
|
||||||
|
$volume = $chapter->getVolume();
|
||||||
|
|
||||||
|
if ($pagesDir !== null && $volume !== null) {
|
||||||
|
if ($pagesDir === $currentPagesDir && $volume === $currentVolume) {
|
||||||
|
$currentGroup[] = $chapter;
|
||||||
|
} else {
|
||||||
|
if (!empty($currentGroup)) {
|
||||||
|
$result[] = $this->buildVolumeGroupResponse($currentGroup);
|
||||||
|
}
|
||||||
|
$currentGroup = [$chapter];
|
||||||
|
$currentPagesDir = $pagesDir;
|
||||||
|
$currentVolume = $volume;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!empty($currentGroup)) {
|
||||||
|
$result[] = $this->buildVolumeGroupResponse($currentGroup);
|
||||||
|
$currentGroup = [];
|
||||||
|
$currentPagesDir = null;
|
||||||
|
$currentVolume = null;
|
||||||
|
}
|
||||||
|
$result[] = new ChapterResponse(
|
||||||
id: $chapter->getId(),
|
id: $chapter->getId(),
|
||||||
number: $chapter->getNumber(),
|
number: $chapter->getNumber(),
|
||||||
title: $chapter->getTitle(),
|
title: $chapter->getTitle(),
|
||||||
@@ -42,12 +84,39 @@ readonly class GetMangaChaptersHandler
|
|||||||
isVisible: $chapter->isVisible(),
|
isVisible: $chapter->isVisible(),
|
||||||
pagesDirectory: $chapter->getPagesDirectory(),
|
pagesDirectory: $chapter->getPagesDirectory(),
|
||||||
createdAt: $chapter->getCreatedAt()->format(\DateTimeInterface::RFC3339)
|
createdAt: $chapter->getCreatedAt()->format(\DateTimeInterface::RFC3339)
|
||||||
),
|
);
|
||||||
$chapters
|
}
|
||||||
),
|
}
|
||||||
total: $total,
|
|
||||||
page: $query->page,
|
if (!empty($currentGroup)) {
|
||||||
limit: $query->limit
|
$result[] = $this->buildVolumeGroupResponse($currentGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param Chapter[] $group */
|
||||||
|
private function buildVolumeGroupResponse(array $group): ChapterResponse
|
||||||
|
{
|
||||||
|
$first = $group[0];
|
||||||
|
$numbers = array_map(fn (Chapter $c) => $c->getNumber(), $group);
|
||||||
|
$min = min($numbers);
|
||||||
|
$max = max($numbers);
|
||||||
|
|
||||||
|
$fmt = fn (float $n) => $n == (int) $n ? (string) (int) $n : (string) $n;
|
||||||
|
$range = count($group) > 1 ? $fmt($min) . '-' . $fmt($max) : $fmt($min);
|
||||||
|
|
||||||
|
return new ChapterResponse(
|
||||||
|
id: $first->getId(),
|
||||||
|
number: $first->getNumber(),
|
||||||
|
title: $first->getTitle(),
|
||||||
|
volume: $first->getVolume(),
|
||||||
|
isVisible: $first->isVisible(),
|
||||||
|
pagesDirectory: $first->getPagesDirectory(),
|
||||||
|
createdAt: $first->getCreatedAt()->format(\DateTimeInterface::RFC3339),
|
||||||
|
isVolumeGroup: true,
|
||||||
|
volumeChaptersRange: $range,
|
||||||
|
volumeChapterCount: count($group)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ readonly class ChapterResponse
|
|||||||
public ?int $volume,
|
public ?int $volume,
|
||||||
public bool $isVisible,
|
public bool $isVisible,
|
||||||
public ?string $pagesDirectory,
|
public ?string $pagesDirectory,
|
||||||
public string $createdAt
|
public string $createdAt,
|
||||||
|
public bool $isVolumeGroup = false,
|
||||||
|
public ?string $volumeChaptersRange = null,
|
||||||
|
public int $volumeChapterCount = 0,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,4 +93,24 @@ interface MangadexClientInterface
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public function getManga(string $mangaId): array;
|
public function getManga(string $mangaId): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{
|
||||||
|
* data: array<array{
|
||||||
|
* id: string,
|
||||||
|
* attributes: array{
|
||||||
|
* title: array<string, string>,
|
||||||
|
* description: array<string, string>,
|
||||||
|
* year: ?int,
|
||||||
|
* status: string,
|
||||||
|
* tags: array<array{attributes: array{name: array<string, string>}}>
|
||||||
|
* },
|
||||||
|
* relationships: array<array{
|
||||||
|
* type: string,
|
||||||
|
* attributes: array{name: string|null, fileName: string|null}
|
||||||
|
* }>
|
||||||
|
* }>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public function getMangaRecommendations(string $mangaId): array;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,9 @@ interface MangaProviderInterface
|
|||||||
public function search(string $title): MangaCollection;
|
public function search(string $title): MangaCollection;
|
||||||
|
|
||||||
public function findByExternalId(ExternalId $externalId): ?Manga;
|
public function findByExternalId(ExternalId $externalId): ?Manga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string[] $sourceExternalIds IDs MangaDex des manga sources
|
||||||
|
*/
|
||||||
|
public function discover(array $sourceExternalIds): MangaCollection;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ interface MangaRepositoryInterface
|
|||||||
// --- Chapters (read) ---
|
// --- Chapters (read) ---
|
||||||
|
|
||||||
public function findChapters(string $mangaId, int $page = 1, int $limit = 20, string $sortOrder = 'desc'): array;
|
public function findChapters(string $mangaId, int $page = 1, int $limit = 20, string $sortOrder = 'desc'): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Chapter[]
|
||||||
|
*/
|
||||||
|
public function findAllChapters(string $mangaId, string $sortOrder = 'desc'): array;
|
||||||
public function countChapters(string $mangaId): int;
|
public function countChapters(string $mangaId): int;
|
||||||
public function countAvailableChapters(string $mangaId): int;
|
public function countAvailableChapters(string $mangaId): int;
|
||||||
public function findChapterById(string $id): ?Chapter;
|
public function findChapterById(string $id): ?Chapter;
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ readonly class ChapterListItem
|
|||||||
public ?int $volume,
|
public ?int $volume,
|
||||||
public bool $isVisible,
|
public bool $isVisible,
|
||||||
public bool $isAvailable,
|
public bool $isAvailable,
|
||||||
public string $createdAt
|
public string $createdAt,
|
||||||
|
public bool $isVolumeGroup = false,
|
||||||
|
public ?string $volumeChaptersRange = null,
|
||||||
|
public int $volumeChapterCount = 0,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Manga\Infrastructure\ApiPlatform\Resource;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use App\Domain\Manga\Infrastructure\ApiPlatform\Dto\MangaSearchCollection;
|
||||||
|
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider\DiscoverMangaStateProvider;
|
||||||
|
|
||||||
|
#[ApiResource(
|
||||||
|
shortName: 'MangaDiscover',
|
||||||
|
operations: [
|
||||||
|
new Get(
|
||||||
|
uriTemplate: '/manga-discover',
|
||||||
|
output: MangaSearchCollection::class,
|
||||||
|
provider: DiscoverMangaStateProvider::class
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
class MangaDiscoverResource
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProviderInterface;
|
||||||
|
use App\Domain\Manga\Application\Query\DiscoverManga;
|
||||||
|
use App\Domain\Manga\Application\QueryHandler\DiscoverMangaHandler;
|
||||||
|
use App\Domain\Manga\Infrastructure\ApiPlatform\Dto\MangaSearchCollection;
|
||||||
|
use App\Domain\Manga\Infrastructure\ApiPlatform\Dto\MangaSearchItem;
|
||||||
|
|
||||||
|
readonly class DiscoverMangaStateProvider implements ProviderInterface
|
||||||
|
{
|
||||||
|
public function __construct(private DiscoverMangaHandler $handler)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): MangaSearchCollection
|
||||||
|
{
|
||||||
|
$response = $this->handler->handle(new DiscoverManga());
|
||||||
|
|
||||||
|
return new MangaSearchCollection(
|
||||||
|
items: array_map(
|
||||||
|
fn ($item) => new MangaSearchItem(
|
||||||
|
externalId: $item->externalId,
|
||||||
|
title: $item->title,
|
||||||
|
slug: $item->slug,
|
||||||
|
description: $item->description,
|
||||||
|
author: $item->author,
|
||||||
|
publicationYear: $item->publicationYear,
|
||||||
|
genres: $item->genres,
|
||||||
|
status: $item->status,
|
||||||
|
imageUrl: $item->imageUrl,
|
||||||
|
thumbnailUrl: $item->thumbnailUrl,
|
||||||
|
rating: $item->rating
|
||||||
|
),
|
||||||
|
$response->items
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,7 +54,10 @@ readonly class GetMangaChaptersStateProvider implements ProviderInterface
|
|||||||
volume: $chapter->volume,
|
volume: $chapter->volume,
|
||||||
isVisible: $chapter->isVisible,
|
isVisible: $chapter->isVisible,
|
||||||
isAvailable: $chapter->pagesDirectory !== null,
|
isAvailable: $chapter->pagesDirectory !== null,
|
||||||
createdAt: $chapter->createdAt
|
createdAt: $chapter->createdAt,
|
||||||
|
isVolumeGroup: $chapter->isVolumeGroup,
|
||||||
|
volumeChaptersRange: $chapter->volumeChaptersRange,
|
||||||
|
volumeChapterCount: $chapter->volumeChapterCount,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,35 @@ class MangadexClient implements MangadexClientInterface
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMangaRecommendations(string $mangaId): array
|
||||||
|
{
|
||||||
|
// L'endpoint retourne des objets manga_recommendation avec des relationships
|
||||||
|
// vers les manga (sans détails). Il faut d'abord récupérer les IDs, puis
|
||||||
|
// fetcher les manga en batch avec leurs détails complets.
|
||||||
|
$recommendations = $this->get('/manga/' . $mangaId . '/recommendation');
|
||||||
|
|
||||||
|
$recommendedIds = [];
|
||||||
|
foreach ($recommendations['data'] ?? [] as $item) {
|
||||||
|
foreach ($item['relationships'] ?? [] as $rel) {
|
||||||
|
if ($rel['type'] === 'manga' && $rel['id'] !== $mangaId) {
|
||||||
|
$recommendedIds[] = $rel['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($recommendedIds)) {
|
||||||
|
return ['data' => []];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->get('/manga', [
|
||||||
|
'ids' => $recommendedIds,
|
||||||
|
'includes' => ['cover_art', 'author'],
|
||||||
|
'contentRating' => ['safe', 'suggestive', 'erotica'],
|
||||||
|
'excludedTags' => self::EXCLUDED_TAGS,
|
||||||
|
'limit' => count($recommendedIds),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
private function get(string $endpoint, array $params = []): array
|
private function get(string $endpoint, array $params = []): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -185,6 +185,21 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findAllChapters(string $mangaId, string $sortOrder = 'desc'): array
|
||||||
|
{
|
||||||
|
$queryBuilder = $this->entityManager->createQueryBuilder()
|
||||||
|
->select('c')
|
||||||
|
->from(EntityChapter::class, 'c')
|
||||||
|
->where('c.manga = :mangaId')
|
||||||
|
->orderBy('c.number', $sortOrder)
|
||||||
|
->setParameter('mangaId', $mangaId);
|
||||||
|
|
||||||
|
return array_map(
|
||||||
|
fn (EntityChapter $entity) => $this->toChapterDomain($entity),
|
||||||
|
$queryBuilder->getQuery()->getResult()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function countChapters(string $mangaId): int
|
public function countChapters(string $mangaId): int
|
||||||
{
|
{
|
||||||
return $this->entityManager->createQueryBuilder()
|
return $this->entityManager->createQueryBuilder()
|
||||||
|
|||||||
@@ -135,6 +135,55 @@ readonly class MangadexProvider implements MangaProviderInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function discover(array $sourceExternalIds): MangaCollection
|
||||||
|
{
|
||||||
|
if (empty($sourceExternalIds)) {
|
||||||
|
return new MangaCollection([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compter les votes : un manga recommandé par plusieurs sources est plus pertinent.
|
||||||
|
// On conserve aussi la position d'apparition pour départager les ex-aequo.
|
||||||
|
$votes = [];
|
||||||
|
$firstPosition = [];
|
||||||
|
$resultsById = [];
|
||||||
|
$position = 0;
|
||||||
|
|
||||||
|
foreach ($sourceExternalIds as $externalId) {
|
||||||
|
try {
|
||||||
|
$response = $this->client->getMangaRecommendations($externalId);
|
||||||
|
foreach ($response['data'] ?? [] as $result) {
|
||||||
|
$id = $result['id'];
|
||||||
|
$votes[$id] = ($votes[$id] ?? 0) + 1;
|
||||||
|
if (!isset($firstPosition[$id])) {
|
||||||
|
$firstPosition[$id] = $position++;
|
||||||
|
$resultsById[$id] = $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Exception) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($resultsById)) {
|
||||||
|
return new MangaCollection([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trier : votes décroissants (multi-sources = plus pertinent), puis position croissante (score API)
|
||||||
|
uksort($resultsById, function (string $a, string $b) use ($votes, $firstPosition): int {
|
||||||
|
$voteDiff = $votes[$b] - $votes[$a];
|
||||||
|
if ($voteDiff !== 0) {
|
||||||
|
return $voteDiff;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $firstPosition[$a] <=> $firstPosition[$b];
|
||||||
|
});
|
||||||
|
|
||||||
|
$mangas = $this->createMangasFromResults(array_values($resultsById));
|
||||||
|
$this->enrichWithRatings($mangas);
|
||||||
|
|
||||||
|
return new MangaCollection($mangas);
|
||||||
|
}
|
||||||
|
|
||||||
public function findByExternalId(ExternalId $externalId): ?Manga
|
public function findByExternalId(ExternalId $externalId): ?Manga
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Scraping\Application\Command;
|
||||||
|
|
||||||
|
readonly class CheckAllScrapersHealth
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -5,7 +5,8 @@ namespace App\Domain\Scraping\Application\Command;
|
|||||||
readonly class ScrapeChapter
|
readonly class ScrapeChapter
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $chapterId
|
public string $chapterId,
|
||||||
|
public string $jobId
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Scraping\Application\CommandHandler;
|
||||||
|
|
||||||
|
use App\Domain\Scraping\Application\Command\CheckAllScrapersHealth;
|
||||||
|
use App\Domain\Scraping\Application\Command\TestScraperConfiguration;
|
||||||
|
use App\Domain\Scraping\Domain\Contract\Repository\ContentSourceForHealthCheckInterface;
|
||||||
|
use App\Domain\Scraping\Domain\Contract\Repository\ContentSourceHealthRepositoryInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
readonly class CheckAllScrapersHealthHandler
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ContentSourceForHealthCheckInterface $contentSourceForHealthCheckRepo,
|
||||||
|
private ContentSourceHealthRepositoryInterface $contentSourceHealthRepo,
|
||||||
|
private TestScraperConfigurationHandler $testScraperConfigurationHandler,
|
||||||
|
private LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(CheckAllScrapersHealth $command): void
|
||||||
|
{
|
||||||
|
$sources = $this->contentSourceForHealthCheckRepo->getAll();
|
||||||
|
|
||||||
|
foreach ($sources as $source) {
|
||||||
|
if ($source->testSlug === null || $source->testChapterNumber === null) {
|
||||||
|
$this->logger->warning('ContentSource {id} has no test config, skipping health check.', ['id' => $source->id]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->contentSourceHealthRepo->markAsTesting($source->id);
|
||||||
|
$testUrl = str_replace(
|
||||||
|
['{slug}', '{chapterNumber}'],
|
||||||
|
[$source->testSlug, $source->testChapterNumber],
|
||||||
|
$source->chapterUrlFormat
|
||||||
|
);
|
||||||
|
|
||||||
|
$testCommand = new TestScraperConfiguration(
|
||||||
|
baseUrl: $source->baseUrl,
|
||||||
|
chapterUrlFormat: $source->chapterUrlFormat,
|
||||||
|
scrapingType: $source->scrapingType,
|
||||||
|
testUrl: $testUrl,
|
||||||
|
mangaSlug: $source->testSlug,
|
||||||
|
chapterNumber: $source->testChapterNumber,
|
||||||
|
imageSelector: $source->imageSelector,
|
||||||
|
nextPageSelector: $source->nextPageSelector,
|
||||||
|
chapterSelector: $source->chapterSelector,
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $this->testScraperConfigurationHandler->handle($testCommand);
|
||||||
|
|
||||||
|
if ($response->success) {
|
||||||
|
$this->contentSourceHealthRepo->markAsHealthy($source->id, new \DateTimeImmutable());
|
||||||
|
} else {
|
||||||
|
$firstError = $response->errors[0]['message'] ?? 'Erreur inconnue';
|
||||||
|
$this->contentSourceHealthRepo->markAsUnhealthy($source->id, new \DateTimeImmutable(), $firstError);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->contentSourceHealthRepo->markAsUnhealthy($source->id, new \DateTimeImmutable(), $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,14 +13,11 @@ use App\Domain\Shared\Domain\Event\ChapterScraped;
|
|||||||
use App\Domain\Scraping\Domain\Event\ChapterScrapingFailed;
|
use App\Domain\Scraping\Domain\Event\ChapterScrapingFailed;
|
||||||
use App\Domain\Scraping\Domain\Event\ChapterScrapingStarted;
|
use App\Domain\Scraping\Domain\Event\ChapterScrapingStarted;
|
||||||
use App\Domain\Scraping\Domain\Model\Chapter;
|
use App\Domain\Scraping\Domain\Model\Chapter;
|
||||||
use App\Domain\Scraping\Domain\Model\ScrapingJob;
|
|
||||||
use App\Domain\Scraping\Domain\Model\Source;
|
use App\Domain\Scraping\Domain\Model\Source;
|
||||||
use App\Domain\Scraping\Domain\Model\ValueObject\ScrapingRequest;
|
use App\Domain\Scraping\Domain\Model\ValueObject\ScrapingRequest;
|
||||||
use App\Domain\Scraping\Domain\Model\ValueObject\TempDirectory;
|
use App\Domain\Scraping\Domain\Model\ValueObject\TempDirectory;
|
||||||
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
|
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
|
||||||
use Ramsey\Uuid\Uuid;
|
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
|
|
||||||
readonly class ScrapeChapterHandler
|
readonly class ScrapeChapterHandler
|
||||||
{
|
{
|
||||||
@@ -33,151 +30,92 @@ readonly class ScrapeChapterHandler
|
|||||||
private MangaRepositoryInterface $mangaRepository,
|
private MangaRepositoryInterface $mangaRepository,
|
||||||
private SourceRepositoryInterface $sourceRepository,
|
private SourceRepositoryInterface $sourceRepository,
|
||||||
private MessageBusInterface $eventBus,
|
private MessageBusInterface $eventBus,
|
||||||
private EntityManagerInterface $entityManager
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(ScrapeChapter $command): void
|
public function handle(ScrapeChapter $command): void
|
||||||
{
|
{
|
||||||
$job = null;
|
/** @var Chapter $chapter */
|
||||||
try {
|
$chapter = $this->chapterRepository->getById($command->chapterId);
|
||||||
// 1. Récupération du chapitre
|
$manga = $this->mangaRepository->getById($chapter->mangaId);
|
||||||
/**@var Chapter $chapter */
|
|
||||||
$chapter = $this->chapterRepository->getById($command->chapterId);
|
|
||||||
if (!$chapter) {
|
|
||||||
throw new \InvalidArgumentException("Chapter not found with ID: {$command->chapterId}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Récupération du manga
|
$job = $this->jobRepository->get($command->jobId);
|
||||||
$manga = $this->mangaRepository->getById($chapter->mangaId);
|
$job->context['chapterId'] = $command->chapterId;
|
||||||
if (!$manga) {
|
$job->context['mangaTitle'] = $manga->getTitle();
|
||||||
throw new \InvalidArgumentException("Manga not found with ID: {$chapter->mangaId}");
|
$job->start();
|
||||||
}
|
$this->jobRepository->save($job);
|
||||||
|
|
||||||
// 3. Dispatch de l'événement de démarrage
|
$this->eventBus->dispatch(new ChapterScrapingStarted($job->id, $manga->getTitle(), $chapter->chapterNumber));
|
||||||
$this->eventBus->dispatch(new ChapterScrapingStarted($manga->getTitle(), $chapter->chapterNumber));
|
|
||||||
|
|
||||||
// 4. Détermination des sources à utiliser
|
$sources = $this->getSourcesToTry($manga);
|
||||||
$sources = $this->getSourcesToTry($manga);
|
$slugsToTry = array_merge([$manga->getSlug()], $manga->getAlternativeSlugs());
|
||||||
if (empty($sources)) {
|
$success = false;
|
||||||
throw new \InvalidArgumentException("No sources available for scraping");
|
$lastException = null;
|
||||||
}
|
|
||||||
|
|
||||||
// 5. Essai de scraping sur chaque source jusqu'à succès
|
foreach ($sources as $source) {
|
||||||
$success = false;
|
foreach ($slugsToTry as $slug) {
|
||||||
$lastException = null;
|
try {
|
||||||
|
$job->context['sourceId'] = $source->getId()->getValue();
|
||||||
foreach ($sources as $source) {
|
|
||||||
// Préparer la liste des slugs à essayer : slug principal + slugs alternatifs
|
|
||||||
$slugsToTry = array_merge([$manga->getSlug()], $manga->getAlternativeSlugs());
|
|
||||||
|
|
||||||
foreach ($slugsToTry as $slug) {
|
|
||||||
$job = new ScrapingJob(
|
|
||||||
Uuid::uuid4()->toString(),
|
|
||||||
$chapter->mangaId,
|
|
||||||
$chapter->chapterNumber,
|
|
||||||
$source->getId()->getValue()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Ajout de l'ID du chapitre et du slug dans le contexte du job
|
|
||||||
$job->context['chapterId'] = $command->chapterId;
|
|
||||||
$job->context['slug'] = $slug;
|
$job->context['slug'] = $slug;
|
||||||
$job->context['mangaTitle'] = $manga->getTitle();
|
|
||||||
|
|
||||||
$job->start();
|
|
||||||
$this->jobRepository->save($job);
|
$this->jobRepository->save($job);
|
||||||
|
|
||||||
try {
|
$scrapingParameters = $source->getScrappingParameters();
|
||||||
$this->entityManager->beginTransaction();
|
$scrapingParameters['chapterNumber'] = $chapter->chapterNumber;
|
||||||
|
$scrapingType = $scrapingParameters['scrapingType'] ?? 'html';
|
||||||
|
|
||||||
// 5. Scraping des URLs avec le slug courant
|
$scrapingRequest = new ScrapingRequest(
|
||||||
$scrapingParameters = $source->getScrappingParameters();
|
$scrapingType,
|
||||||
$scrapingParameters['chapterNumber'] = $chapter->chapterNumber;
|
$source->buildChapterUrl($slug, $chapter->chapterNumber),
|
||||||
$scrapingType = $scrapingParameters['scrapingType'] ?? 'html';
|
$scrapingParameters
|
||||||
|
);
|
||||||
|
|
||||||
$scrapingRequest = new ScrapingRequest(
|
$scraper = $this->scraperFactory->getScraperWithFallback($scrapingType);
|
||||||
$scrapingType,
|
$scrapingResult = $scraper->scrape($scrapingRequest);
|
||||||
$source->buildChapterUrl($slug, $chapter->chapterNumber),
|
|
||||||
$scrapingParameters
|
|
||||||
);
|
|
||||||
|
|
||||||
// Sélection du scraper approprié selon le type
|
$tempDir = new TempDirectory();
|
||||||
$scraper = $this->scraperFactory->getScraperWithFallback($scrapingType);
|
$downloadResults = $this->imageDownloader->downloadBatch(
|
||||||
$scrapingResult = $scraper->scrape($scrapingRequest);
|
$scrapingResult->getImageUrls(),
|
||||||
|
$tempDir,
|
||||||
|
$job->id
|
||||||
|
);
|
||||||
|
|
||||||
// 6. Téléchargement des images
|
$localPaths = array_map(fn ($r) => $r->getLocalPath(), $downloadResults);
|
||||||
$tempDir = new TempDirectory();
|
$pagesDirectory = $this->imageStorage->storeChapterImages($command->chapterId, $localPaths);
|
||||||
$downloadResults = $this->imageDownloader->downloadBatch(
|
$pageCount = count($downloadResults);
|
||||||
$scrapingResult->getImageUrls(),
|
|
||||||
$tempDir,
|
|
||||||
$job->id
|
|
||||||
);
|
|
||||||
|
|
||||||
// 7. Stockage des images individuelles
|
$job->complete();
|
||||||
$localPaths = array_map(fn ($r) => $r->getLocalPath(), $downloadResults);
|
$this->jobRepository->save($job);
|
||||||
$pagesDirectory = $this->imageStorage->storeChapterImages($command->chapterId, $localPaths);
|
|
||||||
$pageCount = count($downloadResults);
|
|
||||||
|
|
||||||
$job->complete();
|
$this->eventBus->dispatch(new ChapterScraped($job->id, $command->chapterId, $pagesDirectory, $pageCount));
|
||||||
$this->jobRepository->save($job);
|
$tempDir->cleanup();
|
||||||
|
|
||||||
$this->entityManager->commit();
|
$success = true;
|
||||||
|
|
||||||
$this->eventBus->dispatch(new ChapterScraped($job->id, $command->chapterId, $pagesDirectory, $pageCount));
|
|
||||||
|
|
||||||
// 8. Nettoyage
|
|
||||||
$tempDir->cleanup();
|
|
||||||
|
|
||||||
// Scraping réussi, pas besoin d'essayer d'autres slugs ni d'autres sources
|
|
||||||
$success = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
dump('EXCEPTION for source ' . $source->getName() . ' with slug ' . $slug . ': ' . $e->getMessage());
|
|
||||||
|
|
||||||
$this->entityManager->rollback();
|
|
||||||
|
|
||||||
if (isset($job)) {
|
|
||||||
$job->fail($e->getMessage());
|
|
||||||
$this->jobRepository->save($job);
|
|
||||||
}
|
|
||||||
|
|
||||||
$lastException = $e;
|
|
||||||
|
|
||||||
// Continuer avec le slug suivant pour cette source
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si le scraping a réussi avec un des slugs, sortir de la boucle des sources
|
|
||||||
if ($success) {
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$lastException = $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si toutes les sources ont échoué
|
if ($success) {
|
||||||
if (!$success) {
|
break;
|
||||||
$errorMessage = $lastException ? $lastException->getMessage() : "Failed to scrape chapter from all available sources";
|
|
||||||
$this->eventBus->dispatch(new ChapterScrapingFailed($chapter->mangaId, $chapter->chapterNumber, $errorMessage));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
if (!$success) {
|
||||||
if (isset($job)) {
|
$errorMessage = $lastException?->getMessage() ?? 'Failed to scrape chapter from all available sources';
|
||||||
$job->fail($e->getMessage());
|
$job->fail($errorMessage);
|
||||||
$this->jobRepository->save($job);
|
$this->jobRepository->save($job);
|
||||||
}
|
$this->eventBus->dispatch(new ChapterScrapingFailed($job->id, $chapter->mangaId, $chapter->chapterNumber, $errorMessage));
|
||||||
$this->eventBus->dispatch(new ChapterScrapingFailed($chapter->mangaId ?? 'unknown', $chapter->chapterNumber ?? 'unknown', $e->getMessage()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Détermine les sources à utiliser pour le scraping en fonction des préférences du manga
|
|
||||||
*
|
|
||||||
* @param \App\Domain\Scraping\Domain\Model\Manga $manga
|
* @param \App\Domain\Scraping\Domain\Model\Manga $manga
|
||||||
* @return Source[]
|
* @return Source[]
|
||||||
*/
|
*/
|
||||||
private function getSourcesToTry(\App\Domain\Scraping\Domain\Model\Manga $manga): array
|
private function getSourcesToTry(\App\Domain\Scraping\Domain\Model\Manga $manga): array
|
||||||
{
|
{
|
||||||
// Si le manga a des sources préférées, les utiliser
|
|
||||||
if ($manga->hasPreferredSources()) {
|
if ($manga->hasPreferredSources()) {
|
||||||
$preferredSources = [];
|
$preferredSources = [];
|
||||||
foreach ($manga->getPreferredSources() as $sourceId) {
|
foreach ($manga->getPreferredSources() as $sourceId) {
|
||||||
@@ -186,7 +124,6 @@ readonly class ScrapeChapterHandler
|
|||||||
$preferredSources[] = $source;
|
$preferredSources[] = $source;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limiter à 3 sources préférées maximum
|
|
||||||
if (count($preferredSources) >= 3) {
|
if (count($preferredSources) >= 3) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -197,7 +134,6 @@ readonly class ScrapeChapterHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sinon, utiliser toutes les sources disponibles
|
|
||||||
return $this->sourceRepository->getAll();
|
return $this->sourceRepository->getAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Scraping\Domain\Contract\Repository;
|
||||||
|
|
||||||
|
use App\Domain\Scraping\Domain\Model\ValueObject\ContentSourceHealthCheckData;
|
||||||
|
|
||||||
|
interface ContentSourceForHealthCheckInterface
|
||||||
|
{
|
||||||
|
/** @return ContentSourceHealthCheckData[] */
|
||||||
|
public function getAll(): array;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Scraping\Domain\Contract\Repository;
|
||||||
|
|
||||||
|
interface ContentSourceHealthRepositoryInterface
|
||||||
|
{
|
||||||
|
public function markAsTesting(int $sourceId): void;
|
||||||
|
|
||||||
|
public function markAsHealthy(int $sourceId, \DateTimeImmutable $testedAt): void;
|
||||||
|
|
||||||
|
public function markAsUnhealthy(int $sourceId, \DateTimeImmutable $testedAt, string $error): void;
|
||||||
|
}
|
||||||
@@ -5,12 +5,18 @@ namespace App\Domain\Scraping\Domain\Event;
|
|||||||
readonly class ChapterScrapingFailed
|
readonly class ChapterScrapingFailed
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
private string $jobId,
|
||||||
private string $mangaId,
|
private string $mangaId,
|
||||||
private string $chapterNumber,
|
private string $chapterNumber,
|
||||||
private string $reason
|
private string $reason
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getJobId(): string
|
||||||
|
{
|
||||||
|
return $this->jobId;
|
||||||
|
}
|
||||||
|
|
||||||
public function getMangaId(): string
|
public function getMangaId(): string
|
||||||
{
|
{
|
||||||
return $this->mangaId;
|
return $this->mangaId;
|
||||||
|
|||||||
@@ -5,11 +5,17 @@ namespace App\Domain\Scraping\Domain\Event;
|
|||||||
class ChapterScrapingStarted
|
class ChapterScrapingStarted
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
private readonly string $jobId,
|
||||||
private readonly string $mangaTitle,
|
private readonly string $mangaTitle,
|
||||||
private readonly float $chapterNumber,
|
private readonly float $chapterNumber,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getJobId(): string
|
||||||
|
{
|
||||||
|
return $this->jobId;
|
||||||
|
}
|
||||||
|
|
||||||
public function getMangaTitle(): string
|
public function getMangaTitle(): string
|
||||||
{
|
{
|
||||||
return $this->mangaTitle;
|
return $this->mangaTitle;
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ class ScrapingJob extends Job
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $id,
|
string $id,
|
||||||
string $mangaId,
|
?string $mangaId = null,
|
||||||
float $chapterNumber,
|
?float $chapterNumber = null,
|
||||||
string $sourceId
|
?string $sourceId = null
|
||||||
) {
|
) {
|
||||||
parent::__construct($id, 'scraping_job');
|
parent::__construct($id, 'scraping_job');
|
||||||
$this->maxAttempts = 1;
|
$this->maxAttempts = 1;
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Scraping\Domain\Model\ValueObject;
|
||||||
|
|
||||||
|
readonly class ContentSourceHealthCheckData
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $id,
|
||||||
|
public string $baseUrl,
|
||||||
|
public string $chapterUrlFormat,
|
||||||
|
public string $scrapingType,
|
||||||
|
public ?string $imageSelector,
|
||||||
|
public ?string $nextPageSelector,
|
||||||
|
public ?string $chapterSelector,
|
||||||
|
public ?string $testSlug,
|
||||||
|
public ?float $testChapterNumber,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Scraping\Infrastructure\ApiPlatform\Resource;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Post;
|
||||||
|
use App\Domain\Scraping\Infrastructure\ApiPlatform\State\Processor\CheckAllScrapersHealthStateProcessor;
|
||||||
|
|
||||||
|
#[ApiResource(
|
||||||
|
shortName: 'Scraping',
|
||||||
|
operations: [
|
||||||
|
new Post(
|
||||||
|
uriTemplate: '/scraping/check-all-health',
|
||||||
|
processor: CheckAllScrapersHealthStateProcessor::class,
|
||||||
|
output: false,
|
||||||
|
status: 202,
|
||||||
|
description: 'Déclenche le test de santé de tous les scrapers configurés avec testSlug',
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
class CheckAllScrapersHealthResource
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Scraping\Infrastructure\ApiPlatform\State\Processor;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
|
use App\Domain\Scraping\Application\Command\CheckAllScrapersHealth;
|
||||||
|
use App\Domain\Scraping\Application\CommandHandler\CheckAllScrapersHealthHandler;
|
||||||
|
|
||||||
|
readonly class CheckAllScrapersHealthStateProcessor implements ProcessorInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private CheckAllScrapersHealthHandler $handler,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||||
|
{
|
||||||
|
$this->handler->handle(new CheckAllScrapersHealth());
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,13 +5,20 @@ namespace App\Domain\Scraping\Infrastructure\ApiPlatform\State\Processor;
|
|||||||
use ApiPlatform\Metadata\Operation;
|
use ApiPlatform\Metadata\Operation;
|
||||||
use ApiPlatform\State\ProcessorInterface;
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
use App\Domain\Scraping\Application\Command\ScrapeChapter;
|
use App\Domain\Scraping\Application\Command\ScrapeChapter;
|
||||||
|
use App\Domain\Scraping\Domain\Model\ScrapingJob;
|
||||||
use App\Domain\Scraping\Infrastructure\ApiPlatform\Dto\ScrapeChapterRequest;
|
use App\Domain\Scraping\Infrastructure\ApiPlatform\Dto\ScrapeChapterRequest;
|
||||||
|
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
|
use Symfony\Component\Mercure\HubInterface;
|
||||||
|
use Symfony\Component\Mercure\Update;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
|
|
||||||
final class ScrapeChapterStateProcessor implements ProcessorInterface
|
final class ScrapeChapterStateProcessor implements ProcessorInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly MessageBusInterface $commandBus
|
private readonly MessageBusInterface $commandBus,
|
||||||
|
private readonly JobRepositoryInterface $jobRepository,
|
||||||
|
private readonly HubInterface $hub,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,10 +27,25 @@ final class ScrapeChapterStateProcessor implements ProcessorInterface
|
|||||||
*/
|
*/
|
||||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
|
||||||
{
|
{
|
||||||
$this->commandBus->dispatch(
|
$jobId = Uuid::uuid4()->toString();
|
||||||
new ScrapeChapter(
|
$job = new ScrapingJob($jobId);
|
||||||
$data->chapterId
|
$job->context['chapterId'] = $data->chapterId;
|
||||||
)
|
$this->jobRepository->save($job);
|
||||||
);
|
|
||||||
|
$this->hub->publish(new Update(
|
||||||
|
'jobs/activity',
|
||||||
|
json_encode([
|
||||||
|
'type' => 'job.created',
|
||||||
|
'id' => $job->id,
|
||||||
|
'type_job' => $job->type,
|
||||||
|
'status' => $job->status->value,
|
||||||
|
'createdAt' => $job->createdAt->format('c'),
|
||||||
|
'context' => $job->context,
|
||||||
|
'attempts' => $job->attempts,
|
||||||
|
'maxAttempts' => $job->maxAttempts,
|
||||||
|
])
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->commandBus->dispatch(new ScrapeChapter($data->chapterId, $jobId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Domain\Scraping\Infrastructure\EventSubscriber;
|
|||||||
use App\Domain\Shared\Domain\Event\ChapterScraped;
|
use App\Domain\Shared\Domain\Event\ChapterScraped;
|
||||||
use App\Domain\Scraping\Domain\Event\ChapterScrapingFailed;
|
use App\Domain\Scraping\Domain\Event\ChapterScrapingFailed;
|
||||||
use App\Domain\Scraping\Domain\Event\ChapterScrapingStarted;
|
use App\Domain\Scraping\Domain\Event\ChapterScrapingStarted;
|
||||||
|
use App\Domain\Scraping\Domain\Event\PageScrapingProgressed;
|
||||||
use App\Domain\Scraping\Domain\Contract\Repository\ChapterRepositoryInterface;
|
use App\Domain\Scraping\Domain\Contract\Repository\ChapterRepositoryInterface;
|
||||||
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
|
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
|
||||||
use App\Domain\Shared\Domain\Contract\NotificationInterface;
|
use App\Domain\Shared\Domain\Contract\NotificationInterface;
|
||||||
@@ -30,14 +31,32 @@ class ScrapingEventSubscriber implements EventSubscriberInterface
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[AsMessageHandler]
|
||||||
|
public function onPageScrapingProgressed(PageScrapingProgressed $event): void
|
||||||
|
{
|
||||||
|
$progress = (int) round($event->getProgress()->getPercentage());
|
||||||
|
|
||||||
|
$update = new Update(
|
||||||
|
'jobs/activity',
|
||||||
|
json_encode([
|
||||||
|
'type' => 'job.progress_updated',
|
||||||
|
'jobId' => $event->getJobId(),
|
||||||
|
'progress' => $progress,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
$this->hub->publish($update);
|
||||||
|
}
|
||||||
|
|
||||||
#[AsMessageHandler]
|
#[AsMessageHandler]
|
||||||
public function onChapterScrapingStarted(ChapterScrapingStarted $event): void
|
public function onChapterScrapingStarted(ChapterScrapingStarted $event): void
|
||||||
{
|
{
|
||||||
$chapterNumber = $event->getChapterNumber();
|
$this->hub->publish(new Update(
|
||||||
$mangaTitle = $event->getMangaTitle();
|
'jobs/activity',
|
||||||
|
json_encode(['type' => 'job.status_changed', 'jobId' => $event->getJobId(), 'status' => 'in_progress'])
|
||||||
|
));
|
||||||
|
|
||||||
$this->notification->sendInfo(
|
$this->notification->sendInfo(
|
||||||
sprintf('Scraping du chapitre %s de "%s" démarré', $chapterNumber, $mangaTitle)
|
sprintf('Scraping du chapitre %s de "%s" démarré', $event->getChapterNumber(), $event->getMangaTitle())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +103,11 @@ class ScrapingEventSubscriber implements EventSubscriberInterface
|
|||||||
$update = new Update($topics, json_encode($data));
|
$update = new Update($topics, json_encode($data));
|
||||||
$this->hub->publish($update);
|
$this->hub->publish($update);
|
||||||
|
|
||||||
|
$this->hub->publish(new Update(
|
||||||
|
'jobs/activity',
|
||||||
|
json_encode(['type' => 'job.status_changed', 'jobId' => $jobId, 'status' => 'completed'])
|
||||||
|
));
|
||||||
|
|
||||||
$mangaTitle = $job->context['mangaTitle'] ?? 'manga inconnu';
|
$mangaTitle = $job->context['mangaTitle'] ?? 'manga inconnu';
|
||||||
$this->notification->sendSuccess(
|
$this->notification->sendSuccess(
|
||||||
sprintf('Chapitre %s de "%s" scrappé avec succès', $chapter->chapterNumber, $mangaTitle)
|
sprintf('Chapitre %s de "%s" scrappé avec succès', $chapter->chapterNumber, $mangaTitle)
|
||||||
@@ -93,6 +117,11 @@ class ScrapingEventSubscriber implements EventSubscriberInterface
|
|||||||
#[AsMessageHandler]
|
#[AsMessageHandler]
|
||||||
public function onChapterScrapingFailed(ChapterScrapingFailed $event): void
|
public function onChapterScrapingFailed(ChapterScrapingFailed $event): void
|
||||||
{
|
{
|
||||||
|
$this->hub->publish(new Update(
|
||||||
|
'jobs/activity',
|
||||||
|
json_encode(['type' => 'job.status_changed', 'jobId' => $event->getJobId(), 'status' => 'failed'])
|
||||||
|
));
|
||||||
|
|
||||||
$this->logger->info('ChapterScrapingFailed reçu pour mangaId: ' . $event->getMangaId() . ', chapter: ' . $event->getChapterNumber());
|
$this->logger->info('ChapterScrapingFailed reçu pour mangaId: ' . $event->getMangaId() . ', chapter: ' . $event->getChapterNumber());
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
|
|||||||
@@ -20,7 +20,14 @@ readonly class ImageDownloader implements ImageDownloaderInterface
|
|||||||
|
|
||||||
public function download(string $url, string $destination): void
|
public function download(string $url, string $destination): void
|
||||||
{
|
{
|
||||||
$response = $this->httpClient->request('GET', $url);
|
$urlParts = parse_url($url);
|
||||||
|
$referer = ($urlParts['scheme'] ?? 'https') . '://' . ($urlParts['host'] ?? '');
|
||||||
|
|
||||||
|
$response = $this->httpClient->request('GET', $url, [
|
||||||
|
'headers' => [
|
||||||
|
'Referer' => $referer,
|
||||||
|
],
|
||||||
|
]);
|
||||||
$contentType = $response->getHeaders()['content-type'][0] ?? '';
|
$contentType = $response->getHeaders()['content-type'][0] ?? '';
|
||||||
|
|
||||||
if (!str_starts_with($contentType, 'image/')) {
|
if (!str_starts_with($contentType, 'image/')) {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Setting\Application\Command;
|
||||||
|
|
||||||
|
readonly class DeleteContentSourceCommand
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $id
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ readonly class UpsertContentSourceCommand
|
|||||||
public ?string $imageSelector = null,
|
public ?string $imageSelector = null,
|
||||||
public ?string $nextPageSelector = null,
|
public ?string $nextPageSelector = null,
|
||||||
public ?string $chapterSelector = null,
|
public ?string $chapterSelector = null,
|
||||||
|
public ?string $testSlug = null,
|
||||||
|
public ?float $testChapterNumber = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Setting\Application\CommandHandler;
|
||||||
|
|
||||||
|
use App\Domain\Setting\Application\Command\DeleteContentSourceCommand;
|
||||||
|
use App\Domain\Setting\Domain\Contract\Repository\ContentSourceRepositoryInterface;
|
||||||
|
use App\Domain\Setting\Domain\Exception\ContentSourceNotFoundException;
|
||||||
|
|
||||||
|
readonly class DeleteContentSourceCommandHandler
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ContentSourceRepositoryInterface $contentSourceRepository
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(DeleteContentSourceCommand $command): void
|
||||||
|
{
|
||||||
|
$contentSource = $this->contentSourceRepository->findById($command->id);
|
||||||
|
|
||||||
|
if (!$contentSource) {
|
||||||
|
throw new ContentSourceNotFoundException($command->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->contentSourceRepository->delete($contentSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,8 @@ readonly class UpsertContentSourceCommandHandler
|
|||||||
imageSelector: $command->imageSelector,
|
imageSelector: $command->imageSelector,
|
||||||
nextPageSelector: $command->nextPageSelector,
|
nextPageSelector: $command->nextPageSelector,
|
||||||
chapterSelector: $command->chapterSelector,
|
chapterSelector: $command->chapterSelector,
|
||||||
|
testSlug: $command->testSlug,
|
||||||
|
testChapterNumber: $command->testChapterNumber,
|
||||||
);
|
);
|
||||||
$this->contentSourceRepository->save($contentSource);
|
$this->contentSourceRepository->save($contentSource);
|
||||||
}
|
}
|
||||||
@@ -38,6 +40,8 @@ readonly class UpsertContentSourceCommandHandler
|
|||||||
imageSelector: $command->imageSelector,
|
imageSelector: $command->imageSelector,
|
||||||
nextPageSelector: $command->nextPageSelector,
|
nextPageSelector: $command->nextPageSelector,
|
||||||
chapterSelector: $command->chapterSelector,
|
chapterSelector: $command->chapterSelector,
|
||||||
|
testSlug: $command->testSlug,
|
||||||
|
testChapterNumber: $command->testChapterNumber,
|
||||||
);
|
);
|
||||||
$this->contentSourceRepository->save($contentSource);
|
$this->contentSourceRepository->save($contentSource);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ readonly class ContentSourceResponse
|
|||||||
public ?string $nextPageSelector,
|
public ?string $nextPageSelector,
|
||||||
public ?string $chapterSelector,
|
public ?string $chapterSelector,
|
||||||
public string $cleanBaseUrl,
|
public string $cleanBaseUrl,
|
||||||
|
public ?string $testSlug = null,
|
||||||
|
public ?float $testChapterNumber = null,
|
||||||
|
public string $healthStatus = 'unknown',
|
||||||
|
public ?\DateTimeImmutable $healthLastTestedAt = null,
|
||||||
|
public ?string $healthLastError = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +34,11 @@ readonly class ContentSourceResponse
|
|||||||
nextPageSelector: $contentSource->getNextPageSelector(),
|
nextPageSelector: $contentSource->getNextPageSelector(),
|
||||||
chapterSelector: $contentSource->getChapterSelector(),
|
chapterSelector: $contentSource->getChapterSelector(),
|
||||||
cleanBaseUrl: $contentSource->getCleanBaseUrl(),
|
cleanBaseUrl: $contentSource->getCleanBaseUrl(),
|
||||||
|
testSlug: $contentSource->getTestSlug(),
|
||||||
|
testChapterNumber: $contentSource->getTestChapterNumber(),
|
||||||
|
healthStatus: $contentSource->getHealthStatus(),
|
||||||
|
healthLastTestedAt: $contentSource->getHealthLastTestedAt(),
|
||||||
|
healthLastError: $contentSource->getHealthLastError(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ final class ContentSource
|
|||||||
private ?string $imageSelector = null,
|
private ?string $imageSelector = null,
|
||||||
private ?string $nextPageSelector = null,
|
private ?string $nextPageSelector = null,
|
||||||
private ?string $chapterSelector = null,
|
private ?string $chapterSelector = null,
|
||||||
|
private ?string $testSlug = null,
|
||||||
|
private ?float $testChapterNumber = null,
|
||||||
|
private string $healthStatus = 'unknown',
|
||||||
|
private ?\DateTimeImmutable $healthLastTestedAt = null,
|
||||||
|
private ?string $healthLastError = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +55,44 @@ final class ContentSource
|
|||||||
return $this->chapterSelector;
|
return $this->chapterSelector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTestSlug(): ?string
|
||||||
|
{
|
||||||
|
return $this->testSlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTestChapterNumber(): ?float
|
||||||
|
{
|
||||||
|
return $this->testChapterNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHealthStatus(): string
|
||||||
|
{
|
||||||
|
return $this->healthStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHealthLastTestedAt(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->healthLastTestedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHealthLastError(): ?string
|
||||||
|
{
|
||||||
|
return $this->healthLastError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateTestConfig(?string $testSlug, ?float $testChapterNumber): void
|
||||||
|
{
|
||||||
|
$this->testSlug = $testSlug;
|
||||||
|
$this->testChapterNumber = $testChapterNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateHealthStatus(string $status, ?\DateTimeImmutable $testedAt = null, ?string $error = null): void
|
||||||
|
{
|
||||||
|
$this->healthStatus = $status;
|
||||||
|
$this->healthLastTestedAt = $testedAt;
|
||||||
|
$this->healthLastError = $error;
|
||||||
|
}
|
||||||
|
|
||||||
public function updateId(int $id): void
|
public function updateId(int $id): void
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
@@ -71,6 +114,8 @@ final class ContentSource
|
|||||||
?string $imageSelector = null,
|
?string $imageSelector = null,
|
||||||
?string $nextPageSelector = null,
|
?string $nextPageSelector = null,
|
||||||
?string $chapterSelector = null,
|
?string $chapterSelector = null,
|
||||||
|
?string $testSlug = null,
|
||||||
|
?float $testChapterNumber = null,
|
||||||
): self {
|
): self {
|
||||||
return new self(
|
return new self(
|
||||||
id: null,
|
id: null,
|
||||||
@@ -80,6 +125,8 @@ final class ContentSource
|
|||||||
imageSelector: $imageSelector,
|
imageSelector: $imageSelector,
|
||||||
nextPageSelector: $nextPageSelector,
|
nextPageSelector: $nextPageSelector,
|
||||||
chapterSelector: $chapterSelector,
|
chapterSelector: $chapterSelector,
|
||||||
|
testSlug: $testSlug,
|
||||||
|
testChapterNumber: $testChapterNumber,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +137,8 @@ final class ContentSource
|
|||||||
?string $imageSelector = null,
|
?string $imageSelector = null,
|
||||||
?string $nextPageSelector = null,
|
?string $nextPageSelector = null,
|
||||||
?string $chapterSelector = null,
|
?string $chapterSelector = null,
|
||||||
|
?string $testSlug = null,
|
||||||
|
?float $testChapterNumber = null,
|
||||||
): void {
|
): void {
|
||||||
$this->baseUrl = $baseUrl;
|
$this->baseUrl = $baseUrl;
|
||||||
$this->chapterUrlFormat = $chapterUrlFormat;
|
$this->chapterUrlFormat = $chapterUrlFormat;
|
||||||
@@ -97,5 +146,7 @@ final class ContentSource
|
|||||||
$this->imageSelector = $imageSelector;
|
$this->imageSelector = $imageSelector;
|
||||||
$this->nextPageSelector = $nextPageSelector;
|
$this->nextPageSelector = $nextPageSelector;
|
||||||
$this->chapterSelector = $chapterSelector;
|
$this->chapterSelector = $chapterSelector;
|
||||||
|
$this->testSlug = $testSlug;
|
||||||
|
$this->testChapterNumber = $testChapterNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Setting\Infrastructure\ApiPlatform\Resource;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Delete;
|
||||||
|
use App\Domain\Setting\Infrastructure\ApiPlatform\State\Processor\DeleteContentSourceStateProcessor;
|
||||||
|
use App\Domain\Setting\Infrastructure\ApiPlatform\State\Provider\DeleteContentSourceStateProvider;
|
||||||
|
|
||||||
|
#[ApiResource(
|
||||||
|
shortName: 'ContentSource',
|
||||||
|
operations: [
|
||||||
|
new Delete(
|
||||||
|
uriTemplate: '/content-sources/{id}',
|
||||||
|
provider: DeleteContentSourceStateProvider::class,
|
||||||
|
processor: DeleteContentSourceStateProcessor::class,
|
||||||
|
name: 'delete_content_source',
|
||||||
|
openapiContext: [
|
||||||
|
'summary' => 'Delete a content source',
|
||||||
|
'description' => 'Permanently deletes a content source',
|
||||||
|
'parameters' => [
|
||||||
|
[
|
||||||
|
'name' => 'id',
|
||||||
|
'in' => 'path',
|
||||||
|
'required' => true,
|
||||||
|
'schema' => [
|
||||||
|
'type' => 'integer'
|
||||||
|
],
|
||||||
|
'description' => 'The content source ID'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'responses' => [
|
||||||
|
'204' => [
|
||||||
|
'description' => 'Content source successfully deleted'
|
||||||
|
],
|
||||||
|
'404' => [
|
||||||
|
'description' => 'Content source not found'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
class DeleteContentSourceResource
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $id
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,11 @@ class GetContentSourceResource
|
|||||||
public readonly ?string $nextPageSelector,
|
public readonly ?string $nextPageSelector,
|
||||||
public readonly ?string $chapterSelector,
|
public readonly ?string $chapterSelector,
|
||||||
public readonly string $cleanBaseUrl,
|
public readonly string $cleanBaseUrl,
|
||||||
|
public readonly ?string $testSlug = null,
|
||||||
|
public readonly ?float $testChapterNumber = null,
|
||||||
|
public readonly string $healthStatus = 'unknown',
|
||||||
|
public readonly ?\DateTimeImmutable $healthLastTestedAt = null,
|
||||||
|
public readonly ?string $healthLastError = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ class UpsertContentSourceResource
|
|||||||
public readonly ?string $imageSelector = null,
|
public readonly ?string $imageSelector = null,
|
||||||
public readonly ?string $nextPageSelector = null,
|
public readonly ?string $nextPageSelector = null,
|
||||||
public readonly ?string $chapterSelector = null,
|
public readonly ?string $chapterSelector = null,
|
||||||
|
public readonly ?string $testSlug = null,
|
||||||
|
public readonly ?float $testChapterNumber = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Setting\Infrastructure\ApiPlatform\State\Processor;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
|
use App\Domain\Setting\Application\Command\DeleteContentSourceCommand;
|
||||||
|
use App\Domain\Setting\Application\CommandHandler\DeleteContentSourceCommandHandler;
|
||||||
|
use App\Domain\Setting\Domain\Exception\ContentSourceNotFoundException;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
|
readonly class DeleteContentSourceStateProcessor implements ProcessorInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private DeleteContentSourceCommandHandler $handler
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): int
|
||||||
|
{
|
||||||
|
if (!isset($uriVariables['id'])) {
|
||||||
|
throw new \InvalidArgumentException('Content source ID is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$command = new DeleteContentSourceCommand((int) $uriVariables['id']);
|
||||||
|
$this->handler->handle($command);
|
||||||
|
|
||||||
|
return Response::HTTP_NO_CONTENT;
|
||||||
|
} catch (ContentSourceNotFoundException $e) {
|
||||||
|
throw new NotFoundHttpException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,8 @@ readonly class UpsertContentSourceStateProcessor implements ProcessorInterface
|
|||||||
imageSelector: $data->imageSelector,
|
imageSelector: $data->imageSelector,
|
||||||
nextPageSelector: $data->nextPageSelector,
|
nextPageSelector: $data->nextPageSelector,
|
||||||
chapterSelector: $data->chapterSelector,
|
chapterSelector: $data->chapterSelector,
|
||||||
|
testSlug: $data->testSlug,
|
||||||
|
testChapterNumber: $data->testChapterNumber,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->handler->handle($command);
|
$this->handler->handle($command);
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Setting\Infrastructure\ApiPlatform\State\Provider;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProviderInterface;
|
||||||
|
use App\Domain\Setting\Domain\Contract\Repository\ContentSourceRepositoryInterface;
|
||||||
|
use App\Domain\Setting\Domain\Exception\ContentSourceNotFoundException;
|
||||||
|
use App\Domain\Setting\Infrastructure\ApiPlatform\Resource\DeleteContentSourceResource;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
|
readonly class DeleteContentSourceStateProvider implements ProviderInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ContentSourceRepositoryInterface $contentSourceRepository
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): DeleteContentSourceResource
|
||||||
|
{
|
||||||
|
if (!isset($uriVariables['id'])) {
|
||||||
|
throw new NotFoundHttpException('Content source ID is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = (int) $uriVariables['id'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$contentSource = $this->contentSourceRepository->findById($id);
|
||||||
|
|
||||||
|
if (!$contentSource) {
|
||||||
|
throw new ContentSourceNotFoundException($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DeleteContentSourceResource($id);
|
||||||
|
} catch (ContentSourceNotFoundException $e) {
|
||||||
|
throw new NotFoundHttpException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,11 @@ readonly class GetContentSourceStateProvider implements ProviderInterface
|
|||||||
nextPageSelector: $response->nextPageSelector,
|
nextPageSelector: $response->nextPageSelector,
|
||||||
chapterSelector: $response->chapterSelector,
|
chapterSelector: $response->chapterSelector,
|
||||||
cleanBaseUrl: $response->cleanBaseUrl,
|
cleanBaseUrl: $response->cleanBaseUrl,
|
||||||
|
testSlug: $response->testSlug,
|
||||||
|
testChapterNumber: $response->testChapterNumber,
|
||||||
|
healthStatus: $response->healthStatus,
|
||||||
|
healthLastTestedAt: $response->healthLastTestedAt,
|
||||||
|
healthLastError: $response->healthLastError,
|
||||||
);
|
);
|
||||||
} catch (ContentSourceNotFoundException $e) {
|
} catch (ContentSourceNotFoundException $e) {
|
||||||
throw new NotFoundHttpException($e->getMessage());
|
throw new NotFoundHttpException($e->getMessage());
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ readonly class ListContentSourceStateProvider implements ProviderInterface
|
|||||||
nextPageSelector: $contentSourceResponse->nextPageSelector,
|
nextPageSelector: $contentSourceResponse->nextPageSelector,
|
||||||
chapterSelector: $contentSourceResponse->chapterSelector,
|
chapterSelector: $contentSourceResponse->chapterSelector,
|
||||||
cleanBaseUrl: $contentSourceResponse->cleanBaseUrl,
|
cleanBaseUrl: $contentSourceResponse->cleanBaseUrl,
|
||||||
|
testSlug: $contentSourceResponse->testSlug,
|
||||||
|
testChapterNumber: $contentSourceResponse->testChapterNumber,
|
||||||
|
healthStatus: $contentSourceResponse->healthStatus,
|
||||||
|
healthLastTestedAt: $contentSourceResponse->healthLastTestedAt,
|
||||||
|
healthLastError: $contentSourceResponse->healthLastError,
|
||||||
),
|
),
|
||||||
$response->contentSources
|
$response->contentSources
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ readonly class ContentSourceMapper
|
|||||||
imageSelector: $entity->getImageSelector(),
|
imageSelector: $entity->getImageSelector(),
|
||||||
nextPageSelector: $entity->getNextPageSelector(),
|
nextPageSelector: $entity->getNextPageSelector(),
|
||||||
chapterSelector: $entity->getChapterSelector(),
|
chapterSelector: $entity->getChapterSelector(),
|
||||||
|
testSlug: $entity->getTestSlug(),
|
||||||
|
testChapterNumber: $entity->getTestChapterNumber(),
|
||||||
|
healthStatus: $entity->getHealthStatus(),
|
||||||
|
healthLastTestedAt: $entity->getHealthLastTestedAt(),
|
||||||
|
healthLastError: $entity->getHealthLastError(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +34,12 @@ readonly class ContentSourceMapper
|
|||||||
->setScrapingType($contentSource->getScrapingType())
|
->setScrapingType($contentSource->getScrapingType())
|
||||||
->setImageSelector($contentSource->getImageSelector())
|
->setImageSelector($contentSource->getImageSelector())
|
||||||
->setNextPageSelector($contentSource->getNextPageSelector())
|
->setNextPageSelector($contentSource->getNextPageSelector())
|
||||||
->setChapterSelector($contentSource->getChapterSelector());
|
->setChapterSelector($contentSource->getChapterSelector())
|
||||||
|
->setTestSlug($contentSource->getTestSlug())
|
||||||
|
->setTestChapterNumber($contentSource->getTestChapterNumber())
|
||||||
|
->setHealthStatus($contentSource->getHealthStatus())
|
||||||
|
->setHealthLastTestedAt($contentSource->getHealthLastTestedAt())
|
||||||
|
->setHealthLastError($contentSource->getHealthLastError());
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
@@ -41,7 +51,12 @@ readonly class ContentSourceMapper
|
|||||||
->setScrapingType($contentSource->getScrapingType())
|
->setScrapingType($contentSource->getScrapingType())
|
||||||
->setImageSelector($contentSource->getImageSelector())
|
->setImageSelector($contentSource->getImageSelector())
|
||||||
->setNextPageSelector($contentSource->getNextPageSelector())
|
->setNextPageSelector($contentSource->getNextPageSelector())
|
||||||
->setChapterSelector($contentSource->getChapterSelector());
|
->setChapterSelector($contentSource->getChapterSelector())
|
||||||
|
->setTestSlug($contentSource->getTestSlug())
|
||||||
|
->setTestChapterNumber($contentSource->getTestChapterNumber())
|
||||||
|
->setHealthStatus($contentSource->getHealthStatus())
|
||||||
|
->setHealthLastTestedAt($contentSource->getHealthLastTestedAt())
|
||||||
|
->setHealthLastError($contentSource->getHealthLastError());
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Setting\Infrastructure\Persistence\Repository;
|
||||||
|
|
||||||
|
use App\Domain\Scraping\Domain\Contract\Repository\ContentSourceForHealthCheckInterface;
|
||||||
|
use App\Domain\Scraping\Domain\Contract\Repository\ContentSourceHealthRepositoryInterface;
|
||||||
|
use App\Domain\Scraping\Domain\Model\ValueObject\ContentSourceHealthCheckData;
|
||||||
|
use App\Entity\ContentSource as ContentSourceEntity;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Mercure\HubInterface;
|
||||||
|
use Symfony\Component\Mercure\Update;
|
||||||
|
|
||||||
|
readonly class DoctrineContentSourceForHealthCheckRepository implements ContentSourceForHealthCheckInterface, ContentSourceHealthRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private EntityManagerInterface $entityManager,
|
||||||
|
private HubInterface $hub,
|
||||||
|
private LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAll(): array
|
||||||
|
{
|
||||||
|
$entities = $this->entityManager->getRepository(ContentSourceEntity::class)->findAll();
|
||||||
|
|
||||||
|
return array_map(
|
||||||
|
fn (ContentSourceEntity $entity) => new ContentSourceHealthCheckData(
|
||||||
|
id: $entity->getId(),
|
||||||
|
baseUrl: $entity->getBaseUrl(),
|
||||||
|
chapterUrlFormat: $entity->getChapterUrlFormat(),
|
||||||
|
scrapingType: $entity->getScrapingType(),
|
||||||
|
imageSelector: $entity->getImageSelector(),
|
||||||
|
nextPageSelector: $entity->getNextPageSelector(),
|
||||||
|
chapterSelector: $entity->getChapterSelector(),
|
||||||
|
testSlug: $entity->getTestSlug(),
|
||||||
|
testChapterNumber: $entity->getTestChapterNumber(),
|
||||||
|
),
|
||||||
|
$entities
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function markAsTesting(int $sourceId): void
|
||||||
|
{
|
||||||
|
$entity = $this->entityManager->find(ContentSourceEntity::class, $sourceId);
|
||||||
|
if (!$entity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$entity->setHealthStatus('testing')
|
||||||
|
->setHealthLastError(null);
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$this->publishUpdate($sourceId, 'testing', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function markAsHealthy(int $sourceId, \DateTimeImmutable $testedAt): void
|
||||||
|
{
|
||||||
|
$entity = $this->entityManager->find(ContentSourceEntity::class, $sourceId);
|
||||||
|
if (!$entity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$entity->setHealthStatus('ok')
|
||||||
|
->setHealthLastTestedAt($testedAt)
|
||||||
|
->setHealthLastError(null);
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$this->publishUpdate($sourceId, 'ok', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function markAsUnhealthy(int $sourceId, \DateTimeImmutable $testedAt, string $error): void
|
||||||
|
{
|
||||||
|
$entity = $this->entityManager->find(ContentSourceEntity::class, $sourceId);
|
||||||
|
if (!$entity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$entity->setHealthStatus('ko')
|
||||||
|
->setHealthLastTestedAt($testedAt)
|
||||||
|
->setHealthLastError($error);
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$this->publishUpdate($sourceId, 'ko', $error);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function publishUpdate(int $sourceId, string $status, ?string $error): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->hub->publish(new Update(
|
||||||
|
"scrapers/health/{$sourceId}",
|
||||||
|
json_encode(['sourceId' => $sourceId, 'status' => $status, 'error' => $error])
|
||||||
|
));
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->logger->warning('Mercure publish failed for scraper health update', [
|
||||||
|
'sourceId' => $sourceId,
|
||||||
|
'status' => $status,
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\System\Application\Query;
|
||||||
|
|
||||||
|
final class GetSystemStatusQuery
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\System\Application\QueryHandler;
|
||||||
|
|
||||||
|
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
|
||||||
|
use App\Domain\Shared\Domain\Model\JobStatus;
|
||||||
|
use App\Domain\System\Application\Query\GetSystemStatusQuery;
|
||||||
|
use App\Domain\System\Domain\Contract\Repository\SystemStatusRepositoryInterface;
|
||||||
|
use App\Domain\System\Domain\Model\SystemStatus;
|
||||||
|
|
||||||
|
readonly class GetSystemStatusQueryHandler
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private SystemStatusRepositoryInterface $systemStatusRepository,
|
||||||
|
private JobRepositoryInterface $jobRepository,
|
||||||
|
private string $mangaDataPath,
|
||||||
|
private string $imagesStoragePath,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(GetSystemStatusQuery $query): SystemStatus
|
||||||
|
{
|
||||||
|
$now = new \DateTimeImmutable();
|
||||||
|
$last24h = $now->modify('-24 hours');
|
||||||
|
$last7d = $now->modify('-7 days');
|
||||||
|
|
||||||
|
$totalJobs = $this->jobRepository->countByCriteria([]);
|
||||||
|
$completedJobs = $this->jobRepository->countByCriteria(['status' => JobStatus::COMPLETED]);
|
||||||
|
$failedJobs = $this->jobRepository->countByCriteria(['status' => JobStatus::FAILED]);
|
||||||
|
$pendingJobs = $this->jobRepository->countByCriteria(['status' => JobStatus::PENDING]);
|
||||||
|
$inProgressJobs = $this->jobRepository->countByCriteria(['status' => JobStatus::IN_PROGRESS]);
|
||||||
|
|
||||||
|
$totalJobsLast24h = $this->jobRepository->countByCriteria(['createdAfter' => $last24h]);
|
||||||
|
$completedJobsLast24h = $this->jobRepository->countByCriteria(['status' => JobStatus::COMPLETED, 'createdAfter' => $last24h]);
|
||||||
|
$failedJobsLast24h = $this->jobRepository->countByCriteria(['status' => JobStatus::FAILED, 'createdAfter' => $last24h]);
|
||||||
|
|
||||||
|
$totalJobsLast7d = $this->jobRepository->countByCriteria(['createdAfter' => $last7d]);
|
||||||
|
$completedJobsLast7d = $this->jobRepository->countByCriteria(['status' => JobStatus::COMPLETED, 'createdAfter' => $last7d]);
|
||||||
|
$failedJobsLast7d = $this->jobRepository->countByCriteria(['status' => JobStatus::FAILED, 'createdAfter' => $last7d]);
|
||||||
|
|
||||||
|
$storagePath = $this->imagesStoragePath;
|
||||||
|
$storageTotalBytes = (int) (@disk_total_space($storagePath) ?: 0);
|
||||||
|
$storageFreeBytes = (int) (@disk_free_space($storagePath) ?: 0);
|
||||||
|
$storageUsedBytes = $this->computeDirectorySize($storagePath);
|
||||||
|
|
||||||
|
return new SystemStatus(
|
||||||
|
totalMangas: $this->systemStatusRepository->countMangas(),
|
||||||
|
monitoredMangas: $this->systemStatusRepository->countMonitoredMangas(),
|
||||||
|
mangasByStatus: $this->systemStatusRepository->countMangasByStatus(),
|
||||||
|
totalChapters: $this->systemStatusRepository->countChapters(),
|
||||||
|
downloadedChapters: $this->systemStatusRepository->countDownloadedChapters(),
|
||||||
|
totalJobs: $totalJobs,
|
||||||
|
completedJobs: $completedJobs,
|
||||||
|
failedJobs: $failedJobs,
|
||||||
|
pendingJobs: $pendingJobs,
|
||||||
|
inProgressJobs: $inProgressJobs,
|
||||||
|
totalJobsLast24h: $totalJobsLast24h,
|
||||||
|
completedJobsLast24h: $completedJobsLast24h,
|
||||||
|
failedJobsLast24h: $failedJobsLast24h,
|
||||||
|
totalJobsLast7d: $totalJobsLast7d,
|
||||||
|
completedJobsLast7d: $completedJobsLast7d,
|
||||||
|
failedJobsLast7d: $failedJobsLast7d,
|
||||||
|
storagePath: $this->mangaDataPath,
|
||||||
|
storageTotalBytes: $storageTotalBytes,
|
||||||
|
storageFreeBytes: $storageFreeBytes,
|
||||||
|
storageUsedBytes: $storageUsedBytes,
|
||||||
|
totalSources: $this->systemStatusRepository->countContentSources(),
|
||||||
|
sourcesByHealth: $this->systemStatusRepository->countContentSourcesByHealth(),
|
||||||
|
phpVersion: PHP_VERSION,
|
||||||
|
generatedAt: $now,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function computeDirectorySize(string $path): int
|
||||||
|
{
|
||||||
|
if (!is_dir($path)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$size = 0;
|
||||||
|
$iterator = new \RecursiveIteratorIterator(
|
||||||
|
new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($iterator as $file) {
|
||||||
|
if ($file->isFile()) {
|
||||||
|
$size += $file->getSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $size;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\System\Domain\Contract\Repository;
|
||||||
|
|
||||||
|
interface SystemStatusRepositoryInterface
|
||||||
|
{
|
||||||
|
public function countMangas(): int;
|
||||||
|
|
||||||
|
public function countMonitoredMangas(): int;
|
||||||
|
|
||||||
|
/** @return array<string, int> */
|
||||||
|
public function countMangasByStatus(): array;
|
||||||
|
|
||||||
|
public function countChapters(): int;
|
||||||
|
|
||||||
|
public function countDownloadedChapters(): int;
|
||||||
|
|
||||||
|
public function countContentSources(): int;
|
||||||
|
|
||||||
|
/** @return array<string, int> */
|
||||||
|
public function countContentSourcesByHealth(): array;
|
||||||
|
}
|
||||||
44
src/Domain/System/Domain/Model/SystemStatus.php
Normal file
44
src/Domain/System/Domain/Model/SystemStatus.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\System\Domain\Model;
|
||||||
|
|
||||||
|
readonly class SystemStatus
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
// Mangas
|
||||||
|
public int $totalMangas,
|
||||||
|
public int $monitoredMangas,
|
||||||
|
/** @var array<string, int> */
|
||||||
|
public array $mangasByStatus,
|
||||||
|
// Chapitres
|
||||||
|
public int $totalChapters,
|
||||||
|
public int $downloadedChapters,
|
||||||
|
// Jobs global
|
||||||
|
public int $totalJobs,
|
||||||
|
public int $completedJobs,
|
||||||
|
public int $failedJobs,
|
||||||
|
public int $pendingJobs,
|
||||||
|
public int $inProgressJobs,
|
||||||
|
// Jobs 24h
|
||||||
|
public int $totalJobsLast24h,
|
||||||
|
public int $completedJobsLast24h,
|
||||||
|
public int $failedJobsLast24h,
|
||||||
|
// Jobs 7j
|
||||||
|
public int $totalJobsLast7d,
|
||||||
|
public int $completedJobsLast7d,
|
||||||
|
public int $failedJobsLast7d,
|
||||||
|
// Stockage
|
||||||
|
public string $storagePath,
|
||||||
|
public int $storageTotalBytes,
|
||||||
|
public int $storageFreeBytes,
|
||||||
|
public int $storageUsedBytes,
|
||||||
|
// Sources
|
||||||
|
public int $totalSources,
|
||||||
|
/** @var array<string, int> */
|
||||||
|
public array $sourcesByHealth,
|
||||||
|
// Système
|
||||||
|
public string $phpVersion,
|
||||||
|
public \DateTimeImmutable $generatedAt,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\System\Infrastructure\ApiPlatform\Resource;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiProperty;
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use App\Domain\System\Infrastructure\ApiPlatform\State\Provider\GetSystemStatusStateProvider;
|
||||||
|
|
||||||
|
#[ApiResource(
|
||||||
|
shortName: 'System',
|
||||||
|
operations: [
|
||||||
|
new Get(
|
||||||
|
uriTemplate: '/system/status',
|
||||||
|
provider: GetSystemStatusStateProvider::class,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
class GetSystemStatusResource
|
||||||
|
{
|
||||||
|
#[ApiProperty(identifier: true)]
|
||||||
|
public string $id = 'current';
|
||||||
|
|
||||||
|
public int $totalMangas = 0;
|
||||||
|
public int $monitoredMangas = 0;
|
||||||
|
/** @var array<string, int> */
|
||||||
|
public array $mangasByStatus = [];
|
||||||
|
public int $totalChapters = 0;
|
||||||
|
public int $downloadedChapters = 0;
|
||||||
|
public int $pendingChapters = 0;
|
||||||
|
public int $totalJobs = 0;
|
||||||
|
public int $completedJobs = 0;
|
||||||
|
public int $failedJobs = 0;
|
||||||
|
public int $pendingJobs = 0;
|
||||||
|
public int $inProgressJobs = 0;
|
||||||
|
public int $totalJobsLast24h = 0;
|
||||||
|
public int $completedJobsLast24h = 0;
|
||||||
|
public int $failedJobsLast24h = 0;
|
||||||
|
public float $successRateLast24h = 0.0;
|
||||||
|
public int $totalJobsLast7d = 0;
|
||||||
|
public int $completedJobsLast7d = 0;
|
||||||
|
public int $failedJobsLast7d = 0;
|
||||||
|
public float $successRateLast7d = 0.0;
|
||||||
|
public string $storagePath = '';
|
||||||
|
public int $storageTotalBytes = 0;
|
||||||
|
public int $storageFreeBytes = 0;
|
||||||
|
public int $storageUsedBytes = 0;
|
||||||
|
public string $storageTotalHuman = '';
|
||||||
|
public string $storageFreeHuman = '';
|
||||||
|
public string $storageUsedHuman = '';
|
||||||
|
public int $totalSources = 0;
|
||||||
|
/** @var array<string, int> */
|
||||||
|
public array $sourcesByHealth = [];
|
||||||
|
public string $phpVersion = '';
|
||||||
|
public string $generatedAt = '';
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\System\Infrastructure\ApiPlatform\State\Provider;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProviderInterface;
|
||||||
|
use App\Domain\System\Application\Query\GetSystemStatusQuery;
|
||||||
|
use App\Domain\System\Application\QueryHandler\GetSystemStatusQueryHandler;
|
||||||
|
use App\Domain\System\Domain\Model\SystemStatus;
|
||||||
|
use App\Domain\System\Infrastructure\ApiPlatform\Resource\GetSystemStatusResource;
|
||||||
|
|
||||||
|
final class GetSystemStatusStateProvider implements ProviderInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly GetSystemStatusQueryHandler $handler,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): GetSystemStatusResource
|
||||||
|
{
|
||||||
|
$response = $this->handler->handle(new GetSystemStatusQuery());
|
||||||
|
|
||||||
|
return $this->toResource($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function toResource(SystemStatus $response): GetSystemStatusResource
|
||||||
|
{
|
||||||
|
$resource = new GetSystemStatusResource();
|
||||||
|
$resource->id = 'current';
|
||||||
|
|
||||||
|
$resource->totalMangas = $response->totalMangas;
|
||||||
|
$resource->monitoredMangas = $response->monitoredMangas;
|
||||||
|
$resource->mangasByStatus = $response->mangasByStatus;
|
||||||
|
|
||||||
|
$resource->totalChapters = $response->totalChapters;
|
||||||
|
$resource->downloadedChapters = $response->downloadedChapters;
|
||||||
|
$resource->pendingChapters = $response->totalChapters - $response->downloadedChapters;
|
||||||
|
|
||||||
|
$resource->totalJobs = $response->totalJobs;
|
||||||
|
$resource->completedJobs = $response->completedJobs;
|
||||||
|
$resource->failedJobs = $response->failedJobs;
|
||||||
|
$resource->pendingJobs = $response->pendingJobs;
|
||||||
|
$resource->inProgressJobs = $response->inProgressJobs;
|
||||||
|
|
||||||
|
$resource->totalJobsLast24h = $response->totalJobsLast24h;
|
||||||
|
$resource->completedJobsLast24h = $response->completedJobsLast24h;
|
||||||
|
$resource->failedJobsLast24h = $response->failedJobsLast24h;
|
||||||
|
$resource->successRateLast24h = $response->totalJobsLast24h > 0
|
||||||
|
? round($response->completedJobsLast24h / $response->totalJobsLast24h * 100, 1)
|
||||||
|
: 0.0;
|
||||||
|
|
||||||
|
$resource->totalJobsLast7d = $response->totalJobsLast7d;
|
||||||
|
$resource->completedJobsLast7d = $response->completedJobsLast7d;
|
||||||
|
$resource->failedJobsLast7d = $response->failedJobsLast7d;
|
||||||
|
$resource->successRateLast7d = $response->totalJobsLast7d > 0
|
||||||
|
? round($response->completedJobsLast7d / $response->totalJobsLast7d * 100, 1)
|
||||||
|
: 0.0;
|
||||||
|
|
||||||
|
$resource->storagePath = $response->storagePath;
|
||||||
|
$resource->storageTotalBytes = $response->storageTotalBytes;
|
||||||
|
$resource->storageFreeBytes = $response->storageFreeBytes;
|
||||||
|
$resource->storageUsedBytes = $response->storageUsedBytes;
|
||||||
|
$resource->storageTotalHuman = $this->formatBytes($response->storageTotalBytes);
|
||||||
|
$resource->storageFreeHuman = $this->formatBytes($response->storageFreeBytes);
|
||||||
|
$resource->storageUsedHuman = $this->formatBytes($response->storageUsedBytes);
|
||||||
|
|
||||||
|
$resource->totalSources = $response->totalSources;
|
||||||
|
$resource->sourcesByHealth = $response->sourcesByHealth;
|
||||||
|
|
||||||
|
$resource->phpVersion = $response->phpVersion;
|
||||||
|
$resource->generatedAt = $response->generatedAt->format(\DateTimeInterface::ATOM);
|
||||||
|
|
||||||
|
return $resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatBytes(int $bytes): string
|
||||||
|
{
|
||||||
|
if ($bytes <= 0) {
|
||||||
|
return '0 B';
|
||||||
|
}
|
||||||
|
|
||||||
|
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||||
|
$exp = (int) floor(log($bytes, 1024));
|
||||||
|
$exp = min($exp, count($units) - 1);
|
||||||
|
|
||||||
|
return round($bytes / (1024 ** $exp), 2) . ' ' . $units[$exp];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\System\Infrastructure\Persistence\Repository;
|
||||||
|
|
||||||
|
use App\Domain\System\Domain\Contract\Repository\SystemStatusRepositoryInterface;
|
||||||
|
use App\Entity\Chapter;
|
||||||
|
use App\Entity\ContentSource;
|
||||||
|
use App\Entity\Manga;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
class DoctrineSystemStatusRepository implements SystemStatusRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countMangas(): int
|
||||||
|
{
|
||||||
|
return (int) $this->entityManager
|
||||||
|
->createQuery('SELECT COUNT(m) FROM ' . Manga::class . ' m')
|
||||||
|
->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countMonitoredMangas(): int
|
||||||
|
{
|
||||||
|
return (int) $this->entityManager
|
||||||
|
->createQuery('SELECT COUNT(m) FROM ' . Manga::class . ' m WHERE m.monitored = true')
|
||||||
|
->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countMangasByStatus(): array
|
||||||
|
{
|
||||||
|
$results = $this->entityManager
|
||||||
|
->createQuery('SELECT m.status, COUNT(m) as cnt FROM ' . Manga::class . ' m GROUP BY m.status')
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
$counts = [];
|
||||||
|
foreach ($results as $row) {
|
||||||
|
$status = $row['status'] ?? 'unknown';
|
||||||
|
$counts[$status] = (int) $row['cnt'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countChapters(): int
|
||||||
|
{
|
||||||
|
return (int) $this->entityManager
|
||||||
|
->createQuery('SELECT COUNT(c) FROM ' . Chapter::class . ' c')
|
||||||
|
->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countDownloadedChapters(): int
|
||||||
|
{
|
||||||
|
return (int) $this->entityManager
|
||||||
|
->createQuery('SELECT COUNT(c) FROM ' . Chapter::class . ' c WHERE c.cbzPath IS NOT NULL')
|
||||||
|
->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countContentSources(): int
|
||||||
|
{
|
||||||
|
return (int) $this->entityManager
|
||||||
|
->createQuery('SELECT COUNT(s) FROM ' . ContentSource::class . ' s')
|
||||||
|
->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countContentSourcesByHealth(): array
|
||||||
|
{
|
||||||
|
$results = $this->entityManager
|
||||||
|
->createQuery('SELECT s.healthStatus, COUNT(s) as cnt FROM ' . ContentSource::class . ' s GROUP BY s.healthStatus')
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
$counts = [];
|
||||||
|
foreach ($results as $row) {
|
||||||
|
$counts[$row['healthStatus']] = (int) $row['cnt'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $counts;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user