-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
96 lines (88 loc) · 2.47 KB
/
main.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
//
// Created by zerocool on 12/11/22.
//
#include <iostream>
#include <algorithm>
#include <cctype>
#include "log.h"
#include "HttpServer.h"
struct Args {
bool megaDebug;
const char* appPort;
const char* megaApiKey;
int threads;
int megaThreads;
};
int run(Args& args)
{
mega::MegaApi* api;
MegaDownloader* downloader;
api = new mega::MegaApi(args.megaApiKey, (const char*)NULL, "MegaSDKRestPP", args.megaThreads);
downloader = new MegaDownloader(args.megaApiKey, api);
if (args.megaDebug)
{
api->setLogToConsole(true);
api->setLogLevel(mega::MegaApi::LOG_LEVEL_DEBUG);
}
LOG_F(INFO, "creating server on 0.0.0.0:%s with %d threads", args.appPort, args.threads);
HttpServer* httpServer = new HttpServer(downloader);
httpServer->InitEndpoints();
httpServer->StartServer(args.appPort, args.threads);
LOG_F(INFO, "cleaning httpServer..");
delete httpServer;
return 0;
}
int main(int argc, char* argv[])
{
Args args;
const char* megaApiKey = std::getenv("MEGA_API_KEY");
if (megaApiKey == NULL)
{
std::cerr << "Environment variable MEGA_API_KEY not set, exitting!!!" << std::endl;
return -1;
}
const char* appPort = std::getenv("APP_PORT");
if (appPort == NULL)
{
appPort = "8069";
}
const char* logFile = std::getenv("LOG_FILE");
if (logFile == NULL)
{
logFile = "log.txt";
}
const char* threadCount = std::getenv("APP_THREADS");
if (threadCount == NULL) {
args.threads = 1;
} else {
std::stringstream ss(threadCount);
ss >> args.threads;
}
const char* megaThreadCount = std::getenv("MEGA_THREADS");
if (megaThreadCount == NULL) {
args.megaThreads = 1;
} else {
std::stringstream ss(megaThreadCount);
ss >> args.megaThreads;
}
const char* megaDebugChar = std::getenv("MEGA_DEBUG");
if (megaDebugChar == NULL) {
args.megaDebug = false;
} else {
std::string megaDebug = megaDebugChar;
std::transform(megaDebug.begin(), megaDebug.end(), megaDebug.begin(),
[](unsigned char c){
return std::tolower(c);
}
);
if (megaDebug == "true") {
args.megaDebug = true;
} else {
args.megaDebug = false;
}
}
args.appPort = appPort;
args.megaApiKey = megaApiKey;
InitializeLogger(argc, argv, logFile);
return run(args);
}