| | $name = $_GET['name'] ?? 'file'; |
| | $isImage = isImageFile($name); |
| | +$isVideo = isVideoFile($name); |
| | |
| | // Check file size before loading |
| | $repoPath = REPOS_PATH . '/' . basename($repo); |
| | $isBare = is_file($repoPath . '/HEAD') && !is_dir($repoPath . '/.git'); |
| | |
| | if ($isBare) { |
| | - $sizeCmd = "git --git-dir=" . escapeshellarg($repoPath) . " cat-file -s " . escapeshellarg($hash); |
| | + $sizeCmd = "git --git-dir=" . escapeshellarg($repoPath) . " cat-file -s " . escapeshellarg($hash); |
| | } else { |
| | - $sizeCmd = "cd " . escapeshellarg($repoPath) . " && git cat-file -s " . escapeshellarg($hash); |
| | + $sizeCmd = "cd " . escapeshellarg($repoPath) . " && git cat-file -s " . escapeshellarg($hash); |
| | } |
| | |
| | $fileSize = intval(trim(shell_exec($sizeCmd))); |
| | $maxDisplaySize = 10 * 1024 * 1024; // 10MB limit for display |
| | +$maxVideoSize = 100 * 1024 * 1024; // 100MB limit for video playback |
| | $tooLarge = $fileSize > $maxDisplaySize; |
| | +$videoTooLarge = $isVideo && $fileSize > $maxVideoSize; |
| | ?> |
| | <div class="breadcrumb"> |
| | - <a href="?theme=<?php echo $current_theme; ?>">Repositories</a> <span>/</span> |
| | - <a href="?action=repo&repo=<?php echo urlencode($repo); ?>&theme=<?php echo $current_theme; ?>"><?php echo htmlspecialchars($repo); ?></a> <span>/</span> |
| | - <a href="?action=repo&repo=<?php echo urlencode($repo); ?>&view=tree&theme=<?php echo $current_theme; ?>">Files</a> <span>/</span> |
| | - <strong><?php echo htmlspecialchars($name); ?></strong> |
| | + <a href="?theme=<?php echo $current_theme; ?>">Repositories</a> <span>/</span> |
| | + <a href="?action=repo&repo=<?php echo urlencode($repo); ?>&theme=<?php echo $current_theme; ?>"><?php echo htmlspecialchars($repo); ?></a> <span>/</span> |
| | + <a href="?action=repo&repo=<?php echo urlencode($repo); ?>&view=tree&theme=<?php echo $current_theme; ?>">Files</a> <span>/</span> |
| | + <strong><?php echo htmlspecialchars($name); ?></strong> |
| | </div> |
| | |
| | <div class="card"> |
| | - <div class="card-header"> |
| | - <?php echo htmlspecialchars($name); ?> |
| | - <span style="color: #666; font-size: 0.9em; margin-left: 10px;"> |
| | - (<?php echo number_format($fileSize / 1024, 2); ?> KB) |
| | - </span> |
| | + <div class="card-header"> |
| | + <?php echo htmlspecialchars($name); ?> |
| | + <span style="color: #666; font-size: 0.9em; margin-left: 10px;"> |
| | + (<?php echo number_format($fileSize / 1024, 2); ?> KB) |
| | + </span> |
| | + </div> |
| | + <div class="file-actions"> |
| | + <a href="?action=raw&repo=<?php echo urlencode($repo); ?>&hash=<?php echo urlencode($hash); ?>&name=<?php echo urlencode($name); ?>" class="btn" download> |
| | + 📥 Download |
| | + </a> |
| | + </div> |
| | + |
| | + <?php if ($videoTooLarge): ?> |
| | + <div class="empty-state"> |
| | + <div class="empty-state-icon">⚠️</div> |
| | + <p>Video file is too large to play in browser (<?php echo number_format($fileSize / 1024 / 1024, 2); ?> MB)</p> |
| | + <p>Please download it to view the contents.</p> |
| | </div> |
| | - <div class="file-actions"> |
| | - <a href="?action=raw&repo=<?php echo urlencode($repo); ?>&hash=<?php echo urlencode($hash); ?>&name=<?php echo urlencode($name); ?>" class="btn" download> |
| | - 📥 Download |
| | - </a> |
| | + <?php elseif ($isVideo): ?> |
| | + <div class="video-preview"> |
| | + <video controls style="max-width: 100%; height: auto;"> |
| | + <source src="data:<?php echo getVideoMimeType($name); ?>;base64,<?php echo base64_encode(getBlobBinary($repo, $hash)); ?>" type="<?php echo getVideoMimeType($name); ?>"> |
| | + Your browser does not support the video tag. |
| | + </video> |
| | </div> |
| | - |
| | - <?php if ($tooLarge): ?> |
| | - <div class="empty-state"> |
| | - <div class="empty-state-icon">⚠️</div> |
| | - <p>File is too large to display (<?php echo number_format($fileSize / 1024 / 1024, 2); ?> MB)</p> |
| | - <p>Please download it to view the contents.</p> |
| | - </div> |
| | - <?php elseif ($isImage): ?> |
| | - <div class="image-preview"> |
| | - <img src="data:<?php echo getImageMimeType($name); ?>;base64,<?php echo base64_encode(getBlobBinary($repo, $hash)); ?>" alt="<?php echo htmlspecialchars($name); ?>"> |
| | - </div> |
| | - <?php else: |
| | - $content = getBlob($repo, $hash); |
| | - if (empty($content) || mb_detect_encoding($content, 'UTF-8', true) === false): |
| | - ?> |
| | - <div class="empty-state"> |
| | - <div class="empty-state-icon">📦</div> |
| | - <p>This appears to be a binary file.</p> |
| | - <p>Please download it to view the contents.</p> |
| | - </div> |
| | - <?php else: ?> |
| | - <div class="code-block"> |
| | - <pre><?php echo htmlspecialchars($content); ?></pre> |
| | - </div> |
| | - <?php endif; ?> |
| | + <?php elseif ($tooLarge): ?> |
| | + <div class="empty-state"> |
| | + <div class="empty-state-icon">⚠️</div> |
| | + <p>File is too large to display (<?php echo number_format($fileSize / 1024 / 1024, 2); ?> MB)</p> |
| | + <p>Please download it to view the contents.</p> |
| | + </div> |
| | + <?php elseif ($isImage): ?> |
| | + <div class="image-preview"> |
| | + <img src="data:<?php echo getImageMimeType($name); ?>;base64,<?php echo base64_encode(getBlobBinary($repo, $hash)); ?>" alt="<?php echo htmlspecialchars($name); ?>"> |
| | + </div> |
| | + <?php else: |
| | + $content = getBlob($repo, $hash); |
| | + if (empty($content) || mb_detect_encoding($content, 'UTF-8', true) === false): |
| | + ?> |
| | + <div class="empty-state"> |
| | + <div class="empty-state-icon">📦</div> |
| | + <p>This appears to be a binary file.</p> |
| | + <p>Please download it to view the contents.</p> |
| | + </div> |
| | + <?php else: ?> |
| | + <div class="code-block"> |
| | + <pre><?php echo htmlspecialchars($content); ?></pre> |
| | + </div> |
| | <?php endif; ?> |
| | + <?php endif; ?> |
| | </div> |
| | - |
| | |