From db30d6d7911b2fe458b5ccb5c6f6ad73381c9a70 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20Br=C3=B6ms?=
<9416498+cez81@users.noreply.github.com>
Date: Tue, 30 Oct 2018 03:17:26 +0100
Subject: [PATCH] Serve audio files using HTML5 audio tag (#5221)
* Serve audio files using HTML5 audio tag
* Correct copy paste error
---
modules/base/tool.go | 5 +++++
options/locale/locale_en-US.ini | 1 +
routers/repo/view.go | 2 ++
templates/repo/view_file.tmpl | 4 ++++
4 files changed, 12 insertions(+)
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 5b79a844ab..b069e5faee 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -576,6 +576,11 @@ func IsVideoFile(data []byte) bool {
return strings.Index(http.DetectContentType(data), "video/") != -1
}
+// IsAudioFile detects if data is an video format
+func IsAudioFile(data []byte) bool {
+ return strings.Index(http.DetectContentType(data), "audio/") != -1
+}
+
// EntryIcon returns the octicon class for displaying files/directories
func EntryIcon(entry *git.TreeEntry) string {
switch {
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index a0babf7a19..6f32341575 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -592,6 +592,7 @@ file_view_raw = View Raw
file_permalink = Permalink
file_too_large = The file is too large to be shown.
video_not_supported_in_browser = Your browser does not support the HTML5 'video' tag.
+audio_not_supported_in_browser = Your browser does not support the HTML5 'audio' tag.
stored_lfs = Stored with Git LFS
commit_graph = Commit Graph
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 210eb9fe5f..657fe315a2 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -264,6 +264,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
ctx.Data["IsPDFFile"] = true
case base.IsVideoFile(buf):
ctx.Data["IsVideoFile"] = true
+ case base.IsAudioFile(buf):
+ ctx.Data["IsAudioFile"] = true
case base.IsImageFile(buf):
ctx.Data["IsImageFile"] = true
}
diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl
index 6c37aab58a..07d1075b13 100644
--- a/templates/repo/view_file.tmpl
+++ b/templates/repo/view_file.tmpl
@@ -55,6 +55,10 @@
+ {{else if .IsAudioFile}}
+
{{else if .IsPDFFile}}
{{else}}