wayver's git archive


a simple self-hosted git server
git clone https://git.wayver.dev/bile

Commit: a5fbdd41e56dc312103006ed0c7058b275594a83 (tree)
Parent: 32c6bed79b26b918b19bcaa6d2f5eaf797bbeb92 (tree)
Author: wayverd
Date: 2026 M02 24, Tue 01:17:03 -0500
5 files changed; 77 insertions 3 deletions
use mime_guess to actually guess the file type

i have no idea what my thought process was there

diff --git a/Cargo.lock b/Cargo.lock
index 953297a..047358b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -255,6 +255,7 @@ dependencies = [
  "jiff",
  "mimalloc",
  "mime",
+ "mime_guess",
  "num-conv",
  "serde",
  "syntect",
@@ -1115,6 +1116,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
 
 [[package]]
+name = "mime_guess"
+version = "2.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
+dependencies = [
+ "mime",
+ "unicase",
+]
+
+[[package]]
 name = "miniz_oxide"
 version = "0.8.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1945,6 +1956,12 @@ dependencies = [
 ]
 
 [[package]]
+name = "unicase"
+version = "2.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142"
+
+[[package]]
 name = "unicode-ident"
 version = "1.0.24"
 source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index d915875..16ce33e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,6 +22,7 @@ http = "=1.4.0"
 jiff = "=0.2.20"
 mimalloc = "=0.1.48"
 mime = "=0.3.17"
+mime_guess = "2.0.5"
 num-conv = "=0.2.0"
 serde = { version = "=1.0.228", features = ["derive"] }
 syntect = { version = "=5.3.0", default-features = false, features = ["default-onig"] }
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 0000000..06a75bf
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,53 @@
+# TODO
+
+## code stats
+
+might be interesting to try and add github style code stats
+
+look into these libraries
+
+  - https://crates.io/crates/gengo
+    - this one actually supports reading from a bare git repo
+  - https://crates.io/crates/hyperpolyglot
+    - this one does not support bare git repos
+
+## default file handling
+
+other than specific routes all files are handled as 'raw'
+
+should svg be rendered as source code or as an image
+
+should markdown documents be rendered like README routes or should they be handled like all other code
+
+maybe add a way to switch between rendered and 'raw' views
+
+`?raw` query maybe?
+
+## gitweb style project listing
+
+support something like gitwebs project listing config to allow for a custom repo listing layout
+
+might use the current config for it
+
+maybe something like this?
+
+```toml
+[[repo]]
+name = "bile"
+section = "web services"
+```
+
+could even have it be part of the repo config
+
+```ini
+[bile]
+    section = "web services"
+```
+
+## html sanitization for code view and readme
+
+looking into using https://crates.io/crates/ammonia for this as there might be an injection possiblity with code and readme views
+
+## use gix instead of git2 and/or caching repo data
+
+see https://codeberg.org/kallisti5/gitore for this
diff --git a/src/handlers/repo_file.rs b/src/handlers/repo_file.rs
index 7e32a6f..4d12010 100644
--- a/src/handlers/repo_file.rs
+++ b/src/handlers/repo_file.rs
@@ -181,7 +181,7 @@ fn render(
 
         let output = match mime.type_() {
             mime::TEXT => unreachable!("git detected this file as binary"),
-            mime::IMAGE => format!(
+            mime::IMAGE | mime::BMP | mime::GIF | mime::JPEG | mime::PNG | mime::SVG => format!(
                 "<img src=\"/{}/tree/{}/raw/{}\" />",
                 repo_name,
                 spec,
@@ -194,7 +194,10 @@ fn render(
                 spec,
                 path.display()
             ),
-            _ => "Cannot display binary file.".to_string(),
+            name => {
+                tracing::warn!(mime=?mime, name=?name, "unsupported mime type");
+                "Cannot display binary file.".to_string()
+            }
         };
 
         return Ok(output);
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index ac25dd4..49ebf68 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -3,7 +3,7 @@ pub(crate) mod markdown;
 
 #[must_use]
 pub(crate) fn blob_mime(blob: &git2::Blob<'_>, extension: &str) -> mime::Mime {
-    extension.parse().unwrap_or_else(|_| {
+    mime_guess::MimeGuess::from_ext(extension).first_or_else(|| {
         if blob.is_binary() {
             mime::APPLICATION_OCTET_STREAM
         } else {