mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-01 02:56:08 +01:00
Don't display binary file at the blob view.
This commit is contained in:
@@ -126,10 +126,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
}
|
||||
|
||||
val treeWalk = new TreeWalk(git.getRepository)
|
||||
val objectId = try {
|
||||
treeWalk.addTree(revCommit.getTree)
|
||||
treeWalk.setRecursive(true)
|
||||
val objectId = getPathObjectId(path, treeWalk)
|
||||
getPathObjectId(path, treeWalk)
|
||||
} finally {
|
||||
treeWalk.release
|
||||
}
|
||||
|
||||
if(raw){
|
||||
// Download
|
||||
@@ -138,9 +141,21 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
} else {
|
||||
// Viewer
|
||||
val large = FileTypeUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize)
|
||||
val viewer = if(FileTypeUtil.isImage(path)) "image" else if(large) "large" else "text"
|
||||
val content = JGitUtil.ContentInfo(viewer,
|
||||
if(viewer == "text") JGitUtil.getContent(git, objectId, false).map(new String(_, "UTF-8")) else None)
|
||||
val viewer = if(FileTypeUtil.isImage(path)) "image" else if(large) "large" else "other"
|
||||
val bytes = if(viewer == "other") JGitUtil.getContent(git, objectId, false) else None
|
||||
|
||||
val content = if(viewer == "other"){
|
||||
if(bytes.isDefined && FileTypeUtil.isText(bytes.get)){
|
||||
// text
|
||||
JGitUtil.ContentInfo("text", bytes.map(new String(_, "UTF-8")))
|
||||
} else {
|
||||
// binary
|
||||
JGitUtil.ContentInfo("binary", None)
|
||||
}
|
||||
} else {
|
||||
// image or large
|
||||
JGitUtil.ContentInfo(viewer, None)
|
||||
}
|
||||
|
||||
repo.html.blob(id, repositoryInfo, path.split("/").toList, content, new JGitUtil.CommitInfo(revCommit))
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
@if(content.viewType == "image"){
|
||||
<img src="?raw=true"/>
|
||||
}
|
||||
@if(content.viewType == "large"){
|
||||
@if(content.viewType == "large" || content.viewType == "binary"){
|
||||
<div style="text-align: center">
|
||||
<a href="?raw=true">View Raw</a><br>
|
||||
(Sorry about that, but we can't show files that are this big right now)
|
||||
|
||||
Reference in New Issue
Block a user