Add admin panel, WebSocket support, and API versioning
Introduce an admin portal (React + Nginx), WebSocket routing, and API versioning middleware with `/api/v1/` prefix deprecation. Add master API key authentication, new Prometheus metrics for AI token consumption and active WebSockets, and extend S3 config with a public endpoint URL. Update test paths and fixtures to align with the new routing structure.
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { PageLayout } from '@/components/layout/PageLayout';
|
||||
import { PlanBadge } from '@/components/shared/PlanBadge';
|
||||
import { StatusBadge } from '@/components/shared/StatusBadge';
|
||||
import { Pagination } from '@/components/shared/Pagination';
|
||||
import { EmptyState } from '@/components/shared/EmptyState';
|
||||
import { ImageGridSkeleton } from '@/components/shared/Skeleton';
|
||||
import { SearchInput } from '@/components/shared/SearchInput';
|
||||
import { ImageLoader } from '@/components/shared/ImageLoader';
|
||||
import { useImages } from '@/hooks/useImages';
|
||||
import { useClient } from '@/hooks/useClients';
|
||||
import { formatDate, formatBytes, truncate } from '@/utils/formatters';
|
||||
import { ArrowLeft, ExternalLink, Images, Camera } from 'lucide-react';
|
||||
import { useState, useCallback } from 'react';
|
||||
|
||||
export default function ClientGallery() {
|
||||
const { clientId } = useParams<{ clientId: string }>();
|
||||
const { data: client } = useClient(clientId);
|
||||
const [page, setPage] = useState(1);
|
||||
const [search, setSearch] = useState('');
|
||||
|
||||
const { data, isLoading } = useImages({
|
||||
client_id: clientId,
|
||||
search: search || undefined,
|
||||
page,
|
||||
page_size: 20,
|
||||
sort_by: 'uploaded_at',
|
||||
sort_order: 'desc',
|
||||
});
|
||||
|
||||
const images = data?.items ?? [];
|
||||
const total = data?.total ?? 0;
|
||||
const totalPages = data?.pages ?? 1;
|
||||
|
||||
const handleSearch = useCallback((value: string) => {
|
||||
setSearch(value);
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<PageLayout
|
||||
title={client ? `Images de "${client.name}"` : 'Galerie client'}
|
||||
description={
|
||||
client
|
||||
? `${total} image${total !== 1 ? 's' : ''} · ${formatBytes(client.storage_used_bytes)} utilisés`
|
||||
: undefined
|
||||
}
|
||||
actions={
|
||||
<div className="flex items-center gap-2">
|
||||
{client && <PlanBadge plan={client.plan} />}
|
||||
{client && (
|
||||
<Link to={`/admin/clients/${client.id}`} className="btn-ghost text-sm flex items-center gap-1">
|
||||
Détail client <ExternalLink size={12} />
|
||||
</Link>
|
||||
)}
|
||||
<Link to="/gallery" className="btn-ghost text-sm flex items-center gap-1">
|
||||
<ArrowLeft size={14} /> Toutes les images
|
||||
</Link>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{/* Search */}
|
||||
<div className="mb-6">
|
||||
<SearchInput
|
||||
value={search}
|
||||
onChange={handleSearch}
|
||||
placeholder="Rechercher dans les images de ce client…"
|
||||
className="max-w-md"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Grid */}
|
||||
{isLoading ? (
|
||||
<ImageGridSkeleton count={8} />
|
||||
) : images.length === 0 ? (
|
||||
<EmptyState
|
||||
title="Aucune image"
|
||||
description={search ? 'Aucun résultat pour cette recherche' : 'Ce client n\'a pas encore uploadé d\'images'}
|
||||
icon={<Images size={32} className="text-content-muted" />}
|
||||
/>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
||||
{images.map((img) => (
|
||||
<Link
|
||||
key={img.id}
|
||||
to={`/gallery/image/${img.id}`}
|
||||
className="card-compact group hover:border-border-light transition-all duration-200 hover:-translate-y-0.5"
|
||||
>
|
||||
<ImageLoader
|
||||
imageId={img.id}
|
||||
alt={img.original_name}
|
||||
className="mb-3"
|
||||
/>
|
||||
<div className="space-y-1.5">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<p className="text-sm font-medium text-content-primary truncate">{truncate(img.original_name, 25)}</p>
|
||||
<StatusBadge status={img.processing_status} />
|
||||
</div>
|
||||
{img.ai_tags?.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{img.ai_tags?.slice(0, 3).map((tag) => (
|
||||
<span key={tag} className="text-[10px] bg-surface-overlay text-content-muted px-1.5 py-0.5 rounded">{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-2 text-xs text-content-muted">
|
||||
<span>{formatDate(img.uploaded_at)}</span>
|
||||
{img.exif_make && (
|
||||
<span className="flex items-center gap-1"><Camera size={10} /> {img.exif_make}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Pagination */}
|
||||
{totalPages > 1 && (
|
||||
<div className="flex justify-center mt-6">
|
||||
<Pagination page={page} totalPages={totalPages} onPageChange={setPage} />
|
||||
</div>
|
||||
)}
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { PageLayout } from '@/components/layout/PageLayout';
|
||||
import { SearchInput } from '@/components/shared/SearchInput';
|
||||
import { StatusBadge } from '@/components/shared/StatusBadge';
|
||||
import { Pagination } from '@/components/shared/Pagination';
|
||||
import { EmptyState } from '@/components/shared/EmptyState';
|
||||
import { ImageGridSkeleton } from '@/components/shared/Skeleton';
|
||||
import { useImages } from '@/hooks/useImages';
|
||||
import { useClients } from '@/hooks/useClients';
|
||||
import { useImagesStore } from '@/store/images.store';
|
||||
import { formatDate, formatBytes, truncate } from '@/utils/formatters';
|
||||
import { getClientColor, getClientBgColor } from '@/utils/colors';
|
||||
import { Grid3X3, List, Camera, Tag, X, Filter, Images as ImagesIcon } from 'lucide-react';
|
||||
import { ImageLoader } from '@/components/shared/ImageLoader';
|
||||
import { clsx } from 'clsx';
|
||||
import type { ImageFilters } from '@/types/api.types';
|
||||
|
||||
export default function Gallery() {
|
||||
const { filters, viewMode, setFilters, resetFilters, setViewMode } = useImagesStore();
|
||||
const { data, isLoading, error, refetch } = useImages(filters);
|
||||
const { data: clients } = useClients();
|
||||
|
||||
const [showFilters, setShowFilters] = useState(false);
|
||||
|
||||
const images = data?.items ?? [];
|
||||
const total = data?.total ?? 0;
|
||||
const totalPages = data?.pages ?? 1;
|
||||
|
||||
const handleSearch = useCallback((search: string) => {
|
||||
setFilters({ search: search || undefined });
|
||||
}, [setFilters]);
|
||||
|
||||
const handlePageChange = useCallback((page: number) => {
|
||||
setFilters({ page });
|
||||
}, [setFilters]);
|
||||
|
||||
const activeFilterCount = [
|
||||
filters.client_id,
|
||||
filters.tags?.length,
|
||||
filters.status?.length,
|
||||
filters.has_gps,
|
||||
filters.has_ocr,
|
||||
filters.date_from,
|
||||
].filter(Boolean).length;
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<PageLayout title="Galerie">
|
||||
<div className="card text-center py-12">
|
||||
<p className="text-status-error mb-4">Erreur de chargement des images</p>
|
||||
<button onClick={() => refetch()} className="btn-primary">Réessayer</button>
|
||||
</div>
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<PageLayout
|
||||
title="Galerie"
|
||||
description={`${total} image${total !== 1 ? 's' : ''}`}
|
||||
actions={
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={() => setViewMode('grid')}
|
||||
className={clsx('p-2 rounded-lg transition-colors', viewMode === 'grid' ? 'bg-brand-500/20 text-brand-400' : 'text-content-muted hover:bg-surface-overlay')}
|
||||
aria-label="Vue grille"
|
||||
>
|
||||
<Grid3X3 size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setViewMode('list')}
|
||||
className={clsx('p-2 rounded-lg transition-colors', viewMode === 'list' ? 'bg-brand-500/20 text-brand-400' : 'text-content-muted hover:bg-surface-overlay')}
|
||||
aria-label="Vue liste"
|
||||
>
|
||||
<List size={16} />
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{/* Search & Filters */}
|
||||
<div className="flex flex-wrap items-center gap-3 mb-4">
|
||||
<SearchInput
|
||||
value={filters.search || ''}
|
||||
onChange={handleSearch}
|
||||
placeholder="Rechercher dans description, OCR, tags…"
|
||||
className="flex-1 min-w-[250px]"
|
||||
/>
|
||||
<button
|
||||
onClick={() => setShowFilters(!showFilters)}
|
||||
className={clsx('btn-secondary text-sm flex items-center gap-2', activeFilterCount > 0 && 'bg-brand-500/10 text-brand-400')}
|
||||
>
|
||||
<Filter size={14} />
|
||||
Filtres {activeFilterCount > 0 && `(${activeFilterCount})`}
|
||||
</button>
|
||||
{activeFilterCount > 0 && (
|
||||
<button onClick={resetFilters} className="text-xs text-content-muted hover:text-content-primary flex items-center gap-1">
|
||||
<X size={12} /> Effacer tout
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Active filter chips */}
|
||||
{activeFilterCount > 0 && (
|
||||
<div className="flex flex-wrap gap-2 mb-4">
|
||||
{filters.client_id && (
|
||||
<span className="badge bg-surface-overlay text-content-secondary">
|
||||
Client: {clients?.find((c) => c.id === filters.client_id)?.name || filters.client_id?.slice(0, 8)}
|
||||
<button onClick={() => setFilters({ client_id: undefined })} className="ml-1"><X size={10} /></button>
|
||||
</span>
|
||||
)}
|
||||
{filters.tags?.map((tag) => (
|
||||
<span key={tag} className="badge bg-surface-overlay text-content-secondary">
|
||||
<Tag size={10} /> {tag}
|
||||
<button onClick={() => setFilters({ tags: filters.tags?.filter((t) => t !== tag) })} className="ml-1"><X size={10} /></button>
|
||||
</span>
|
||||
))}
|
||||
{filters.status?.map((s) => (
|
||||
<span key={s} className="badge bg-surface-overlay text-content-secondary">
|
||||
{s}
|
||||
<button onClick={() => setFilters({ status: filters.status?.filter((st) => st !== s) })} className="ml-1"><X size={10} /></button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Filter panel */}
|
||||
{showFilters && (
|
||||
<div className="card mb-6 animate-slide-in">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-content-muted mb-1">Application</label>
|
||||
<select
|
||||
value={filters.client_id || ''}
|
||||
onChange={(e) => setFilters({ client_id: e.target.value || undefined })}
|
||||
className="input-field w-full text-sm"
|
||||
>
|
||||
<option value="">Toutes</option>
|
||||
{clients?.map((c) => <option key={c.id} value={c.id}>{c.name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-content-muted mb-1">Statut pipeline</label>
|
||||
<select
|
||||
value={filters.status?.[0] || ''}
|
||||
onChange={(e) => setFilters({ status: e.target.value ? [e.target.value as ImageFilters['status'] extends (infer U)[] ? U : never] : undefined })}
|
||||
className="input-field w-full text-sm"
|
||||
>
|
||||
<option value="">Tous</option>
|
||||
<option value="done">Terminé</option>
|
||||
<option value="processing">En cours</option>
|
||||
<option value="pending">En attente</option>
|
||||
<option value="error">Erreur</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-content-muted mb-1">Tri par</label>
|
||||
<select
|
||||
value={filters.sort_by || 'uploaded_at'}
|
||||
onChange={(e) => setFilters({ sort_by: e.target.value })}
|
||||
className="input-field w-full text-sm"
|
||||
>
|
||||
<option value="uploaded_at">Date d'upload</option>
|
||||
<option value="file_size">Taille</option>
|
||||
<option value="original_name">Nom</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-content-muted mb-1">Ordre</label>
|
||||
<select
|
||||
value={filters.sort_order || 'desc'}
|
||||
onChange={(e) => setFilters({ sort_order: e.target.value as 'asc' | 'desc' })}
|
||||
className="input-field w-full text-sm"
|
||||
>
|
||||
<option value="desc">Plus récent d'abord</option>
|
||||
<option value="asc">Plus ancien d'abord</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="flex items-end gap-4">
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={filters.has_gps === true}
|
||||
onChange={(e) => setFilters({ has_gps: e.target.checked ? true : undefined })}
|
||||
className="rounded border-border bg-surface text-brand-500 focus:ring-brand-500"
|
||||
/>
|
||||
<span className="text-sm text-content-secondary">Avec GPS</span>
|
||||
</label>
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={filters.has_ocr === true}
|
||||
onChange={(e) => setFilters({ has_ocr: e.target.checked ? true : undefined })}
|
||||
className="rounded border-border bg-surface text-brand-500 focus:ring-brand-500"
|
||||
/>
|
||||
<span className="text-sm text-content-secondary">Avec texte OCR</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Results */}
|
||||
{isLoading ? (
|
||||
<ImageGridSkeleton count={8} />
|
||||
) : images.length === 0 ? (
|
||||
<EmptyState
|
||||
title="Aucune image trouvée"
|
||||
description={filters.search ? 'Essayez avec d\'autres termes' : 'Aucune image n\'a été uploadée'}
|
||||
icon={<ImagesIcon size={32} className="text-content-muted" />}
|
||||
/>
|
||||
) : viewMode === 'grid' ? (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
||||
{images.map((img) => (
|
||||
<Link
|
||||
key={img.id}
|
||||
to={`/gallery/image/${img.id}`}
|
||||
className="card-compact group hover:border-border-light transition-all duration-200 hover:-translate-y-0.5"
|
||||
>
|
||||
<ImageLoader
|
||||
imageId={img.id}
|
||||
alt={img.original_name}
|
||||
className="mb-3"
|
||||
/>
|
||||
<div className="space-y-1.5">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<p className="text-sm font-medium text-content-primary truncate">{truncate(img.original_name, 25)}</p>
|
||||
<StatusBadge status={img.processing_status} />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className="badge text-[10px]"
|
||||
style={{ backgroundColor: getClientBgColor(img.client_id), color: getClientColor(img.client_id) }}
|
||||
>
|
||||
{img.client_name || img.client_id?.slice(0, 8)}
|
||||
</span>
|
||||
</div>
|
||||
{img.ai_tags?.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{img.ai_tags?.slice(0, 3).map((tag) => (
|
||||
<span key={tag} className="text-[10px] bg-surface-overlay text-content-muted px-1.5 py-0.5 rounded">
|
||||
{tag}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-2 text-xs text-content-muted">
|
||||
<span>{formatDate(img.uploaded_at)}</span>
|
||||
{img.exif_make && (
|
||||
<span className="flex items-center gap-1">
|
||||
<Camera size={10} /> {img.exif_make} {img.exif_model}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
/* List view */
|
||||
<div className="card overflow-hidden p-0">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border text-left">
|
||||
<th className="py-3 px-4 font-medium text-content-muted">Nom</th>
|
||||
<th className="py-3 px-4 font-medium text-content-muted">Client</th>
|
||||
<th className="py-3 px-4 font-medium text-content-muted">Statut</th>
|
||||
<th className="py-3 px-4 font-medium text-content-muted">Taille</th>
|
||||
<th className="py-3 px-4 font-medium text-content-muted">Tags</th>
|
||||
<th className="py-3 px-4 font-medium text-content-muted">Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{images.map((img) => (
|
||||
<tr key={img.id} className="border-b border-border/50 hover:bg-surface-overlay/50 transition-colors">
|
||||
<td className="py-3 px-4">
|
||||
<Link to={`/gallery/image/${img.id}`} className="font-medium hover:text-brand-400">
|
||||
{truncate(img.original_name, 30)}
|
||||
</Link>
|
||||
</td>
|
||||
<td className="py-3 px-4">
|
||||
<span className="badge text-xs" style={{ backgroundColor: getClientBgColor(img.client_id), color: getClientColor(img.client_id) }}>
|
||||
{img.client_name || img.client_id?.slice(0, 8)}
|
||||
</span>
|
||||
</td>
|
||||
<td className="py-3 px-4"><StatusBadge status={img.processing_status} /></td>
|
||||
<td className="py-3 px-4 text-content-muted">{formatBytes(img.file_size)}</td>
|
||||
<td className="py-3 px-4">
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{img.ai_tags?.slice(0, 3).map((tag) => (
|
||||
<span key={tag} className="text-[10px] bg-surface-overlay text-content-muted px-1 rounded">{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
</td>
|
||||
<td className="py-3 px-4 text-content-muted text-xs">{formatDate(img.uploaded_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Pagination */}
|
||||
{totalPages > 1 && (
|
||||
<div className="flex justify-center mt-6">
|
||||
<Pagination page={filters.page || 1} totalPages={totalPages} onPageChange={handlePageChange} />
|
||||
</div>
|
||||
)}
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams, Link, useNavigate } from 'react-router-dom';
|
||||
import { PageLayout } from '@/components/layout/PageLayout';
|
||||
import { StatusBadge } from '@/components/shared/StatusBadge';
|
||||
import { PlanBadge } from '@/components/shared/PlanBadge';
|
||||
import { ConfirmDialog } from '@/components/shared/ConfirmDialog';
|
||||
import { CardSkeleton } from '@/components/shared/Skeleton';
|
||||
import { toast } from '@/components/shared/Toast';
|
||||
import { useImage, useReprocessImage, useDeleteImage } from '@/hooks/useImages';
|
||||
import { useClient } from '@/hooks/useClients';
|
||||
import { formatDate, formatDateTime, formatBytes, formatNumber } from '@/utils/formatters';
|
||||
import { getClientColor, getClientBgColor } from '@/utils/colors';
|
||||
import {
|
||||
ArrowLeft, RefreshCw, Trash2, Camera, FileText, Bot,
|
||||
Settings, UserCircle, Tag, Loader2, ExternalLink,
|
||||
} from 'lucide-react';
|
||||
import { ImageLoader } from '@/components/shared/ImageLoader';
|
||||
import { clsx } from 'clsx';
|
||||
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
|
||||
import type { LatLngExpression } from 'leaflet';
|
||||
import L from 'leaflet';
|
||||
|
||||
// Fix default marker icon
|
||||
import markerIcon2x from 'leaflet/dist/images/marker-icon-2x.png';
|
||||
import markerIcon from 'leaflet/dist/images/marker-icon.png';
|
||||
import markerShadow from 'leaflet/dist/images/marker-shadow.png';
|
||||
|
||||
delete (L.Icon.Default.prototype as unknown as Record<string, unknown>)._getIconUrl;
|
||||
L.Icon.Default.mergeOptions({
|
||||
iconRetinaUrl: markerIcon2x,
|
||||
iconUrl: markerIcon,
|
||||
shadowUrl: markerShadow,
|
||||
});
|
||||
|
||||
type TabId = 'ai' | 'exif' | 'ocr' | 'tech' | 'provenance';
|
||||
|
||||
export default function ImageDetail() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const { data: image, isLoading } = useImage(id ? Number(id) : undefined);
|
||||
const { data: client } = useClient(image?.client_id);
|
||||
const reprocessMut = useReprocessImage();
|
||||
const deleteMut = useDeleteImage();
|
||||
const [activeTab, setActiveTab] = useState<TabId>('ai');
|
||||
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||
|
||||
const handleReprocess = async () => {
|
||||
if (!image) return;
|
||||
try {
|
||||
await reprocessMut.mutateAsync(image.id);
|
||||
toast('success', 'Image remise en file de traitement');
|
||||
} catch {
|
||||
toast('error', 'Erreur lors du retraitement');
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (!image) return;
|
||||
try {
|
||||
await deleteMut.mutateAsync(image.id);
|
||||
toast('success', 'Image supprimée');
|
||||
navigate('/gallery');
|
||||
} catch {
|
||||
toast('error', 'Erreur lors de la suppression');
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<PageLayout title="Chargement…">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
<CardSkeleton />
|
||||
<CardSkeleton />
|
||||
</div>
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
|
||||
if (!image) {
|
||||
return (
|
||||
<PageLayout title="Image introuvable">
|
||||
<Link to="/gallery" className="btn-secondary flex items-center gap-2 w-fit">
|
||||
<ArrowLeft size={16} /> Retour à la galerie
|
||||
</Link>
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
|
||||
const hasGps = image.exif_gps_lat != null && image.exif_gps_lon != null;
|
||||
const position: LatLngExpression | null = hasGps ? [image.exif_gps_lat!, image.exif_gps_lon!] : null;
|
||||
|
||||
const tabs: { id: TabId; label: string; icon: typeof Bot }[] = [
|
||||
{ id: 'ai', label: 'Vision AI', icon: Bot },
|
||||
{ id: 'exif', label: 'EXIF', icon: Camera },
|
||||
{ id: 'ocr', label: 'OCR', icon: FileText },
|
||||
{ id: 'tech', label: 'Technique', icon: Settings },
|
||||
{ id: 'provenance', label: 'Provenance', icon: UserCircle },
|
||||
];
|
||||
|
||||
return (
|
||||
<PageLayout
|
||||
title={image.original_name}
|
||||
description={`Uploadé le ${formatDateTime(image.uploaded_at)}`}
|
||||
actions={
|
||||
<div className="flex items-center gap-2">
|
||||
<StatusBadge status={image.processing_status} size="md" />
|
||||
<button onClick={handleReprocess} disabled={reprocessMut.isPending} className="btn-secondary text-sm flex items-center gap-2">
|
||||
{reprocessMut.isPending ? <Loader2 size={14} className="animate-spin" /> : <RefreshCw size={14} />}
|
||||
Reprocesser
|
||||
</button>
|
||||
<button onClick={() => setConfirmDelete(true)} className="btn-danger text-sm flex items-center gap-2">
|
||||
<Trash2 size={14} /> Supprimer
|
||||
</button>
|
||||
<Link to="/gallery" className="btn-ghost text-sm flex items-center gap-1">
|
||||
<ArrowLeft size={14} /> Retour
|
||||
</Link>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
{/* Left: Image */}
|
||||
<div className="card flex items-center justify-center min-h-[400px]">
|
||||
<div className="text-center space-y-4 w-full">
|
||||
<ImageLoader
|
||||
imageId={image.id}
|
||||
alt={image.original_name}
|
||||
aspectRatio="aspect-square"
|
||||
className="max-w-xs mx-auto shadow-lg"
|
||||
/>
|
||||
<div>
|
||||
<p className="text-content-secondary text-sm font-medium">{image.original_name}</p>
|
||||
<p className="text-content-muted text-xs mt-1">
|
||||
{image.width && image.height ? `${image.width} × ${image.height}px · ` : ''}{formatBytes(image.file_size)} · {image.mime_type}
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
className="inline-flex badge text-xs"
|
||||
style={{ backgroundColor: getClientBgColor(image.client_id), color: getClientColor(image.client_id) }}
|
||||
>
|
||||
{image.client_name || image.client_id?.slice(0, 8)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right: Tabs */}
|
||||
<div>
|
||||
<div className="flex gap-1 mb-4 overflow-x-auto">
|
||||
{tabs.map((tab) => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActiveTab(tab.id)}
|
||||
className={clsx(
|
||||
'flex items-center gap-1.5 px-3 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap',
|
||||
activeTab === tab.id
|
||||
? 'bg-brand-500/10 text-brand-400'
|
||||
: 'text-content-secondary hover:bg-surface-overlay',
|
||||
)}
|
||||
>
|
||||
<tab.icon size={14} />
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="card animate-fade-in">
|
||||
{/* AI Tab */}
|
||||
{activeTab === 'ai' && (
|
||||
<div className="space-y-4">
|
||||
{image.ai_description ? (
|
||||
<>
|
||||
<div>
|
||||
<h4 className="text-xs font-medium text-content-muted mb-2">Description</h4>
|
||||
<p className="text-sm text-content-primary leading-relaxed">{image.ai_description}</p>
|
||||
</div>
|
||||
{image.ai_tags?.length > 0 && (
|
||||
<div>
|
||||
<h4 className="text-xs font-medium text-content-muted mb-2">Tags</h4>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{image.ai_tags.map((tag) => (
|
||||
<Link
|
||||
key={tag}
|
||||
to={`/gallery?tags=${tag}`}
|
||||
className="badge bg-brand-500/10 text-brand-400 hover:bg-brand-500/20 transition-colors"
|
||||
>
|
||||
<Tag size={10} /> {tag}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{image.ai_confidence != null && (
|
||||
<div>
|
||||
<h4 className="text-xs font-medium text-content-muted mb-2">Confiance</h4>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex-1 h-2 bg-surface-overlay rounded-full overflow-hidden">
|
||||
<div className="h-full bg-brand-500 rounded-full" style={{ width: `${image.ai_confidence * 100}%` }} />
|
||||
</div>
|
||||
<span className="text-sm font-mono text-content-primary">{(image.ai_confidence * 100).toFixed(1)}%</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid grid-cols-2 gap-3 pt-2 border-t border-border">
|
||||
<div className="text-xs"><span className="text-content-muted">Modèle:</span> <span className="text-content-primary">{image.ai_model_used || '—'}</span></div>
|
||||
<div className="text-xs"><span className="text-content-muted">Tokens:</span> <span className="text-content-primary">{image.ai_prompt_tokens ? `${formatNumber(image.ai_prompt_tokens)} prompt / ${formatNumber(image.ai_output_tokens || 0)} output` : '—'}</span></div>
|
||||
<div className="text-xs"><span className="text-content-muted">Date:</span> <span className="text-content-primary">{image.ai_processed_at ? formatDateTime(image.ai_processed_at) : '—'}</span></div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-content-muted text-sm text-center py-4">Analyse AI non disponible</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* EXIF Tab */}
|
||||
{activeTab === 'exif' && (
|
||||
<div className="space-y-3">
|
||||
<ExifRow icon="📷" label="Appareil" value={[image.exif_make, image.exif_model].filter(Boolean).join(' ') || null} />
|
||||
<ExifRow icon="🔭" label="Objectif" value={image.exif_lens} />
|
||||
<ExifRow icon="📅" label="Prise de vue" value={image.exif_taken_at ? formatDateTime(image.exif_taken_at) : null} />
|
||||
<ExifRow icon="⚙️" label="Paramètres" value={
|
||||
[
|
||||
image.exif_iso && `ISO ${image.exif_iso}`,
|
||||
image.exif_aperture && `f/${image.exif_aperture}`,
|
||||
image.exif_shutter,
|
||||
image.exif_focal && `${image.exif_focal}mm`,
|
||||
].filter(Boolean).join(' · ') || null
|
||||
} />
|
||||
<ExifRow icon="📍" label="Localisation" value={hasGps ? `${image.exif_gps_lat!.toFixed(4)}°, ${image.exif_gps_lon!.toFixed(4)}°` : null} />
|
||||
<ExifRow icon="🧭" label="Altitude" value={image.exif_altitude != null ? `${image.exif_altitude}m` : null} />
|
||||
|
||||
{position && (
|
||||
<div className="mt-4 rounded-lg overflow-hidden border border-border" style={{ height: '250px' }}>
|
||||
<MapContainer center={position} zoom={13} style={{ height: '100%', width: '100%' }} scrollWheelZoom={false}>
|
||||
<TileLayer
|
||||
attribution='© <a href="https://osm.org/copyright">OpenStreetMap</a>'
|
||||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
/>
|
||||
<Marker position={position}>
|
||||
<Popup>{image.original_name}</Popup>
|
||||
</Marker>
|
||||
</MapContainer>
|
||||
<div className="flex gap-2 p-2 bg-surface-raised text-xs">
|
||||
<a
|
||||
href={`https://www.google.com/maps?q=${image.exif_gps_lat},${image.exif_gps_lon}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-brand-400 hover:underline flex items-center gap-1"
|
||||
>
|
||||
Google Maps <ExternalLink size={10} />
|
||||
</a>
|
||||
<a
|
||||
href={`https://www.openstreetmap.org/?mlat=${image.exif_gps_lat}&mlon=${image.exif_gps_lon}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-brand-400 hover:underline flex items-center gap-1"
|
||||
>
|
||||
OpenStreetMap <ExternalLink size={10} />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* OCR Tab */}
|
||||
{activeTab === 'ocr' && (
|
||||
<div>
|
||||
{image.ocr_has_text && image.ocr_text ? (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center gap-2 text-xs text-content-muted">
|
||||
<span>Langue : {image.ocr_language || 'inconnue'}</span>
|
||||
{image.ocr_confidence != null && <span>· Confiance : {(image.ocr_confidence * 100).toFixed(0)}%</span>}
|
||||
</div>
|
||||
<pre className="bg-surface rounded-lg p-4 text-sm text-content-primary font-mono whitespace-pre-wrap max-h-[400px] overflow-y-auto">
|
||||
{image.ocr_text}
|
||||
</pre>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-content-muted text-sm text-center py-8">Aucun texte détecté dans cette image</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Tech Tab */}
|
||||
{activeTab === 'tech' && (
|
||||
<div className="space-y-3">
|
||||
<TechRow label="Dimensions" value={image.width && image.height ? `${image.width} × ${image.height} px` : '—'} />
|
||||
<TechRow label="Taille" value={formatBytes(image.file_size)} />
|
||||
<TechRow label="Format" value={image.mime_type} />
|
||||
<TechRow label="UUID" value={image.uuid} mono />
|
||||
<TechRow label="ID" value={String(image.id)} />
|
||||
<TechRow label="Fichier" value={image.filename} mono />
|
||||
<TechRow label="Statut pipeline" value={image.processing_status} />
|
||||
{image.processing_error && <TechRow label="Erreur" value={image.processing_error} error />}
|
||||
{image.processing_started_at && <TechRow label="Début traitement" value={formatDateTime(image.processing_started_at)} />}
|
||||
{image.processing_done_at && <TechRow label="Fin traitement" value={formatDateTime(image.processing_done_at)} />}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Provenance Tab */}
|
||||
{activeTab === 'provenance' && (
|
||||
<div className="space-y-4">
|
||||
{client ? (
|
||||
<>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-lg flex items-center justify-center" style={{ backgroundColor: getClientBgColor(client.id) }}>
|
||||
<UserCircle size={20} style={{ color: getClientColor(client.id) }} />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium text-content-primary">{client.name}</p>
|
||||
<div className="flex items-center gap-2 mt-0.5">
|
||||
<PlanBadge plan={client.plan} />
|
||||
<span className="text-xs text-content-muted">Créé le {formatDate(client.created_at)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="pt-3 space-y-2">
|
||||
<Link
|
||||
to={`/gallery/client/${client.id}`}
|
||||
className="text-sm text-brand-400 hover:text-brand-300 flex items-center gap-1"
|
||||
>
|
||||
Voir toutes les images de cette application <ExternalLink size={12} />
|
||||
</Link>
|
||||
<Link
|
||||
to={`/admin/clients/${client.id}`}
|
||||
className="text-sm text-brand-400 hover:text-brand-300 flex items-center gap-1"
|
||||
>
|
||||
Voir les détails du client <ExternalLink size={12} />
|
||||
</Link>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-content-muted text-sm">
|
||||
Client: {image.client_name || image.client_id}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
isOpen={confirmDelete}
|
||||
title="Supprimer cette image ?"
|
||||
message="L'image sera définitivement supprimée ainsi que toutes ses métadonnées."
|
||||
confirmLabel="Supprimer"
|
||||
onConfirm={handleDelete}
|
||||
onCancel={() => setConfirmDelete(false)}
|
||||
/>
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
|
||||
function ExifRow({ icon, label, value }: { icon: string; label: string; value: string | null }) {
|
||||
return (
|
||||
<div className="flex items-center gap-3 py-1">
|
||||
<span className="text-sm">{icon}</span>
|
||||
<span className="text-sm text-content-muted w-28 shrink-0">{label}</span>
|
||||
<span className="text-sm text-content-primary">{value || '—'}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TechRow({ label, value, mono, error }: { label: string; value: string; mono?: boolean; error?: boolean }) {
|
||||
return (
|
||||
<div className="flex items-start gap-3 py-1">
|
||||
<span className="text-sm text-content-muted w-32 shrink-0">{label}</span>
|
||||
<span className={clsx('text-sm break-all', mono && 'font-mono text-xs', error ? 'text-status-error' : 'text-content-primary')}>
|
||||
{value}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user