mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 22:15:51 +01:00
Add FileUtil#getContentType().
This commit is contained in:
@@ -94,17 +94,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
|
||||
if(raw){
|
||||
// Download
|
||||
val mimeType = FileUtil.getMimeType(path)
|
||||
val bytes = JGitUtil.getContent(git, objectId, false).get
|
||||
|
||||
contentType = if(mimeType == "application/octet-stream" && FileUtil.isText(bytes)){
|
||||
"text/plain"
|
||||
} else {
|
||||
mimeType
|
||||
}
|
||||
//response.setHeader("Content-Disposition", s"inline; filename=${FileUtil.getFileName(path)}")
|
||||
defining(JGitUtil.getContent(git, objectId, false).get){ bytes =>
|
||||
contentType = FileUtil.getContentType(path, bytes)
|
||||
bytes
|
||||
|
||||
}
|
||||
} else {
|
||||
// Viewer
|
||||
val large = FileUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize)
|
||||
|
||||
@@ -164,12 +164,7 @@ trait WikiControllerBase extends ControllerBase with FlashMapSupport {
|
||||
val path = multiParams("splat").head
|
||||
|
||||
getFileContent(repository.owner, repository.name, path).map { bytes =>
|
||||
val mimeType = FileUtil.getMimeType(path)
|
||||
contentType = if(mimeType == "application/octet-stream" && FileUtil.isText(bytes)){
|
||||
"text/plain"
|
||||
} else {
|
||||
mimeType
|
||||
}
|
||||
contentType = FileUtil.getContentType(path, bytes)
|
||||
bytes
|
||||
} getOrElse NotFound
|
||||
})
|
||||
|
||||
@@ -16,6 +16,16 @@ object FileUtil {
|
||||
}
|
||||
}
|
||||
|
||||
def getContentType(name: String, bytes: Array[Byte]): String = {
|
||||
defining(getMimeType(name)){ mimeType =>
|
||||
if(mimeType == "application/octet-stream" && isText(bytes)){
|
||||
"text/plain"
|
||||
} else {
|
||||
mimeType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def isImage(name: String): Boolean = getMimeType(name).startsWith("image/")
|
||||
|
||||
def isLarge(size: Long): Boolean = (size > 1024 * 1000)
|
||||
|
||||
Reference in New Issue
Block a user