diff --git a/src/git.rs b/src/git.rs
@@ -80,6 +80,7 @@ impl OpenRepository {
path: Option<PathBuf>,
tree_id: Option<&str>,
branch: Option<String>,
+ formatted: bool,
) -> Result<PathDestination> {
let tree_id = tree_id
.map(Oid::from_str)
@@ -119,7 +120,11 @@ impl OpenRepository {
.extension()
.or_else(|| path.file_name())
.map_or_else(|| Cow::Borrowed(""), OsStr::to_string_lossy);
- let content = format_file(blob.content(), &extension, &self.git.syntax_set)?;
+ let content = if formatted {
+ format_file(blob.content(), &extension, &self.git.syntax_set)?
+ } else {
+ String::from_utf8_lossy(blob.content()).to_string()
+ };
return Ok(PathDestination::File(FileWithContent {
metadata: File {
diff --git a/src/methods/repo/tree.rs b/src/methods/repo/tree.rs
@@ -4,7 +4,7 @@ use std::{
};
use askama::Template;
-use axum::{extract::Query, response::Response, Extension};
+use axum::{extract::Query, http, response::IntoResponse, response::Response, Extension};
use serde::Deserialize;
use crate::{
@@ -22,6 +22,8 @@ pub struct UriQuery {
id: Option<String>,
#[serde(rename = "h")]
branch: Option<String>,
+ #[serde(default)]
+ raw: bool,
}
impl Display for UriQuery {
@@ -68,10 +70,23 @@ pub async fn handle(
Ok(
match open_repo
- .path(child_path, query.id.as_deref(), query.branch.clone())
+ .path(
+ child_path,
+ query.id.as_deref(),
+ query.branch.clone(),
+ !query.raw,
+ )
.await?
{
PathDestination::Tree(items) => into_response(&TreeView { repo, items, query }),
+ PathDestination::File(file) if query.raw => {
+ let headers = [(
+ http::header::CONTENT_TYPE,
+ http::HeaderValue::from_static("text/plain"),
+ )];
+
+ (headers, file.content).into_response()
+ }
PathDestination::File(file) => into_response(&FileView { repo, file }),
},
)