Merge pull request #142 from strlght/podcastitem-content-type

Looks good
pull/175/head
Akhil Gupta 3 years ago committed by GitHub
commit 2382f53b5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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