Fixed potential issue where a malformed CBZ would cause a panic. Now it just ignores malformed CBZ files.

This commit is contained in:
2024-12-31 03:40:07 -07:00
parent 974fa024a1
commit 8d397ac1a9
2 changed files with 25 additions and 11 deletions
+19 -11
View File
@@ -55,7 +55,7 @@ func Index(w http.ResponseWriter, r *http.Request) {
feed.Entry = append(feed.Entry)
_ = filepath.WalkDir(ctx.String("manga"), func(path string, d fs.DirEntry, err error) error {
err := filepath.WalkDir(ctx.String("manga"), func(path string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() || filepath.Ext(d.Name()) != ".cbz" {
return err
}
@@ -68,17 +68,21 @@ func Index(w http.ResponseWriter, r *http.Request) {
if found {
ComicInfo = ci.(comicinfo.ComicInfo)
} else {
zf, _ := zip.OpenReader(path)
for i := range zf.File {
if strings.ToLower(zf.File[i].Name) == "comicinfo.xml" {
cif, err := zf.File[i].Open()
if err != nil {
return err
zf, err := zip.OpenReader(path)
if err != nil {
return nil
} else {
for i := range zf.File {
if strings.ToLower(zf.File[i].Name) == "comicinfo.xml" {
cif, err := zf.File[i].Open()
if err != nil {
return err
}
cib, _ := io.ReadAll(cif)
_ = cif.Close()
_ = xml.Unmarshal(cib, &ComicInfo)
c.Set(path, ComicInfo, cache.NoExpiration)
}
cib, _ := io.ReadAll(cif)
_ = cif.Close()
_ = xml.Unmarshal(cib, &ComicInfo)
c.Set(path, ComicInfo, cache.NoExpiration)
}
}
}
@@ -125,6 +129,10 @@ func Index(w http.ResponseWriter, r *http.Request) {
return nil
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
_ = defaults.Set(&feed)
data, _ := xml.MarshalIndent(feed, "", " ")
http.ServeContent(w, r, "feed.xml", time.Now(), bytes.NewReader(data))