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