Added token update.

This commit is contained in:
Преподобный Ален
2022-11-01 00:57:06 +03:00
parent 94ffb25f8a
commit d99708838f
3 changed files with 122 additions and 22 deletions

View File

@@ -127,6 +127,16 @@ namespace Apostol {
}
pProxyConnection->SendReply(pProxyReply->Status, nullptr, true);
} else {
if (pProxyReply->Status == CHTTPReply::forbidden) {
const auto &caServerParam = pServerRequest->Params["server"];
const auto index = CurrentContextIndex(caServerParam);
auto &Context = index == -1 ? m_CurrentServer : m_Servers[index].Value();
Context.SetCheckDate(0);
Context.SetStatus(Context::csInitialized);
}
pServerReply->Content = pProxyReply->Content;
pProxyConnection->SendStockReply(pProxyReply->Status, true);
}
@@ -1079,15 +1089,17 @@ namespace Apostol {
DebugReply(pReply);
CString Content;
CString Code;
CString Key;
try {
JsonStringToKey(pReply->Content, Content);
JsonStringToKey(pReply->Content, Code, Key);
if (Content.IsEmpty())
if (Key.IsEmpty())
throw Delphi::Exception::Exception("Not found.");
const auto &name = pClient->Data()["name"];
auto &Keys = Context.PGP();
int index = 0;
@@ -1096,17 +1108,19 @@ namespace Apostol {
}
if (index < Keys.Count()) {
auto &Key = Keys[index];
auto &PGP = Keys[index];
Key.Status = CKeyContext::ksSuccess;
Key.StatusTime = Now();
Key.Key = Content;
PGP.Status = CKeyContext::ksSuccess;
PGP.StatusTime = Now();
PGP.Key = Key;
UpdateServerList(m_Servers, Content);
if (Code == "PUBLIC") {
UpdateServerList(m_Servers, Key);
Context.SetStatus(csRunning);
}
}
Context.SetStatus(csRunning);
} catch (Delphi::Exception::Exception &e) {
Context.SetStatus(Context::csAuthorized);
Log()->Error(APP_LOG_INFO, 0, "[FetchPGP] %s", e.what());
}