mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-10-29 01:26:23 +01:00
Add document file formats for upload
The following extension is added. - .docx - .pptx - .txt - .xlsx
This commit is contained in:
@@ -56,6 +56,7 @@ object MyBuild extends Build {
|
||||
"org.apache.commons" % "commons-email" % "1.3.3",
|
||||
"org.apache.httpcomponents" % "httpclient" % "4.3.6",
|
||||
"org.apache.sshd" % "apache-sshd" % "0.11.0",
|
||||
"org.apache.tika" % "tika-core" % "1.10",
|
||||
"com.typesafe.slick" %% "slick" % "2.1.0",
|
||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||
"com.h2database" % "h2" % "1.4.180",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package gitbucket.core.util
|
||||
|
||||
import org.apache.commons.io.FileUtils
|
||||
import java.net.URLConnection
|
||||
import org.apache.tika.Tika
|
||||
import java.io.File
|
||||
import ControlUtil._
|
||||
import scala.util.Random
|
||||
@@ -9,8 +9,8 @@ import scala.util.Random
|
||||
object FileUtil {
|
||||
|
||||
def getMimeType(name: String): String =
|
||||
defining(URLConnection.getFileNameMap()){ fileNameMap =>
|
||||
fileNameMap.getContentTypeFor(name) match {
|
||||
defining(new Tika()){ tika =>
|
||||
tika.detect(name) match {
|
||||
case null => "application/octet-stream"
|
||||
case mimeType => mimeType
|
||||
}
|
||||
@@ -28,11 +28,7 @@ object FileUtil {
|
||||
|
||||
def isImage(name: String): Boolean = getMimeType(name).startsWith("image/")
|
||||
|
||||
def isUploadableType(name: String): Boolean = getMimeType(name) match {
|
||||
case t if t.startsWith("image/") => true
|
||||
case "application/pdf" => true
|
||||
case _ => false
|
||||
}
|
||||
def isUploadableType(name: String): Boolean = mimeTypeWhiteList contains getMimeType(name)
|
||||
|
||||
def isLarge(size: Long): Boolean = (size > 1024 * 1000)
|
||||
|
||||
@@ -56,4 +52,14 @@ object FileUtil {
|
||||
FileUtils.deleteDirectory(dir)
|
||||
}
|
||||
}
|
||||
|
||||
val mimeTypeWhiteList: Array[String] = Array(
|
||||
"application/pdf",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
"text/plain")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
@(owner: String, repository: String)(textarea: Html)(implicit context: gitbucket.core.controller.Context)
|
||||
@import context._
|
||||
@import gitbucket.core.util.FileUtil
|
||||
<div class="muted attachable">
|
||||
@textarea
|
||||
<div class="clickable">Attach images or PDF files by dragging & dropping, or selecting them.</div>
|
||||
@@ -11,7 +12,7 @@ $(function(){
|
||||
$([$('#@textareaId').closest('div')[0], $('#@textareaId').next('div')[0]]).dropzone({
|
||||
url: '@path/upload/file/@owner/@repository',
|
||||
maxFilesize: 10,
|
||||
acceptedFiles: 'image/*,application/pdf',
|
||||
acceptedFiles: @Html(FileUtil.mimeTypeWhiteList.mkString("'", ",", "'")),
|
||||
dictInvalidFileType: 'Unfortunately, we don\'t support that file type. Try again with a PNG, GIF, or JPG.',
|
||||
previewTemplate: "<div class=\"dz-preview\">\n <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress>Uploading your images or PDF files...</span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>",
|
||||
success: function(file, id) {
|
||||
|
||||
Reference in New Issue
Block a user