[add] better error handling, [add] font selector, [add] tailwind generation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
Binary file not shown.
@@ -8,6 +8,20 @@ import (
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
func getEPUBMetadata(filepath string) (*MetadataInfo, error) {
|
||||
rc, err := epub.OpenReader(filepath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rf := rc.Rootfiles[0]
|
||||
|
||||
return &MetadataInfo{
|
||||
Title: &rf.Title,
|
||||
Author: &rf.Creator,
|
||||
Description: &rf.Description,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func countEPUBWords(filepath string) (int64, error) {
|
||||
rc, err := epub.OpenReader(filepath)
|
||||
if err != nil {
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestGBooksISBNQuery(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGBooksTitleQuery(t *testing.T) {
|
||||
title := "Alice in Wonderland"
|
||||
title := "Alice in Wonderland 1877527815"
|
||||
metadataResp, err := getGBooksMetadata(MetadataInfo{
|
||||
Title: &title,
|
||||
})
|
||||
|
||||
@@ -67,3 +67,16 @@ func GetWordCount(filepath string) (int64, error) {
|
||||
return 0, errors.New("Invalid Extension")
|
||||
}
|
||||
}
|
||||
|
||||
func GetMetadata(filepath string) (*MetadataInfo, error) {
|
||||
fileMime, err := mimetype.DetectFile(filepath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if fileExtension := fileMime.Extension(); fileExtension == ".epub" {
|
||||
return getEPUBMetadata(filepath)
|
||||
} else {
|
||||
return nil, errors.New("Invalid Extension")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,31 @@ import (
|
||||
|
||||
func TestGetWordCount(t *testing.T) {
|
||||
var want int64 = 30477
|
||||
wordCount, err := countEPUBWords("./_test_files/alice.epub")
|
||||
wordCount, err := countEPUBWords("../_test_files/alice.epub")
|
||||
|
||||
if wordCount != want {
|
||||
t.Fatalf(`Expected: %v, Got: %v, Error: %v`, want, wordCount, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMetadata(t *testing.T) {
|
||||
metadataInfo, err := getEPUBMetadata("../_test_files/alice.epub")
|
||||
if err != nil {
|
||||
t.Fatalf(`Expected: *MetadataInfo, Got: nil, Error: %v`, err)
|
||||
}
|
||||
|
||||
want := "Alice's Adventures in Wonderland / Illustrated by Arthur Rackham. With a Proem by Austin Dobson"
|
||||
if *metadataInfo.Title != want {
|
||||
t.Fatalf(`Expected: %v, Got: %v, Error: %v`, want, *metadataInfo.Title, err)
|
||||
}
|
||||
|
||||
want = "Lewis Carroll"
|
||||
if *metadataInfo.Author != want {
|
||||
t.Fatalf(`Expected: %v, Got: %v, Error: %v`, want, *metadataInfo.Author, err)
|
||||
}
|
||||
|
||||
want = ""
|
||||
if *metadataInfo.Description != want {
|
||||
t.Fatalf(`Expected: %v, Got: %v, Error: %v`, want, *metadataInfo.Description, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user