-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinterface.go
134 lines (123 loc) · 4.03 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package fb2
import (
"encoding/xml"
proto "github.com/centrypoint/fb2/prototype"
)
// List of interfaces for integration
// FB2 represents FB2 structure
//proteus:generate
type FB2 struct {
ID string `bson:"_id"`
FictionBook xml.Name `xml:"FictionBook" bson:"FictionBook"`
Stylesheet []string `xml:"stylesheet" bson:"stylesheet"`
Description struct {
TitleInfo struct {
Genre []string `xml:"genre" bson:"genre"`
GenreType []string `xml:"genreType" bson:"genreType"`
Author []AuthorType `xml:"author" bson:"author"`
BookTitle string `xml:"book-title" bson:"book-title"`
Annotation string `xml:"annotation" bson:"annotation"`
Keywords string `xml:"keywords" bson:"keywords"`
Date string `xml:"date" bson:"date"`
Coverpage struct {
Image struct {
Href string `xml:"xlink:href,attr" bson:"href"`
} `xml:"image,allowempty" bson:"image"`
} `xml:"coverpage" bson:"coverpage"`
Lang string `xml:"lang" bson:"lang"`
SrcLang string `xml:"src-lang" bson:"src-lang"`
Translator AuthorType `xml:"translator" bson:"translator"`
Sequence string `xml:"sequence" bson:"sequence"`
} `xml:"title-info" bson:"title-info"`
DocumentInfo struct {
Author []AuthorType `xml:"author" bson:"author"`
ProgramUsed string `xml:"program-used" bson:"program-used"`
Date string `xml:"date" bson:"date"`
SrcURL []string `xml:"src-url" bson:"src-url"`
SrcOcr string `xml:"src-ocr" bson:"src-ocr"`
ID string `xml:"id" bson:"id"`
Version float64 `xml:"version" bson:"version"`
History string `xml:"history" bson:"history"`
} `xml:"document-info" bson:"document-info"`
PublishInfo struct {
BookName string `xml:"book-name" bson:"book-name"`
Publisher string `xml:"publisher" bson:"publisher"`
City string `xml:"city" bson:"city"`
Year int `xml:"year" bson:"year"`
ISBN string `xml:"isbn" bson:"isbn"`
Sequence string `xml:"sequence" bson:"sequence"`
} `xml:"PublishInfo" bson:"PublishInfo"`
CustomInfo []struct {
InfoType string `xml:"info-type" bson:"info-type"`
} `xml:"custom-info" bson:"custom-info"`
} `xml:"description" bson:"description"`
Body struct {
Sections []struct {
P []string `xml:"p" bson:"p"`
} `xml:"section" bson:"section"`
} `xml:"body" bson:"body"`
Binary []struct {
Value string `xml:",chardata" bson:"value"`
ContentType string `xml:"content-type,attr" bson:"content-type"`
ID string `xml:"id,attr" bson:"id"`
} `xml:"binary" bson:"binary"`
}
// UnmarshalCoverpage func
func (f *FB2) UnmarshalCoverpage(data []byte) {
tagOpened := false
coverpageStartIndex := 0
coverpageEndIndex := 0
// imageHref := ""
tagName := ""
_loop:
for i, v := range data {
if tagOpened {
switch v {
case '>':
if tagName != "p" && tagName != "/p" {
}
tagOpened = false
if tagName == "coverpage" {
coverpageStartIndex = i + 1
} else if tagName == "/coverpage" {
coverpageEndIndex = i - 11
break _loop
}
tagName = ""
break
default:
tagName += string(v)
}
} else {
if v == '<' {
tagOpened = true
}
}
}
if coverpageEndIndex > coverpageStartIndex {
href := parseImage(data[coverpageStartIndex:coverpageEndIndex])
f.Description.TitleInfo.Coverpage.Image.Href = href
}
}
// AuthorType embedded fb2 type, represents author info
type AuthorType struct {
FirstName string `xml:"first-name"`
MiddleName string `xml:"middle-name"`
LastName string `xml:"last-name"`
Nickname string `xml:"nickname"`
HomePage string `xml:"home-page"`
Email string `xml:"email"`
}
// TextFieldType embedded fb2 type, represents text field
type TextFieldType struct {
}
// TitleType embedded fb2 type, represents title type fields
type TitleType struct {
P []string `xml:"p"`
EmptyLine []string `xml:"empty-line"`
}
// PType embedded fb2 type, represents paragraph
type PType struct {
}
// ProtoFB2 type
type ProtoFB2 proto.PFB2