Send correct Content-Type for podcastitem

Need to pass correct Content-Type because Safari won't play any sound passed as application/octet-stream
pull/142/head
Grigorii Dzhanelidze 3 years ago
parent 06feb39820
commit f7ed85d2ab

@ -289,7 +289,7 @@ func GetPodcastItemFileById(c *gin.Context) {
c.Header("Content-Description", "File Transfer")
c.Header("Content-Transfer-Encoding", "binary")
c.Header("Content-Disposition", "attachment; filename="+path.Base(podcast.DownloadPath))
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Type", GetFileContentType(podcast.DownloadPath))
c.File(podcast.DownloadPath)
} else {
c.Redirect(302, podcast.FileURL)
@ -300,6 +300,19 @@ func GetPodcastItemFileById(c *gin.Context) {
}
}
func GetFileContentType(filePath string) string {
file, err := os.Open(filePath)
if err != nil {
return "application/octet-stream"
}
defer file.Close()
buffer := make([]byte, 512)
if _, err := file.Read(buffer); err != nil {
return "application/octet-stream"
}
return http.DetectContentType(buffer)
}
func MarkPodcastItemAsUnplayed(c *gin.Context) {
var searchByIdQuery SearchByIdQuery

Loading…
Cancel
Save