...
1 package util
2
3 import (
4 "strings"
5 "time"
6 )
7
8 type UploadType struct {
9 Ext string
10 MIME string
11 Thumb string
12 }
13
14
15 type ImportConfig struct {
16 Address string
17 Username string
18 Password string
19 DBName string
20
21 Posts string
22 Keywords string
23 }
24
25 func (c ImportConfig) Enabled() bool {
26 return c != ImportConfig{}
27 }
28
29
30 type Config struct {
31 Locale string
32 Root string
33 Serve string
34 Header string
35
36 SaltData string
37 SaltPass string
38 SaltTrip string
39
40 Address string
41 Username string
42 Password string
43 DBName string
44 DBURL string
45
46 Template string
47
48 Identifiers bool
49
50 Uploads []string
51
52 Import ImportConfig
53
54
55 cachedUploads []*UploadType
56 ImportMode bool
57 ImportComplete bool
58 StartTime time.Time
59 }
60
61 func (c *Config) UploadTypes() []*UploadType {
62 if c.cachedUploads != nil {
63 return c.cachedUploads
64 }
65 uploads := []*UploadType{}
66 for _, upload := range c.Uploads {
67 fields := strings.Fields(upload)
68 if len(fields) < 2 {
69 continue
70 }
71 u := &UploadType{
72 Ext: strings.ToLower(fields[0]),
73 MIME: strings.ToLower(fields[1]),
74 }
75 if len(fields) > 2 {
76 u.Thumb = fields[2]
77 }
78 uploads = append(uploads, u)
79 }
80 c.cachedUploads = uploads
81 return uploads
82 }
83
View as plain text