-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgamer.cpp
326 lines (190 loc) · 7.52 KB
/
gamer.cpp
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#include "crow_all.h"
#include "s3-upload.cpp"
#include <iostream>
using namespace std;
int send_to_s3(string file_name,string file_data) {
//If no data to upload, fail immediately
if (file_name == "" || file_data == ""){
return 1;
}
cout << "Saving: " << file_name;
std::ofstream out(file_name);
out << file_data;
out.close();
Aws::SDKOptions options;
Aws::InitAPI(options);
{
Aws::String aws_s(file_name.c_str(), file_name.size());
const Aws::String bucket_name = std::getenv("BUCKET_NAME");
const Aws::String object_name = aws_s;
const Aws::String region = std::getenv("BUCKET_REGION");
if (!AwsDoc::S3::PutObject(bucket_name, object_name, region)) {
return 1;
}
}
Aws::ShutdownAPI(options);
return 0;
}
int main(void) {
crow::SimpleApp app;
crow::mustache::set_base(".");
app.loglevel(crow::LogLevel::WARNING);
CROW_ROUTE(app, "/") ([]() {
crow::mustache::context ctx;
auto main_page = crow::mustache::load("index.html");
return main_page.render();
});
CROW_ROUTE(app, "/contato.html") ([] () {
crow::mustache::context ctx2;
auto contato = crow::mustache::load("/contato.html");
return contato.render();
});
CROW_ROUTE(app, "/index.html") ([] () {
crow::mustache::context ctx3;
auto index = crow::mustache::load("/index.html");
return index.render();
});
CROW_ROUTE(app, "/send").methods("POST"_method) ([](const crow::request& req, crow::response& res) {
// simply by reading a crow::request
// crow::multipart::message
// Once a multipart message has been made, the individual parts can be accessed throught mpmes.parts, parts is an std::vector, so accessing the individual parts should be straightforward.
// In order to access the individual part's name or filename, something like mpmes.parts[0].headers[0].params["name"] sould do the trick.
auto msg = crow::multipart::message(req);
// Parts index is defined by the HTML form.
int result = send_to_s3(msg.parts[5].headers[0].params["filename"],msg.parts[5].body);
res.redirect("/sent/"+to_string(result));
res.end();
});
CROW_ROUTE(app, "/sent/<int>")([](int result) {
auto submission = crow::mustache::load("/submission.html");
crow::mustache::context ctx;
if (result==0){
ctx["submission_result"]="Recebemos a aplicação com sucesso";
}
else{
ctx["submission_result"]="Infelizmente algo deu errado ): Veja o Terminal para ver o que deu errado!";
}
return submission.render(ctx);
});
CROW_ROUTE(app, "/css/cafeteria.css") ([]() {
crow::mustache::context css;
auto style = crow::mustache::load("/css/cafeteria.css");
return style.render();
});
CROW_ROUTE(app, "/css/font-awesome.min.css") ([] () {
crow::mustache::context css2;
auto style2 = crow::mustache::load("/css/font-awesome.min.css");
return style2.render();
});
CROW_ROUTE(app, "/css/materialize.min.css") ([] () {
crow::mustache::context css3;
auto style3 = crow::mustache::load("/css/materialize.min.css");
return style3.render();
});
// Routes using args are failing.
// CROW_ROUTE(app, "/css/<string>")
// ([] (string p) {
// crow::mustache::context css3;
// auto css = crow::mustache::load("/css/"+p);
// return css.render();
// });
// CROW_ROUTE(app, "/js/<string>")
// ([] (string p) {
// crow::mustache::context js;
// auto script = crow::mustache::load("/js/"+p);
// return script.render();
// });
// CROW_ROUTE(app, "/imagens/<string>")
// ([] (string p) {
// crow::mustache::context img;
// auto image = crow::mustache::load("/imagens/"+p);
// return image.render();
// });
// CROW_ROUTE(app, "/fonts/<string>")
// ([] (string p) {
// crow::mustache::context fon;
// auto fonte1 = crow::mustache::load("/fonts/"+p);
// return fonte1.render();
// });
CROW_ROUTE(app, "/js/materialize.min.js") ([] () {
crow::mustache::context js;
auto style4 = crow::mustache::load("/js/materialize.min.js");
return style4.render();
});
CROW_ROUTE(app, "/js/jquery.js") ([] () {
crow::mustache::context js2;
auto style5 = crow::mustache::load("/js/jquery.js");
return style5.render();
});
CROW_ROUTE(app, "/imagens/cafeteria2.png") ([] () {
crow::mustache::context img;
auto img1 = crow::mustache::default_loader("/imagens/cafeteria2.png");
return img1;
});
CROW_ROUTE(app, "/imagens/cafe2.jpg") ([] () {
crow::mustache::context img2;
auto img3 = crow::mustache::default_loader("/imagens/cafe2.jpg");
return img3;
});
CROW_ROUTE(app, "/imagens/lanche13.jpg") ([] () {
crow::mustache::context img4;
auto img5 = crow::mustache::default_loader("/imagens/lanche13.jpg");
return img5;
});
CROW_ROUTE(app, "/imagens/pao4.jpg") ([] () {
crow::mustache::context img6;
auto img7 = crow::mustache::default_loader("/imagens/pao4.jpg");
return img7;
});
CROW_ROUTE(app, "/imagens/cafe3.jpg") ([] () {
crow::mustache::context img8;
auto img9 = crow::mustache::default_loader("/imagens/cafe3.jpg");
return img9;
});
CROW_ROUTE(app, "/imagens/cafe5.jpg") ([] () {
crow::mustache::context img10;
auto img11 = crow::mustache::default_loader("/imagens/cafe5.jpg");
return img11;
});
CROW_ROUTE(app, "/imagens/cafe14.jpg") ([] () {
crow::mustache::context img12;
auto img13 = crow::mustache::default_loader("/imagens/cafe14.jpg");
return img13;
});
CROW_ROUTE(app, "/imagens/cafeteria1.jpg") ([] () {
crow::mustache::context img14;
auto img15 = crow::mustache::default_loader("/imagens/cafeteria1.jpg");
return img15;
});
CROW_ROUTE(app, "/fonts/roboto/Roboto-Regular.woff2") ([] () {
crow::mustache::context fon;
auto fonte1 = crow::mustache::load("/fonts/roboto/Roboto-Regular.woff2");
return fonte1.render();
});
CROW_ROUTE(app, "/fonts/fontawesome-webfont.woff2") ([] () {
crow::mustache::context fon2;
auto fonte2 = crow::mustache::load("/fonts/fontawesome-webfont.woff2");
return fonte2.render();
});
CROW_ROUTE(app, "/fonts/roboto/Roboto-Medium.woff2") ([] () {
crow::mustache::context fon3;
auto fonte3 = crow::mustache::load("/fonts/roboto/Roboto-Medium.woff2");
return fonte3.render();
});
CROW_ROUTE(app, "/fonts/roboto/Roboto-Regular.woff") ([] () {
crow::mustache::context fon4;
auto fonte4 = crow::mustache::load("/fonts/roboto/Roboto-Regular.woff");
return fonte4.render();
});
CROW_ROUTE(app, "/fonts/fontawesome-webfont.woff") ([] () {
crow::mustache::context fon5;
auto fonte5 = crow::mustache::load_text("/fonts/fontawesome-webfont.woff");
return fonte5;
});
CROW_ROUTE(app, "/fonts/fontawesome-webfont.ttf") ([] () {
crow::mustache::context fon6;
auto fonte6 = crow::mustache::load("/fonts/fontawesome-webfont.ttf");
return fonte6.render();
});
app.port(8080).run();
}