| | private function renderBlob($targetHash) { |
| | $repoParam = '&repo=' . urlencode($this->currentRepo['safe_name']); |
| | - |
| | $size = $this->git->getObjectSize($targetHash); |
| | |
| | $buffer = ''; |
| | $this->git->stream($targetHash, function($d) use (&$buffer) { |
| | if (strlen($buffer) < 12) $buffer .= $d; |
| | }); |
| | |
| | $filename = $_GET['name'] ?? ''; |
| | $category = MediaTypeSniffer::isCategory($buffer, $filename); |
| | - $mimeType = MediaTypeSniffer::isMediaType($buffer, $filename); |
| | + $mediaType = MediaTypeSniffer::isMediaType($buffer, $filename); |
| | |
| | $this->renderBreadcrumbs($targetHash, 'File'); |
| | |
| | - // UPDATED: Handle empty files |
| | if ($size === 0) { |
| | $this->renderDownloadState($targetHash, "This file is empty."); |
| | return; |
| | } |
| | |
| | $rawUrl = '?action=raw&hash=' . $targetHash . $repoParam . '&name=' . urlencode($filename); |
| | |
| | - if ($category === MediaTypeSniffer::CAT_VIDEO) { |
| | + if ($category === MediaTypeSniffer::CAT_IMAGE) { |
| | + echo '<div class="blob-content" style="text-align:center; padding: 20px; background: #f6f8fa;">'; |
| | + echo '<img src="' . $rawUrl . '" style="max-width: 100%; border: 1px solid #dfe2e5;">'; |
| | + echo '</div>'; |
| | + } elseif ($category === MediaTypeSniffer::CAT_VIDEO) { |
| | echo '<div class="blob-content" style="text-align:center; padding: 20px; background: #000;">'; |
| | echo '<video controls style="max-width: 100%; max-height: 80vh;">'; |
| | - echo '<source src="' . $rawUrl . '" type="' . $mimeType . '">'; |
| | - echo 'Your browser does not support the video element.'; |
| | + echo '<source src="' . $rawUrl . '" type="' . $mediaType . '">'; |
| | echo '</video>'; |
| | echo '</div>'; |
| | - |
| | } elseif ($category === MediaTypeSniffer::CAT_AUDIO) { |
| | echo '<div class="blob-content" style="text-align:center; padding: 40px; background: #f6f8fa;">'; |
| | echo '<audio controls style="width: 100%; max-width: 600px;">'; |
| | - echo '<source src="' . $rawUrl . '" type="' . $mimeType . '">'; |
| | - echo 'Your browser does not support the audio element.'; |
| | + echo '<source src="' . $rawUrl . '" type="' . $mediaType . '">'; |
| | echo '</audio>'; |
| | - echo '</div>'; |
| | - |
| | - } elseif ($category === MediaTypeSniffer::CAT_IMAGE) { |
| | - echo '<div class="blob-content" style="text-align:center; padding: 20px; background: #f6f8fa;">'; |
| | - echo '<img src="' . $rawUrl . '" style="max-width: 100%; border: 1px solid #dfe2e5;">'; |
| | echo '</div>'; |
| | - |
| | } elseif ($category === MediaTypeSniffer::CAT_TEXT) { |
| | if ($size > 524288) { |
| | $this->renderDownloadState($targetHash, "File is too large to display (" . $this->formatSize($size) . ")."); |
| | } else { |
| | $content = ''; |
| | $this->git->stream($targetHash, function($d) use (&$content) { $content .= $d; }); |
| | echo '<div class="blob-content"><pre class="blob-code">' . htmlspecialchars($content) . '</pre></div>'; |
| | } |
| | - |
| | } else { |
| | $this->renderDownloadState($targetHash, "This is a binary file."); |