diff --git a/app/pages/page.tsx b/app/pages/page.tsx index c043523..3b60456 100644 --- a/app/pages/page.tsx +++ b/app/pages/page.tsx @@ -724,6 +724,26 @@ export default function CarnetPage() { const handleMissionFileSelect = async (file: { key: string; name: string; path: string }) => { if (!selectedMission) return; + // Check file extension to determine if it's a text file + const fileName = file.name.toLowerCase(); + const textExtensions = ['.md', '.txt', '.json', '.yaml', '.yml', '.csv', '.log', '.conf', '.config', '.ini', '.env']; + const isTextFile = textExtensions.some(ext => fileName.endsWith(ext)); + + // For binary files (PDF, images, etc.), download them instead + if (!isTextFile) { + try { + // Get the file URL for download + const fileUrl = `/api/missions/image/${file.key}`; + // Open in new tab or download + window.open(fileUrl, '_blank'); + return; + } catch (error) { + console.error('Error opening file:', error); + return; + } + } + + // For text files, fetch and open in editor try { const response = await fetch(`/api/missions/${selectedMission.id}/files`, { method: 'POST',