change mimetype for xmls

This commit is contained in:
Sinuhe Tellez 2021-06-10 02:40:08 -04:00
parent 622703cf5c
commit cb46eb6817

View File

@ -60,12 +60,12 @@ func (s OPDS) Handler(w http.ResponseWriter, req *http.Request) error {
var content []byte var content []byte
var err error var err error
if getPathType(fPath) == pathTypeDirOfFiles { if getPathType(fPath) == pathTypeDirOfFiles {
// if path is a directory of files it is an aquisition feed
acFeed := &opds.AcquisitionFeed{Feed: &navFeed, Dc: "http://purl.org/dc/terms/", Opds: "http://opds-spec.org/2010/catalog"} acFeed := &opds.AcquisitionFeed{Feed: &navFeed, Dc: "http://purl.org/dc/terms/", Opds: "http://opds-spec.org/2010/catalog"}
content, err = xml.MarshalIndent(acFeed, " ", " ") content, err = xml.MarshalIndent(acFeed, " ", " ")
w.Header().Add("Content-Type", "application/atom+xml;profile=opds-catalog;kind=acquisition")
} else { } else {
// if path is a directory of directories it is an aquisition feed
content, err = xml.MarshalIndent(navFeed, " ", " ") content, err = xml.MarshalIndent(navFeed, " ", " ")
w.Header().Add("Content-Type", "application/atom+xml;profile=opds-catalog;kind=navigation")
} }
if err != nil { if err != nil {
log.Printf("error while serving '%s': %s", fPath, err) log.Printf("error while serving '%s': %s", fPath, err)
@ -123,10 +123,16 @@ func getRel(name string, pathType int) string {
} }
func getType(name string, pathType int) string { func getType(name string, pathType int) string {
if pathType == pathTypeFile { switch pathType {
case pathTypeFile:
return mime.TypeByExtension(filepath.Ext(name)) return mime.TypeByExtension(filepath.Ext(name))
case pathTypeDirOfFiles:
return "application/atom+xml;profile=opds-catalog;kind=acquisition"
case pathTypeDirOfDirs:
return "application/atom+xml;profile=opds-catalog;kind=navigation"
default:
return mime.TypeByExtension("xml")
} }
return "application/atom+xml;profile=opds-catalog;kind=acquisition"
} }
func getPathType(dirpath string) int { func getPathType(dirpath string) int {