mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Serve audio files using HTML5 audio tag (#5221)
* Serve audio files using HTML5 audio tag * Correct copy paste error
This commit is contained in:
		| @@ -576,6 +576,11 @@ func IsVideoFile(data []byte) bool { | |||||||
| 	return strings.Index(http.DetectContentType(data), "video/") != -1 | 	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 | // EntryIcon returns the octicon class for displaying files/directories | ||||||
| func EntryIcon(entry *git.TreeEntry) string { | func EntryIcon(entry *git.TreeEntry) string { | ||||||
| 	switch { | 	switch { | ||||||
|   | |||||||
| @@ -592,6 +592,7 @@ file_view_raw = View Raw | |||||||
| file_permalink = Permalink | file_permalink = Permalink | ||||||
| file_too_large = The file is too large to be shown. | 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. | 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 | stored_lfs = Stored with Git LFS | ||||||
| commit_graph = Commit Graph | commit_graph = Commit Graph | ||||||
|  |  | ||||||
|   | |||||||
| @@ -264,6 +264,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st | |||||||
| 		ctx.Data["IsPDFFile"] = true | 		ctx.Data["IsPDFFile"] = true | ||||||
| 	case base.IsVideoFile(buf): | 	case base.IsVideoFile(buf): | ||||||
| 		ctx.Data["IsVideoFile"] = true | 		ctx.Data["IsVideoFile"] = true | ||||||
|  | 	case base.IsAudioFile(buf): | ||||||
|  | 		ctx.Data["IsAudioFile"] = true | ||||||
| 	case base.IsImageFile(buf): | 	case base.IsImageFile(buf): | ||||||
| 		ctx.Data["IsImageFile"] = true | 		ctx.Data["IsImageFile"] = true | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -55,6 +55,10 @@ | |||||||
| 						<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> | ||||||
| 						</video> | 						</video> | ||||||
|  | 					{{else if .IsAudioFile}} | ||||||
|  | 						<audio controls src="{{EscapePound $.RawFileLink}}"> | ||||||
|  | 							<strong>{{.i18n.Tr "repo.audio_not_supported_in_browser"}}</strong> | ||||||
|  | 						</audio> | ||||||
| 					{{else if .IsPDFFile}} | 					{{else if .IsPDFFile}} | ||||||
| 						<iframe width="100%" height="600px" src="{{AppSubUrl}}/vendor/plugins/pdfjs/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe> | 						<iframe width="100%" height="600px" src="{{AppSubUrl}}/vendor/plugins/pdfjs/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe> | ||||||
| 					{{else}} | 					{{else}} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user