From 91b80bc8bb535b58a6c6cc35b727b0afa26afc07 Mon Sep 17 00:00:00 2001 From: marmei <43099631+mar-mei@users.noreply.github.com> Date: Mon, 16 Dec 2019 20:23:05 +0100 Subject: [PATCH] Add xteve.xml GZIP --- src/compression.go | 17 +++++++++++++++++ src/config.go | 2 ++ src/struct-system.go | 4 ++++ src/webserver.go | 3 ++- src/xepg.go | 5 +++-- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/compression.go b/src/compression.go index 0429998..ba76626 100644 --- a/src/compression.go +++ b/src/compression.go @@ -146,3 +146,20 @@ func extractGZIP(gzipBody []byte, fileSource string) (body []byte, err error) { body = resB.Bytes() return } + +func compressGZIP(data *[]byte, file string) (err error) { + + if len(file) != 0 { + + f, err := os.Create(file) + if err != nil { + return err + } + + w := gzip.NewWriter(f) + w.Write(*data) + w.Close() + } + + return +} diff --git a/src/config.go b/src/config.go index 1cc43f6..8210084 100644 --- a/src/config.go +++ b/src/config.go @@ -98,6 +98,8 @@ func Init() (err error) { System.File.XML = getPlatformFile(fmt.Sprintf("%s%s.xml", System.Folder.Data, System.AppName)) System.File.M3U = getPlatformFile(fmt.Sprintf("%s%s.m3u", System.Folder.Data, System.AppName)) + System.Compressed.GZxml = getPlatformFile(fmt.Sprintf("%s%s.xml.gz", System.Folder.Data, System.AppName)) + err = activatedSystemAuthentication() if err != nil { return diff --git a/src/struct-system.go b/src/struct-system.go index 67aad6d..e7fcc20 100644 --- a/src/struct-system.go +++ b/src/struct-system.go @@ -42,6 +42,10 @@ type SystemStruct struct { XML string } + Compressed struct { + GZxml string + } + Flag struct { Branch string Debug int diff --git a/src/webserver.go b/src/webserver.go index 4f72266..519de2d 100644 --- a/src/webserver.go +++ b/src/webserver.go @@ -216,7 +216,6 @@ func xTeVe(w http.ResponseWriter, r *http.Request) { // XMLTV Datei if strings.Contains(path, "xmltv/") { - w.Header().Set("Content-Type", "application/xml") requestType = "xml" file = System.Folder.Data + getFilenameFromPath(path) @@ -227,6 +226,8 @@ func xTeVe(w http.ResponseWriter, r *http.Request) { return } + w.Header().Set("Content-Type", http.DetectContentType([]byte(content))) + } // M3U Datei diff --git a/src/xepg.go b/src/xepg.go index 88fb59a..932f373 100644 --- a/src/xepg.go +++ b/src/xepg.go @@ -641,9 +641,10 @@ func createXMLTVFile() (err error) { var xmlOutput = []byte(xml.Header + string(content)) writeByteToFile(System.File.XML, xmlOutput) - xepgXML = XMLTV{} + showInfo("XEPG:" + fmt.Sprintf("Compress XMLTV file (%s)", System.Compressed.GZxml)) + err = compressGZIP(&xmlOutput, System.Compressed.GZxml) - //saveMapToJSONFile(System.File.Images, Data.Cache.ImageCache) + xepgXML = XMLTV{} return }