-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
158 lines (132 loc) · 3.47 KB
/
model.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package model
import (
"fmt"
"path/filepath"
"time"
"github.com/eriq-augustine/comic-server/util"
)
const SERIES_IMAGE_BASEDIR = "series";
const COVER_IMAGE_FILENAME = "cover";
type Series struct {
ID int
Name string
AltNames *string
Author *string
Year *int
URL *string
Description *string
CoverImageRelPath *string
MetadataSource *string
MetadataSourceID *string
}
func EmptySeries() *Series {
return &Series{ID: -1};
}
func (this *Series) AssumeCrawl(crawl *MetadataCrawl) error {
this.MetadataSource = &crawl.MetadataSource;
this.MetadataSourceID = &crawl.MetadataSourceID;
if (this.AltNames == nil) {
this.AltNames = crawl.AltNames;
}
if (this.Author == nil) {
this.Author = crawl.Author;
}
if (this.Year == nil) {
this.Year = crawl.Year;
}
if (this.URL == nil) {
this.URL = crawl.URL;
}
if (this.Description == nil) {
this.Description = crawl.Description;
}
if ((this.CoverImageRelPath == nil) && (crawl.CoverImageRelPath != nil)) {
var filename = COVER_IMAGE_FILENAME + filepath.Ext(*crawl.CoverImageRelPath);
var coverRelPath = filepath.Join(SERIES_IMAGE_BASEDIR, fmt.Sprintf("%06d", this.ID), filename);
_, err := util.CopyImage(*crawl.CoverImageRelPath, coverRelPath);
if (err != nil) {
return fmt.Errorf("Failed to copy image from '%s' to '%s': %w.", *crawl.CoverImageRelPath, coverRelPath, err);
}
this.CoverImageRelPath = &coverRelPath;
}
return nil;
}
func (this *Series) String() string {
text, _ := util.ToJSON(this);
return text;
}
// Archives are things the relate to physical files/directories on disk.
// The are (or can be) packaged up in a single CBZ file.
type Archive struct {
ID int
RelPath string
Series *Series
Volume *string
Chapter *string
PageCount *int
CoverImageRelPath *string
}
func EmptyArchive(relpath string) *Archive {
return &Archive{
ID: -1,
RelPath: relpath,
Series: EmptySeries()}
;
}
// Assume all the attributes of other.
func (this *Archive) Assume(other *Archive) {
this.ID = other.ID;
this.RelPath = other.RelPath;
this.Series = other.Series;
this.Volume = other.Volume;
this.Chapter = other.Chapter;
this.PageCount = other.PageCount;
this.CoverImageRelPath = other.CoverImageRelPath;
}
func (this *Archive) String() string {
text, _ := util.ToJSON(this);
return text;
}
type MetadataCrawlRequest struct {
ID int
Series *Series
Query string
Timestamp time.Time
}
func EmptyCrawlRequest() *MetadataCrawlRequest {
return &MetadataCrawlRequest{
ID: -1,
Series: EmptySeries(),
};
}
func (this *MetadataCrawlRequest) String() string {
text, _ := util.ToJSON(this);
return text;
}
type MetadataCrawl struct {
ID int
MetadataSource string
MetadataSourceID string
SourceSeries *Series
Name string
AltNames *string
Author *string
Year *int
URL *string
Description *string
CoverImageRelPath *string
Timestamp time.Time
}
func EmptyCrawl(source string, sourceID string) *MetadataCrawl {
return &MetadataCrawl{
ID: -1,
MetadataSource: source,
MetadataSourceID: sourceID,
SourceSeries: EmptySeries(),
Timestamp: time.Now(),
};
}
func (this *MetadataCrawl) String() string {
text, _ := util.ToJSON(this);
return text;
}