From 572327a65199b8ba5dad8fc7b6cd0d061cf9afb8 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Tue, 11 Aug 2026 15:31:07 +0200 Subject: [PATCH] Lot E : cas PDF dans ResourceViewer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sans ce cas, un PDF tombait dans le rendu image par défaut et s'affichait en image cassée — le même défaut que celui corrigé pour la vidéo le 09/08. Réutilise le PdfViewer existant et son proxy /api/pdf (le contournement CORS était déjà écrit), importé en dynamic({ssr:false}) comme le fait PdfSection. npm run build ✅. Co-Authored-By: Claude Opus 5 --- src/components/ui/ResourceViewer.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/components/ui/ResourceViewer.tsx b/src/components/ui/ResourceViewer.tsx index db06b29..0a8d76d 100644 --- a/src/components/ui/ResourceViewer.tsx +++ b/src/components/ui/ResourceViewer.tsx @@ -1,13 +1,18 @@ 'use client' +import dynamic from 'next/dynamic' import Image from 'next/image' import type { ResourceDTO } from '@/lib/api/types' +// Même stratégie que PdfSection : react-pdf a besoin de `window`. +const PdfViewer = dynamic(() => import('@/components/sections/pdf/PdfViewer'), { ssr: false }) + // Mirrors C# ResourceType enum — backend may serialize as int OR as string name const IMAGES = new Set([0, 2, 'Image', 'ImageUrl']) const VIDEOS = new Set([1, 3, 'Video', 'VideoUrl']) const AUDIOS = new Set([4, 'Audio']) const VIDEO_URLS = new Set([3, 'VideoUrl']) +const PDFS = new Set([5, 'PDF']) /** An absent type falls back to image rendering below — treat it as an image here too. */ export function isImageResource(type: unknown): boolean { @@ -81,6 +86,16 @@ export default function ResourceViewer({ resource, alt = '', objectFit = 'contai ) } + // PDF — sans ce cas, un PDF tombait dans le rendu image ci-dessous et + // s'affichait en image cassée. Même défaut que celui corrigé pour la vidéo. + if (t !== undefined && PDFS.has(t as never)) { + return ( +
+ +
+ ) + } + // Image, ImageUrl, or unknown → render as image (safe default) return (