feat: add key upload function for module key server sync
This commit is contained in:
parent
99a5cb5ab5
commit
405522f3b0
@ -46,6 +46,7 @@ auto GFRegisterModule() -> int {
|
|||||||
auto GFActiveModule() -> int {
|
auto GFActiveModule() -> int {
|
||||||
LISTEN("REQUEST_GET_PUBLIC_KEY_BY_FINGERPRINT");
|
LISTEN("REQUEST_GET_PUBLIC_KEY_BY_FINGERPRINT");
|
||||||
LISTEN("REQUEST_GET_PUBLIC_KEY_BY_KEY_ID");
|
LISTEN("REQUEST_GET_PUBLIC_KEY_BY_KEY_ID");
|
||||||
|
LISTEN("REQUEST_UPLOAD_PUBLIC_KEY");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +125,45 @@ EXECUTE_MODULE() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event["event_id"] == "REQUEST_UPLOAD_PUBLIC_KEY") {
|
||||||
|
if (event["key_text"].isEmpty()) CB_ERR(event, -1, "key_text is empty");
|
||||||
|
|
||||||
|
QByteArray key_text = event["key_text"].toLatin1();
|
||||||
|
FLOG_DEBUG("try to get key info of key id: %1", key_text);
|
||||||
|
|
||||||
|
auto* vks = new VKSInterface();
|
||||||
|
vks->UploadKey(key_text);
|
||||||
|
QObject::connect(
|
||||||
|
vks, &VKSInterface::SignalKeyUploaded, QThread::currentThread(),
|
||||||
|
[event](const QString& fpr, const QJsonObject& status,
|
||||||
|
const QString& token) {
|
||||||
|
CB(event, GFGetModuleID(),
|
||||||
|
{
|
||||||
|
{"ret", QString::number(0)},
|
||||||
|
{"fingerprint", fpr},
|
||||||
|
{"status", QString::fromUtf8(QJsonDocument(status).toJson())},
|
||||||
|
{"token", token},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
QObject::connect(vks, &VKSInterface::SignalKeyRetrieved, vks,
|
||||||
|
&VKSInterface::deleteLater);
|
||||||
|
|
||||||
|
QObject::connect(vks, &VKSInterface::SignalErrorOccurred,
|
||||||
|
QThread::currentThread(),
|
||||||
|
[event](const QString& error, const QString& data) {
|
||||||
|
CB(event, GFGetModuleID(),
|
||||||
|
{
|
||||||
|
{"ret", QString::number(-1)},
|
||||||
|
{"error_msg", error},
|
||||||
|
{"reply_data", data},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
QObject::connect(vks, &VKSInterface::SignalKeyRetrieved, vks,
|
||||||
|
&VKSInterface::deleteLater);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
CB_SUCC(event);
|
CB_SUCC(event);
|
||||||
}
|
}
|
||||||
END_EXECUTE_MODULE()
|
END_EXECUTE_MODULE()
|
||||||
|
@ -127,7 +127,8 @@ void VKSInterface::on_reply_finished(QNetworkReply* reply) {
|
|||||||
if (json_response.isObject()) {
|
if (json_response.isObject()) {
|
||||||
QJsonObject response_object = json_response.object();
|
QJsonObject response_object = json_response.object();
|
||||||
emit SignalKeyUploaded(response_object["key_fpr"].toString(),
|
emit SignalKeyUploaded(response_object["key_fpr"].toString(),
|
||||||
response_object["status"].toObject());
|
response_object["status"].toObject(),
|
||||||
|
response_object["token"].toString());
|
||||||
}
|
}
|
||||||
} else if (url.path().contains("/vks/v1/request-verify")) {
|
} else if (url.path().contains("/vks/v1/request-verify")) {
|
||||||
if (json_response.isObject()) {
|
if (json_response.isObject()) {
|
||||||
|
@ -48,7 +48,7 @@ class VKSInterface : public QObject {
|
|||||||
signals:
|
signals:
|
||||||
void SignalKeyRetrieved(const QString& key);
|
void SignalKeyRetrieved(const QString& key);
|
||||||
void SignalKeyUploaded(const QString& key_fingerprint,
|
void SignalKeyUploaded(const QString& key_fingerprint,
|
||||||
const QJsonObject& status);
|
const QJsonObject& status, const QString& token);
|
||||||
void SignalVerificationRequested(const QString& key_fingerprint,
|
void SignalVerificationRequested(const QString& key_fingerprint,
|
||||||
const QJsonObject& status);
|
const QJsonObject& status);
|
||||||
void SignalErrorOccurred(const QString& error_string,
|
void SignalErrorOccurred(const QString& error_string,
|
||||||
|
Loading…
Reference in New Issue
Block a user