404
текст книги не найден на сервере
обратитесь к администратору библиотеки
"))
} else {
ctx.JSON(500, gin.H{"err": err})
}
return
}
var bookFile *zip.File
for _, file := range bookcase.File {
if file.Name == book.Filename {
bookFile = file
break
}
}
bookReader, _ := bookFile.Open()
bookContent, _ = io.ReadAll(bookReader)
} else {
bookContent, _ = os.ReadFile(UPLOADS_DIR + "/books/" + book.Filename)
}
switch book.Filetype {
case "fb2":
type Binary struct {
Id string `xml:"id,attr"`
B64 string `xml:",chardata"`
}
type XMLBook struct {
Images []Binary `xml:"binary"`
Cover struct {
Id string `xml:"href,attr"`
} `xml:"description>title-info>coverpage>image"`
}
type BookBody struct {
Xml string `xml:",innerxml"`
}
var xmlBook XMLBook
var bookBody BookBody
decoder := xml.NewDecoder(bytes.NewBuffer(bookContent))
decoder.CharsetReader = charset.NewReaderLabel
for t, _ := decoder.Token(); t != nil; t, _ = decoder.Token() {
if se, ok := t.(xml.StartElement); ok {
if se.Name.Local == "body" {
decoder.DecodeElement(&bookBody, &se)
break
}
}
}
decoder = xml.NewDecoder(bytes.NewBuffer(bookContent))
decoder.CharsetReader = charset.NewReaderLabel
decoder.Decode(&xmlBook)
titleOpen := regexp.MustCompile("(title|subtitle)")
textAuthor := regexp.MustCompile("text-author")
emptyLine := regexp.MustCompile("empty-line")
sub := regexp.MustCompile("