Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix routing and blob display bugs #613

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions Bonobo.Git.Server/App_Start/RouteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
string guid_regex = @"[\da-z]{8}-[\da-z]{4}-[\da-z]{4}-[\da-z]{4}-[\da-z]{12}";

routes.MapRoute("SecureInfoRefs",
"{repositoryName}.git/info/refs",
new { controller = "Git", action = "SecureGetInfoRefs" },
Expand Down Expand Up @@ -37,65 +39,65 @@ public static void RegisterRoutes(RouteCollection routes)
new { action = "Create" });

routes.MapRoute("RepositoryTree",
"Repository/{id}/{encodedName}/Tree/{*encodedPath}",
"Repository/{id}/Tree/{encodedName}/{*encodedPath}",
new { controller = "Repository", action = "Tree" },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("RepositoryBlob",
"Repository/{id}/{encodedName}/Blob/{*encodedPath}",
new { controller = "Repository", action = "Blob" },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("RepositoryRaw",
"Repository/{id}/{encodedName}/Raw/{*encodedPath}",
new { controller = "Repository", action = "Raw" },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("RepositoryBlame",
"Repository/{id}/{encodedName}/Blame/{*encodedPath}",
new { controller = "Repository", action = "Blame" },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("RepositoryDownload",
"Repository/{id}/{encodedName}/Download/{*encodedPath}",
new { controller = "Repository", action = "Download" },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("RepositoryCommits",
"Repository/{id}/{encodedName}/Commits",
new { controller = "Repository", action = "Commits" },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("RepositoryCommit",
"Repository/{id}/{encodedName}/Commit/{commit}/",
"Repository/{id}/Commit/{commit}/",
new { controller = "Repository", action = "Commit" },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("RepositoryHistory",
"Repository/{id}/{encodedName}/History/{*encodedPath}",
new { controller = "Repository", action = "History" },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("Repository",
"Repository/{id}/{action}/{reponame}",
new { controller = "Repository", action = "Detail", reponame = UrlParameter.Optional },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("Account",
"Account/{id}/{action}/{username}",
new { controller = "Account", action = "Detail", username = UrlParameter.Optional },
new { id = @"\d+" });
new { id = guid_regex });

routes.MapRoute("Team",
"Team/{id}/{action}/{teamname}",
new { controller = "Team", action = "Detail", teamname = UrlParameter.Optional },
new { id = @"\d+" });
new { id = guid_regex });


routes.MapRoute("Validation", "Validation/{action}", new { controller = "Validation", action = String.Empty });

routes.MapRoute("RepoCommits",
"Repository/Commits/{id}",
"Repository/{id}/Commits",
new { controller = "Repository", action = "Commits", id = string.Empty, page = 1 });

routes.MapRoute("Default",
Expand Down
12 changes: 7 additions & 5 deletions Bonobo.Git.Server/Controllers/RepositoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ public ActionResult Raw(Guid id, string encodedName, string encodedPath, bool di
{
return File(model.Data, "application/octet-stream", model.Name);
}
if (model.IsText)
if (model.IsImage)
{
return Content(model.Text, "text/plain", model.Encoding);
// do not include the last parameter "fileDownloadName" so the "Content-Disposition: attachment" header will not be added.
return File(model.Data, MimeTypeMap.GetMimeType(Path.GetExtension(model.Name.ToLower())));
}
if (model.IsImage)
// text is the least prefered choice, and seems the IsText will always be true if the file is not zero length...
if (model.IsText)
{
return File(model.Data, MimeTypeMap.GetMimeType(Path.GetExtension(model.Name.ToLower())), model.Name);
return Content(model.Text, "text/plain", model.Encoding);
}
}

Expand Down Expand Up @@ -448,7 +450,7 @@ public ActionResult Tags(Guid id, string encodedName, int page = 1)
}

[WebAuthorizeRepository]
public ActionResult Commits(Guid id, string encodedName, int page)
public ActionResult Commits(Guid id, string encodedName, int page = 1)
{
page = page >= 1 ? page : 1;

Expand Down
8 changes: 4 additions & 4 deletions Bonobo.Git.Server/Views/Repository/Blame.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
@{
<div class="controls">
<span>@Model.LineCount lines | @FileDisplayHandler.GetFileSizeString(Model.FileSize)</span>
<a href="@Url.Action("Blob", new { id=ViewBag.ID, encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true)})"><i class="fa fa-code"></i> @Resources.Repository_Tree_Blob</a>
<a href="@Url.Action("History", new { id=ViewBag.ID, encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true)})"><i class="fa fa-history"></i> @Resources.Repository_Tree_History</a>
<a href="@Url.Action("Raw", new { id=ViewBag.ID, encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true), display = true })"><i class="fa fa-file-text"></i> @Resources.Repository_Tree_RawDisplay</a>
<a href="@Url.Action("Raw", new { id=ViewBag.ID, encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })"><i class="fa fa-download"></i> @Resources.Repository_Tree_Download</a>
<a href="@Url.RouteUrl("RepositoryBlob", new { id = ViewBag.ID, encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })"><i class="fa fa-code"></i> @Resources.Repository_Tree_Blob</a>
<a href="@Url.RouteUrl("RepositoryHistory", new { id = ViewBag.ID, encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })"><i class="fa fa-history"></i> @Resources.Repository_Tree_History</a>
<a href="@Url.RouteUrl("RepositoryRaw", new { id = ViewBag.ID, encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true), display = true })"><i class="fa fa-file-text"></i> @Resources.Repository_Tree_RawDisplay</a>
<a href="@Url.RouteUrl("RepositoryRaw", new { id = ViewBag.ID, encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })"><i class="fa fa-download"></i> @Resources.Repository_Tree_Download</a>
</div>
<div class="blame">
<table id="blame_table">
Expand Down
10 changes: 5 additions & 5 deletions Bonobo.Git.Server/Views/Repository/Blob.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
@{
<div class="controls">
<span>@(Model.IsText ? Model.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).Length + " lines |" : "") @FileDisplayHandler.GetFileSizeString(Model.Data.LongLength)</span>
<a href="@Url.Action("Blame", new { id=ViewBag.ID, encodedName = PathEncoder.Encode(Model.TreeName), encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true)})"><i class="fa fa-comments"></i> @Resources.Repository_Tree_Blame</a>
<a href="@Url.Action("History", new { id=ViewBag.ID, encodedName = PathEncoder.Encode(Model.TreeName), encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true)})"><i class="fa fa-history"></i> @Resources.Repository_Tree_History</a>
<a href="@Url.Action("Raw", new { id=ViewBag.ID, encodedName = PathEncoder.Encode(Model.TreeName), encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true), display = true })"><i class="fa fa-file-text"></i> @Resources.Repository_Tree_RawDisplay</a>
<a href="@Url.Action("Raw", new { id=ViewBag.ID, encodedName = PathEncoder.Encode(Model.TreeName), encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })"><i class="fa fa-download"></i> @Resources.Repository_Tree_Download</a>
<a href="@Url.RouteUrl("RepositoryBlame", new { id = ViewBag.ID, encodedName = PathEncoder.Encode(Model.TreeName), encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })"><i class="fa fa-comments"></i> @Resources.Repository_Tree_Blame</a>
<a href="@Url.RouteUrl("RepositoryHistory", new { id = ViewBag.ID, encodedName = PathEncoder.Encode(Model.TreeName), encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })"><i class="fa fa-history"></i> @Resources.Repository_Tree_History</a>
<a href="@Url.RouteUrl("RepositoryRaw", new { id = ViewBag.ID, encodedName = PathEncoder.Encode(Model.TreeName), encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true), display = true })"><i class="fa fa-file-text"></i> @Resources.Repository_Tree_RawDisplay</a>
<a href="@Url.RouteUrl("RepositoryRaw", new { id = ViewBag.ID, encodedName = PathEncoder.Encode(Model.TreeName), encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })"><i class="fa fa-download"></i> @Resources.Repository_Tree_Download</a>
</div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this isn't really fixing a bug - it's just renaming a bunch of actions to include the controller name within the action name - what was the motivation here?

}
@if (Model.IsImage)
{
<img class="fileImage" alt="@Model.Name" src="@Url.Action("Raw", new { encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })" />
<img class="fileImage" alt="@Model.Name" src="@Url.RouteUrl("RepositoryRaw", new { id = ViewBag.ID, encodedName = PathEncoder.Encode(Model.TreeName), encodedPath = PathEncoder.Encode(Model.Path, allowSlash: true) })" />
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thanks - I'll commit this outside this PR while we get the rest sorted.

else if (Model.IsText && Model.IsMarkdown)
{
Expand Down