Allow ?raw=true to be passed to blob view
Fixes #25
Diff
src/git.rs | 7 +++++++
src/methods/repo/tree.rs | 19 ++++++++++++++++++-
2 files changed, 23 insertions(+), 3 deletions(-)
@@ -80,6 +80,7 @@
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 @@
.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 {
@@ -1,10 +1,10 @@
use std::{
fmt::{Display, Formatter},
sync::Arc,
};
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 @@
id: Option<String>,
#[serde(rename = "h")]
branch: Option<String>,
#[serde(default)]
raw: bool,
}
impl Display for UriQuery {
@@ -68,10 +70,23 @@
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 }),
},
)