mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
(refs #105)Specify suitable Content-Type header for downloaded file.
This commit is contained in:
@@ -93,8 +93,17 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
if(raw){
|
if(raw){
|
||||||
// Download
|
// Download
|
||||||
contentType = "application/octet-stream"
|
val mimeType = FileUtil.getMimeType(path)
|
||||||
JGitUtil.getContent(git, objectId, false).get
|
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)}")
|
||||||
|
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)
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ object FileUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getFileName(path: String): String = defining(path.lastIndexOf('/')){ i =>
|
||||||
|
if(i >= 0) path.substring(i + 1) else path
|
||||||
|
}
|
||||||
|
|
||||||
def getExtension(name: String): String =
|
def getExtension(name: String): String =
|
||||||
name.lastIndexOf('.') match {
|
name.lastIndexOf('.') match {
|
||||||
case i if(i >= 0) => name.substring(i + 1)
|
case i if(i >= 0) => name.substring(i + 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user