~dupunkto/gitz

Awesome PHP-based Git frontend.

Add route for serving raw blob contents

Commited on by Robin.

diff --git a/index.php b/index.php
index 450420b..a73fb1f 100644
--- a/index.php
+++ b/index.php
@@ -104,6 +104,23 @@ switch(true) {
 
           $request_path = trim($params[2], "/");
           break;
+
+        case route("@/raw/{$alnum}(.*)$@"):
+          if(\core\isCommitHash($params[1])) {
+            $hash = $params[1];
+          } else {
+            $branch = $params[1];
+            $hash = \core\getLatestCommits($repo, $branch, 1)[0]['hash'];
+          }
+
+          $request_path = trim($params[2], "/");
+
+          $blob = \core\getBlob($repo, $request_path, $hash);
+          $mime = \core\detectMimeType($repo, $request_path, $hash);
+
+          header("Content-Type: {$mime}");
+          echo $blob;
+          exit;
       }
 
       if(isset($page)) break;