diff --git a/src/main/scala/gitbucket/core/controller/ApiController.scala b/src/main/scala/gitbucket/core/controller/ApiController.scala index 1a2114e..692a1f9 100644 --- a/src/main/scala/gitbucket/core/controller/ApiController.scala +++ b/src/main/scala/gitbucket/core/controller/ApiController.scala @@ -10,6 +10,7 @@ import gitbucket.core.util.JGitUtil._ import gitbucket.core.util._ import gitbucket.core.util.Implicits._ +import gitbucket.core.view.helpers.{renderMarkup, isRenderable} import org.eclipse.jgit.api.Git import org.scalatra.{NoContent, UnprocessableEntity, Created} import scala.collection.JavaConverters._ @@ -127,8 +128,31 @@ using(Git.open(getRepositoryDir(params("owner"), params("repo")))){ git => val fileList = getFileList(git, refStr, path) if (fileList.isEmpty) { // file or NotFound - getFileInfo(git, refStr, path).map(f => { - JsonFormat(ApiContents(f, getContentFromId(git, f.id, true))) + getFileInfo(git, refStr, path).flatMap(f => { + val largeFile = params.get("large_file").exists(s => s.equals("true")) + val content = getContentFromId(git, f.id, largeFile) + request.getHeader("Accept") match { + case "application/vnd.github.v3.raw" => + content + case "application/vnd.github.v3.html" if isRenderable(f.name) => + content.map(c => + List( + "
", "
", + renderMarkup(path.split("/").toList, new String(c), refStr, repository, false, false, true).body, + "
", "
" + ).mkString + ) + case "application/vnd.github.v3.html" => + content.map(c => + List( + "
", "
", "
",
+                  play.twirl.api.HtmlFormat.escape(new String(c)).body,
+                  "
", "
", "
" + ).mkString + ) + case _ => + Some(JsonFormat(ApiContents(f, content))) + } }).getOrElse(NotFound()) } else { // directory JsonFormat(fileList.map{f => ApiContents(f, None)})