-
Notifications
You must be signed in to change notification settings - Fork 3
/
gf_images_service.go
264 lines (225 loc) · 8.38 KB
/
gf_images_service.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
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_lib
import (
"fmt"
"net/http"
"strconv"
"github.com/gloflow/gloflow/go/gf_core"
"github.com/gloflow/gloflow/go/gf_rpc_lib"
"github.com/gloflow/gloflow/go/gf_extern_services/gf_aws"
"github.com/gloflow/gloflow/go/gf_apps/gf_images_lib/gf_images_core"
"github.com/gloflow/gloflow/go/gf_apps/gf_images_lib/gf_images_core/gf_images_storage"
"github.com/gloflow/gloflow/go/gf_apps/gf_images_lib/gf_gif_lib"
"github.com/gloflow/gloflow/go/gf_apps/gf_images_lib/gf_images_service"
"github.com/gloflow/gloflow/go/gf_apps/gf_images_lib/gf_image_editor"
"github.com/gloflow/gloflow/go/gf_apps/gf_images_lib/gf_images_jobs"
"github.com/gloflow/gloflow/go/gf_apps/gf_images_lib/gf_images_jobs_core"
"github.com/gloflow/gloflow/go/gf_apps/gf_images_lib/gf_images_flows"
// "github.com/davecgh/go-spew/spew"
)
//-------------------------------------------------
func InitService(pHTTPmux *http.ServeMux,
pServiceInfo *gf_images_core.GFserviceInfo,
pConfig *gf_images_core.GFconfig,
pRuntimeSys *gf_core.RuntimeSys) gf_images_jobs_core.JobsMngr {
//-------------
// METRICS
metrics := gf_images_core.MetricsCreate("gf_images")
//-------------
// DB_INDEXES
// IMPORTANT!! - make sure mongo has indexes build for relevant queries
gf_images_service.DBmongoIndexInit(pRuntimeSys)
//-------------
// S3
// REMOVE!! - usage of AWS creds here, they should be discovered
// by the AWS client from the environment.
s3Info, gfErr := gf_aws.S3init(// pServiceInfo.AWS_access_key_id_str,
// pServiceInfo.AWS_secret_access_key_str,
// pServiceInfo.AWS_token_str,
pRuntimeSys)
if gfErr != nil {
panic(gfErr.Error)
}
//---------------------
// IMAGE_STORAGE
storageConfig := &gf_images_storage.GFimageStorageConfig{
TypesToProvisionLst: []string{"s3", "ipfs"},
IPFSnodeHostStr: pConfig.IPFSnodeHostStr,
ThumbsS3bucketNameStr: pConfig.ImagesFlowToS3bucketMap["general"],
UploadsSourceS3bucketNameStr: pConfig.Uploaded_images_s3_bucket_str,
UploadsTargetS3bucketNameStr: pConfig.ImagesFlowToS3bucketMap["general"],
ExternImagesS3bucketNameStr: pConfig.ImagesFlowToS3bucketMap["general"],
}
imageStorage, gfErr := gf_images_storage.Init(storageConfig, pRuntimeSys)
if gfErr != nil {
panic(gfErr.Error)
}
//-------------
// JOBS_MANAGER
jobsMngrCh := gf_images_jobs.Init(pServiceInfo.ImagesStoreLocalDirPathStr,
pServiceInfo.ImagesThumbnailsStoreLocalDirPathStr,
pServiceInfo.VideoStoreLocalDirPathStr,
pServiceInfo.MediaDomainStr,
pConfig,
imageStorage,
s3Info,
metrics,
pRuntimeSys)
gf_images_jobs.InitHandlers(pHTTPmux, jobsMngrCh, pRuntimeSys)
//-------------
// IMAGE_FLOWS
gfErr = gf_images_flows.Init(pRuntimeSys)
if gfErr != nil {
panic(gfErr.Error)
}
// flows__templates_dir_path_str := pServiceInfo.Templates_dir_paths_map["flows_str"]
gfErr = gf_images_flows.InitHandlers(pServiceInfo.AuthSubsystemTypeStr,
pServiceInfo.AuthLoginURLstr,
pServiceInfo.KeyServer,
pHTTPmux,
pServiceInfo.TemplatesPathsMap,
jobsMngrCh,
pRuntimeSys)
if gfErr != nil {
panic(gfErr.Error)
}
//-------------
// GIF
gfErr = gf_gif_lib.InitHandlers(pHTTPmux, pRuntimeSys)
if gfErr != nil {
panic(gfErr.Error)
}
/*
gf_gif_lib.Init_img_to_gif_migration(*p_images_store_local_dir_path_str,
*p_images_main_s3_bucket_name_str,
s3_client,
s3_uploader, // s3_client,
mongodb_coll,
pLogFun)
*/
//-------------
// IMAGE_EDITOR
gf_image_editor.InitHandlers(pHTTPmux, pRuntimeSys)
//-------------
// HANDLERS
gfErr = gf_images_service.InitHandlers(pServiceInfo.AuthSubsystemTypeStr,
pServiceInfo.AuthLoginURLstr,
pServiceInfo.KeyServer,
pHTTPmux,
pServiceInfo.TemplatesPathsMap,
jobsMngrCh,
pConfig,
pServiceInfo,
pServiceInfo.MediaDomainStr,
imageStorage,
s3Info,
metrics,
pRuntimeSys)
if gfErr != nil {
panic(gfErr.Error)
}
//------------------------
// STATIC_FILE SERVING
staticFilesURLbaseStr := "/images"
localDirPathStr := "./static"
gf_core.HTTPinitStaticServingWithMux(staticFilesURLbaseStr,
localDirPathStr,
pHTTPmux,
pRuntimeSys)
//------------------------
return jobsMngrCh
}
//-------------------------------------------------
// Run_service runs/starts the gf_images service in the same process as where its being called.
// An HTTP servr is started and listens on a supplied port.
// DB(MongoDB) connection is established as well.
// S3 client is initialized as a target file-system for image files.
func RunService(pHTTPmux *http.ServeMux,
pServiceInfo *gf_images_core.GFserviceInfo,
pInitDoneCh chan bool,
pLogFun func(string, string)) {
pLogFun("INFO", "")
pLogFun("INFO", " >>>>>>>>>>> STARTING GF_IMAGES SERVICE")
pLogFun("INFO", "")
logo_str := `. .. .
. . . . .
. ..xxxxxxxxxx.... . . .
. MWMWMWWMWMWMWMWMWMWMWMWMW .
IIIIMWMWMWMWMWMWMWMWMWMWMWMWMWMttii: . .
. IIYVVXMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWxx... . .
IWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMx..
IIWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWNMWMWMWMWMWMWMWMWMWMWMWMWMx.. .
""MWMWMWMWMWM"""""""". .:.. ."""""MWMWMWMWMWMWMWMWMWMWMWMWMWti.
. "" . .: . :. : . . :. . . . . """"MWMWMWMWMWMWMWMWMWMWMWMWMti=
. . : . : . .'.' '....xxxxx...,'. ' ' ."""YWMWMWMWMWMWMWMWMWMW+
; . . . : . .' : . ..XXXXXXXXXXXXXXXXXXXXx. . YWMWMWMWMWMWMW
. . . . . . . ..XXXXXXXXWWWWWWWWWWWWWWWWXXXX. . . """""""
' : : . : . ...XXXXXWWW" W88N88@888888WWWWWXX. . . . .
. ' . . : ...XXXXXXWWW" M88Ng8GGGG5G888^8M "WMBX. . .. :
: ..XXXXXXXXWWW" M88a8WWRWWWMW8oo88M WWMX. . : .
"XXXXXXXXXXXXWW" WN8s88WWWWW W8@@@8M BMBRX. . : :
. XXXXXXXX=MMWW": . W8N888WWWWWWWW88888W XRBRXX. . .
.... ""XXXXXMM::::. . W8@889WWWWWM8@8N8W . . :RRXx. .
.....''' MMM::.:. . W888N89999888@8W . . ::::"RXV . :
. ..''''' MMMm::. . WW888N88888WW . . mmMMMMMRXx
..' . ""MMmm . . WWWWWWW . :. :,miMM""" : "" .
. . ""MMMMmm . . . . ._,mMMMM""" : ' . :
. ""MMMMMMMMMMMMM""" . : . ' . .
. . . . . .
. . . .`
pLogFun("INFO", logo_str)
//-------------
// RUNTIME_SYS
runtimeSys := &gf_core.RuntimeSys{
ServiceNameStr: "gf_images",
LogFun: pLogFun,
}
mongoDB, _, gfErr := gf_core.MongoConnectNew(pServiceInfo.Mongodb_host_str,
pServiceInfo.Mongodb_db_name_str,
nil,
runtimeSys)
if gfErr != nil {
return
}
runtimeSys.Mongo_db = mongoDB
runtimeSys.Mongo_coll = mongoDB.Collection("data_symphony")
//-------------
// CONFIG
config, gfErr := gf_images_core.ConfigGet(pServiceInfo.ConfigFilePathStr,
pServiceInfo.UseNewStorageEngineBool,
pServiceInfo.IPFSnodeHostStr,
runtimeSys)
if gfErr != nil {
return
}
//------------------------
// INIT
InitService(pHTTPmux, pServiceInfo, config, runtimeSys)
//------------------------
// IMPORTANT!! - signal to user that server in this goroutine is ready to start listening
if pInitDoneCh != nil {
pInitDoneCh <- true
}
//----------------------
portInt, err := strconv.Atoi(pServiceInfo.Port_str)
if err != nil {
fmt.Println(err)
panic(1)
}
// SERVER_INIT - blocking
gf_rpc_lib.ServerInitWithMux("gf_images", portInt, pHTTPmux)
}