From 93cb9054eafb5aa0d6dfdce5555d613eb3ab4563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Br=C3=B6ms?= <9416498+cez81@users.noreply.github.com> Date: Mon, 29 Oct 2018 21:58:23 +0100 Subject: [PATCH 1/2] Serve audio files using HTML5 audio tag --- modules/base/tool.go | 5 +++++ options/locale/locale_en-US.ini | 1 + routers/repo/view.go | 2 ++ templates/repo/view_file.tmpl | 5 +++++ 4 files changed, 13 insertions(+) diff --git a/modules/base/tool.go b/modules/base/tool.go index 5b79a844ab35..b069e5faee25 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 a0babf7a1986..6f323415754b 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 210eb9fe5ffb..657fe315a2a7 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 6c37aab58ad4..0b030cf79154 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -55,6 +55,11 @@ + + {{else if .IsAudioFile}} + {{else if .IsPDFFile}} {{else}} From eacd79e976e6bf6b6808733bf8fd7adde0e40139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Br=C3=B6ms?= <9416498+cez81@users.noreply.github.com> Date: Mon, 29 Oct 2018 22:05:32 +0100 Subject: [PATCH 2/2] Correct copy paste error --- templates/repo/view_file.tmpl | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 0b030cf79154..07d1075b1306 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -55,7 +55,6 @@ - {{else if .IsAudioFile}}