Committing updates.

This commit is contained in:
Преподобный Ален
2022-09-23 17:29:02 +03:00
parent 7fd514a961
commit 1ef81e8344
4 changed files with 22 additions and 30 deletions

View File

@@ -320,9 +320,9 @@ namespace Apostol {
} }
//-------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------
void CCustomModule::CreateAccessToken(const CProvider &Provider, const CString &Application, CContext &Context) { void CCustomModule::CreateAccessToken(CContext &Context, CProvider &Provider, const CString &Application) {
auto OnDone = [this, &Context](CTCPConnection *Sender) { auto OnDone = [this, &Context, &Provider](CTCPConnection *Sender) {
auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender); auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender);
auto pReply = pConnection->Reply(); auto pReply = pConnection->Reply();
@@ -337,18 +337,24 @@ namespace Apostol {
Context.Tokens().Values("access_token", Json["access_token"].AsString()); Context.Tokens().Values("access_token", Json["access_token"].AsString());
Provider.KeyStatus(ksSuccess);
ModuleStatus(Context); ModuleStatus(Context);
} else {
Provider.KeyStatus(ksFailed);
} }
return true; return true;
}; };
auto OnFail = [&Context](CTCPConnection *Sender, const Delphi::Exception::Exception &E) { auto OnFail = [&Context, &Provider](CTCPConnection *Sender, const Delphi::Exception::Exception &E) {
Context.SetStatus(csInitialized); Context.SetStatus(csInitialized);
auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender); auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender);
auto pClient = dynamic_cast<CHTTPClient *> (pConnection->Client()); auto pClient = dynamic_cast<CHTTPClient *> (pConnection->Client());
Provider.KeyStatus(ksFailed);
DebugReply(pConnection->Reply()); DebugReply(pConnection->Reply());
Log()->Error(APP_LOG_ERR, 0, "[%s:%d] %s", pClient->Host().c_str(), pClient->Port(), E.what()); Log()->Error(APP_LOG_ERR, 0, "[%s:%d] %s", pClient->Host().c_str(), pClient->Port(), E.what());
@@ -371,16 +377,16 @@ namespace Apostol {
} }
//-------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------
void CCustomModule::FetchProviders(CDateTime Now, CContext &Context) { void CCustomModule::CheckProviders(CContext &Context, CDateTime Now) {
for (int i = 0; i < Context.Providers().Count(); i++) { for (int i = 0; i < Context.Providers().Count(); i++) {
auto &Provider = Context.Providers()[i].Value(); auto &Provider = Context.Providers()[i].Value();
for (int j = 0; j < Provider.Applications().Count(); ++j) { for (int j = 0; j < Provider.Applications().Count(); ++j) {
const auto &app = Provider.Applications().Members(j); const auto &caApplication = Provider.Applications().Members(j);
if (app["type"].AsString() == "service_account") { if (caApplication["type"].AsString() == "service_account") {
if (Provider.KeyStatus() == ksUnknown) { if (Provider.KeyStatus() != ksFetching) {
CreateAccessToken(Provider, app.String(), Context);
Provider.KeyStatusTime(Now); Provider.KeyStatusTime(Now);
Provider.KeyStatus(ksSuccess); Provider.KeyStatus(ksFetching);
CreateAccessToken(Context, Provider, caApplication.String());
} }
} }
} }
@@ -388,24 +394,13 @@ namespace Apostol {
} }
//-------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------
void CCustomModule::CheckProviders(CDateTime Now, CContext &Context) {
for (int i = 0; i < Context.Providers().Count(); i++) {
auto& Provider = Context.Providers()[i].Value();
if (Provider.KeyStatus() != ksUnknown) {
Provider.KeyStatusTime(Now);
Provider.KeyStatus(ksUnknown);
}
}
}
//--------------------------------------------------------------------------------------------------------------
void CCustomModule::CheckDeal(const CDeal &Deal) { void CCustomModule::CheckDeal(const CDeal &Deal) {
const auto &Data = Deal.Data(); const auto &Data = Deal.Data();
const auto DateTime = UTC(); const auto DateTime = UTC();
const auto Date = StringToDate(Data.Date); const auto Date = StringToDate(Data.Date);
const auto Sum = BTCToDouble(Data.Payment.Sum); //const auto Sum = BTCToDouble(Data.Payment.Sum);
if (Data.Order == doCreate) { if (Data.Order == doCreate) {
if (DateTime < Date) if (DateTime < Date)

View File

@@ -95,10 +95,9 @@ namespace Apostol {
} }
//---------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------
void FetchProviders(CDateTime Now, CContext &Context); void CheckProviders(CContext &Context, CDateTime Now);
static void CheckProviders(CDateTime Now, CContext &Context);
void CreateAccessToken(const CProvider &Provider, const CString &Application, CContext &Context); void CreateAccessToken(CContext &Context, CProvider &Provider, const CString &Application);
void ParsePGPKey(const CString &Key, CStringPairs &ServerList, CStringList &BTCKeys); void ParsePGPKey(const CString &Key, CStringPairs &ServerList, CStringList &BTCKeys);
void ModuleService(CContext &Context); void ModuleService(CContext &Context);

View File

@@ -93,7 +93,6 @@ namespace Apostol {
const auto &caFormat = pServerRequest->Params["payload"]; const auto &caFormat = pServerRequest->Params["payload"];
if (!caFormat.IsEmpty()) { if (!caFormat.IsEmpty()) {
if (caFormat == "html") { if (caFormat == "html") {
pServerReply->ContentType = CHTTPReply::html; pServerReply->ContentType = CHTTPReply::html;
} else if (caFormat == "json") { } else if (caFormat == "json") {
@@ -111,11 +110,12 @@ namespace Apostol {
} }
pProxyConnection->SendReply(pProxyReply->Status, nullptr, true); pProxyConnection->SendReply(pProxyReply->Status, nullptr, true);
} else { } else {
pServerReply->Content = pProxyReply->Content;
pProxyConnection->SendStockReply(pProxyReply->Status, true); pProxyConnection->SendStockReply(pProxyReply->Status, true);
} }
} else { } else {
pServerReply->Content = pProxyReply->Content;
if (pProxyReply->Status == CHTTPReply::ok) { if (pProxyReply->Status == CHTTPReply::ok) {
pServerReply->Content = pProxyReply->Content;
pProxyConnection->SendReply(pProxyReply->Status, nullptr, true); pProxyConnection->SendReply(pProxyReply->Status, nullptr, true);
} else { } else {
pProxyConnection->SendStockReply(pProxyReply->Status, true); pProxyConnection->SendStockReply(pProxyReply->Status, true);
@@ -1103,8 +1103,7 @@ namespace Apostol {
} }
if (Context.Status() >= Context::csInitialized) { if (Context.Status() >= Context::csInitialized) {
CheckProviders(Now, Context); CheckProviders(Context, Now);
FetchProviders(Now, Context);
} }
} }

View File

@@ -1053,8 +1053,7 @@ namespace Apostol {
} }
if (Context.Status() >= Context::csInitialized) { if (Context.Status() >= Context::csInitialized) {
CheckProviders(Now, Context); CheckProviders(Context, Now);
FetchProviders(Now, Context);
} }
} }