mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
specify type for write file
This commit is contained in:
parent
8a1eeb400d
commit
d0d9af7f9b
@ -77,12 +77,12 @@ func (e *ePub) render(templateString string, data any) string {
|
||||
func (e *ePub) writeImage(wz *epubzip.EpubZip, img *epubimage.Image) error {
|
||||
err := wz.WriteFile(
|
||||
fmt.Sprintf("OEBPS/%s", img.TextPath()),
|
||||
e.render(epubtemplates.Text, map[string]any{
|
||||
[]byte(e.render(epubtemplates.Text, map[string]any{
|
||||
"Title": fmt.Sprintf("Image %d Part %d", img.Id, img.Part),
|
||||
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.ViewWidth, e.Image.ViewHeight),
|
||||
"ImagePath": img.ImgPath(),
|
||||
"ImageStyle": img.ImgStyle(e.Image.ViewWidth, e.Image.ViewHeight, e.Image.Manga),
|
||||
}),
|
||||
})),
|
||||
)
|
||||
|
||||
if err == nil {
|
||||
@ -95,10 +95,10 @@ func (e *ePub) writeImage(wz *epubzip.EpubZip, img *epubimage.Image) error {
|
||||
func (e *ePub) writeBlank(wz *epubzip.EpubZip, img *epubimage.Image) error {
|
||||
return wz.WriteFile(
|
||||
fmt.Sprintf("OEBPS/Text/%d_sp.xhtml", img.Id),
|
||||
e.render(epubtemplates.Blank, map[string]any{
|
||||
[]byte(e.render(epubtemplates.Blank, map[string]any{
|
||||
"Title": fmt.Sprintf("Blank Page %d", img.Id),
|
||||
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.ViewWidth, e.Image.ViewHeight),
|
||||
}),
|
||||
})),
|
||||
)
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ func (e *ePub) getTree(images []*epubimage.Image, skip_files bool) string {
|
||||
func (e *ePub) Write() error {
|
||||
type zipContent struct {
|
||||
Name string
|
||||
Content any
|
||||
Content string
|
||||
}
|
||||
|
||||
epubParts, err := e.getParts()
|
||||
@ -280,8 +280,8 @@ func (e *ePub) Write() error {
|
||||
if err = wz.WriteMagic(); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, content := range content {
|
||||
if err := wz.WriteFile(content.Name, content.Content); err != nil {
|
||||
for _, c := range content {
|
||||
if err := wz.WriteFile(c.Name, []byte(c.Content)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package epubzip
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
@ -61,17 +60,7 @@ func (e *EpubZip) WriteImage(image *epubimagedata.ImageData) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *EpubZip) WriteFile(file string, data any) error {
|
||||
var content []byte
|
||||
switch b := data.(type) {
|
||||
case string:
|
||||
content = []byte(b)
|
||||
case []byte:
|
||||
content = b
|
||||
default:
|
||||
return fmt.Errorf("support string of []byte")
|
||||
}
|
||||
|
||||
func (e *EpubZip) WriteFile(file string, content []byte) error {
|
||||
m, err := e.wz.CreateHeader(&zip.FileHeader{
|
||||
Name: file,
|
||||
Modified: time.Now(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user