-
Notifications
You must be signed in to change notification settings - Fork 3
/
gf_image_config.go
170 lines (127 loc) · 5.36 KB
/
gf_image_config.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
159
160
161
162
163
164
165
166
167
168
169
170
/*
GloFlow application and media management/publishing platform
Copyright (C) 2019 Ivan Trajkovic
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package gf_images_core
import (
"io/ioutil"
"gopkg.in/yaml.v2"
"github.com/gloflow/gloflow/go/gf_core"
"github.com/gloflow/gloflow/go/gf_identity/gf_identity_core"
)
//-------------------------------------------------
type GFserviceInfo struct {
Port_str string
DomainBaseStr string
// DB
Mongodb_host_str string
Mongodb_db_name_str string
ImagesStoreLocalDirPathStr string
ImagesThumbnailsStoreLocalDirPathStr string
VideoStoreLocalDirPathStr string
MediaDomainStr string
ImagesMainS3bucketNameStr string
TemplatesPathsMap map[string]string
ConfigFilePathStr string
// email address from which image sharing emails are sent
EmailSharingSenderAddressStr string
//------------------------
// AUTH_SUBSYSTEM_TYPE
AuthSubsystemTypeStr string
// AUTH_LOGIN_URL - url of the login page to which the system should
// redirect users when email is confirmed.
AuthLoginURLstr string
KeyServer *gf_identity_core.GFkeyServerInfo
//------------------------
// NEW_STORAGE_ENGINE - flag indicating if the new image storage engine should be used
UseNewStorageEngineBool bool
// IPFS_NODE_HOST - host/gateway to use to connect to for IPFS operations
IPFSnodeHostStr string
// EVENTS_APP - enable sending of app events from various functions
EnableEventsAppBool bool
}
//-------------------------------------------------
type GFconfig struct {
ImagesStoreLocalDirPathStr string `yaml:"store_local_dir_path"`
ImagesThumbnailsStoreLocalDirPathStr string `yaml:"thumbnails_store_local_dir_path"`
VideoStoreLocalDirPathStr string `yaml:"videos_store_local_dir_path"`
MediaDomainStr string `yaml:"media_domain"`
MainS3bucketNameStr string `yaml:"main_s3_bucket_name"`
EmailSharingSenderAddressStr string `yaml:"email_sharing_sender_address"`
//------------------------
// FUNCTIONS - buckets for particular functions in that system
// UPLOADED_IMAGES - this is a special dedicated bucket, separate from buckets for all other flows.
// Mainly because users are pushing data to it directly and so we want to possibly handle
// it in a separate way from other buckets that only have internal GF systems
// uploading data to it.
Uploaded_images_s3_bucket_str string `yaml:"uploaded_images_s3_bucket"`
// BOOKMARKS_IMAGES - dedicated bucket for screenshots of bookmarks
Bookmark_images_s3_bucket_str string `yaml:"bookmark_images_s3_bucket"`
//------------------------
ImagesFlowToS3bucketDefaultStr string `yaml:"images_flow_to_s3_bucket_default"`
ImagesFlowToS3bucketMap map[string]string `yaml:"images_flow_to_s3_bucket"`
UseNewStorageEngineBool bool `yaml:"use_new_storage_engine"`
//------------------------
// IPFS
IPFSnodeHostStr string `yaml:"ipfs_node_host"`
//------------------------
// PY
//------------------------
// PLUGINGS
PluginsPyDirPathStr string `yaml:"plugins_py_dir_path"`
// IMAGE_CLASSIFY
ImagesClassifyPyDirPathStr string `yaml:"images_classify_py_dir_path"`
//------------------------
}
//-------------------------------------------------
func ConfigGetS3bucketForFlow(pFlowNameStr string,
pConfig *GFconfig) string {
var s3bucketNameFinalStr string
if s3bucketStr, ok := pConfig.ImagesFlowToS3bucketMap[pFlowNameStr]; !ok {
s3bucketNameFinalStr = s3bucketStr
} else {
s3bucketNameFinalStr = pConfig.ImagesFlowToS3bucketDefaultStr
}
return s3bucketNameFinalStr
}
//-------------------------------------------------
func ConfigGet(pConfigPathStr string,
pUseNewStorageEngineBool bool,
pIPFSnodeHostStr string,
pRuntimeSys *gf_core.RuntimeSys) (*GFconfig, *gf_core.GFerror) {
configStr, err := ioutil.ReadFile(pConfigPathStr)
if err != nil {
gfErr := gf_core.ErrorCreate("failed to read YAML config for gf_images",
"file_read_error",
map[string]interface{}{"config_path": pConfigPathStr,},
err, "gf_images_core", pRuntimeSys)
return nil, gfErr
}
config := &GFconfig{}
// YAML - parse config file
err = yaml.Unmarshal([]byte(configStr), config)
if err != nil {
gfErr := gf_core.ErrorCreate("failed to parse YAML config for gf_images",
"yaml_decode_error",
map[string]interface{}{"config_path": pConfigPathStr,},
err, "gf_images_core", pRuntimeSys)
return nil, gfErr
}
//------------------------
// IPFS
config.UseNewStorageEngineBool = pUseNewStorageEngineBool
config.IPFSnodeHostStr = pIPFSnodeHostStr
//------------------------
return config, nil
}