Ver Fonte

[annex] annexed file warning

cgars há 8 anos atrás
pai
commit
452505ea73
3 ficheiros alterados com 18 adições e 1 exclusões
  1. 9 0
      pkg/tool/file.go
  2. 3 1
      routes/repo/view.go
  3. 6 0
      templates/repo/view_file.tmpl

+ 9 - 0
pkg/tool/file.go

@@ -19,6 +19,15 @@ func IsTextFile(data []byte) bool {
 	return strings.Contains(http.DetectContentType(data), "text/")
 	return strings.Contains(http.DetectContentType(data), "text/")
 }
 }
 
 
+func IsAnnexedFile(data []byte) bool {
+	if len(data) == 0 {
+		return true
+	}
+	if strings.Contains(http.DetectContentType(data), "text/") {
+		return strings.Contains(string(data), "annex")
+	}
+	return false
+}
 func IsImageFile(data []byte) bool {
 func IsImageFile(data []byte) bool {
 	return strings.Contains(http.DetectContentType(data), "image/")
 	return strings.Contains(http.DetectContentType(data), "image/")
 }
 }

+ 3 - 1
routes/repo/view.go

@@ -141,7 +141,7 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 	n, _ := dataRc.Read(buf)
 	n, _ := dataRc.Read(buf)
 	buf = buf[:n]
 	buf = buf[:n]
 
 
-	isTextFile := tool.IsTextFile(buf)
+	isTextFile := tool.IsTextFile(buf) && !tool.IsAnnexedFile(buf)
 	c.Data["IsTextFile"] = isTextFile
 	c.Data["IsTextFile"] = isTextFile
 
 
 	// Assume file is not editable first.
 	// Assume file is not editable first.
@@ -212,6 +212,8 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 		c.Data["IsVideoFile"] = true
 		c.Data["IsVideoFile"] = true
 	case tool.IsImageFile(buf):
 	case tool.IsImageFile(buf):
 		c.Data["IsImageFile"] = true
 		c.Data["IsImageFile"] = true
+	case tool.IsAnnexedFile(buf):
+		c.Data["IsAnnexedFile"] = true
 	}
 	}
 
 
 	if canEnableEditor {
 	if canEnableEditor {

+ 6 - 0
templates/repo/view_file.tmpl

@@ -69,6 +69,12 @@
 				<div class="view-raw ui center">
 				<div class="view-raw ui center">
 					{{if .IsImageFile}}
 					{{if .IsImageFile}}
 						<img src="{{EscapePound $.RawFileLink}}">
 						<img src="{{EscapePound $.RawFileLink}}">
+					{{else if .IsAnnexedFile}}
+					<div class="ui piled yellow segment">
+						<b>This is an annexed File.</b> This means its full content currently can not be viewed or downloaded
+						with the
+						web interface.
+						Find more information <a href="/G-Node/Info/wiki/Annexed+Files">here</a></div>
 					{{else if .IsVideoFile}}
 					{{else if .IsVideoFile}}
 						<video controls src="{{EscapePound $.RawFileLink}}">
 						<video controls src="{{EscapePound $.RawFileLink}}">
 							<strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>
 							<strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>