Skip to content

Commit 9bf5a5d

Browse files
committed
Restore code
1 parent f2c5d78 commit 9bf5a5d

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

pkg/opds/opds.go

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -893,38 +893,16 @@ func (h *Handler) unloadBook(w http.ResponseWriter, r *http.Request) {
893893
h.LOG.E.Println(err)
894894
}
895895
case "zip":
896-
// w.Header().Add("Content-Type", fmt.Sprintf("%s; name=%s", mime.TypeByExtension("." + book.Format + zipExt), book.File+zipExt))
897-
w.Header().Add("Content-Type", mime.TypeByExtension("."+book.Format+ext))
898-
w.Header().Add("Content-Transfer-Encoding", "binary")
899-
w.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", book.File+ext))
900-
w.WriteHeader(http.StatusOK)
901-
902-
switch convert {
903-
case "epub":
904-
rsc, err := NewReadSeekCloser(rc)
905-
if err != nil {
906-
h.LOG.E.Println(err)
907-
return
908-
}
909-
wc := NewWriteCloser(w)
910-
err = h.ConvertFb2Epub(bookId, rsc, wc)
911-
if err != nil {
912-
h.LOG.E.Println(err)
913-
}
914-
case "zip":
915-
zipWriter := zip.NewWriter(w)
916-
defer zipWriter.Close()
917-
fileWriter, _ := zipWriter.CreateHeader(
918-
&zip.FileHeader{
919-
Name: book.File,
920-
Method: zip.Deflate,
921-
},
922-
)
923-
io.Copy(fileWriter, rc)
924-
zipWriter.Flush()
925-
default:
926-
io.Copy(w, rc)
927-
}
896+
zipWriter := zip.NewWriter(w)
897+
defer zipWriter.Close()
898+
fileWriter, _ := zipWriter.CreateHeader(
899+
&zip.FileHeader{
900+
Name: book.File,
901+
Method: zip.Deflate,
902+
},
903+
)
904+
io.Copy(fileWriter, rc)
905+
zipWriter.Flush()
928906
default:
929907
io.Copy(w, rc)
930908
}

0 commit comments

Comments
 (0)