fix: 优化客户端错误提示和校验诊断信息
This commit is contained in:
+52
-32
@@ -104,11 +104,13 @@ void UpdateLogic::getDownloadUrl(const QString& appId, const QString& channel, c
|
||||
bool UpdateLogic::cacheManifest(const QString& appId, const QString& channel, const QString& version,
|
||||
int versionId, const QString& cacheDir)
|
||||
{
|
||||
m_error.clear();
|
||||
if (appId.isEmpty() || channel.isEmpty() || version.isEmpty() || versionId <= 0) {
|
||||
m_error = "manifest identity is incomplete";
|
||||
return false;
|
||||
}
|
||||
m_error.clear();
|
||||
if (appId.isEmpty() || channel.isEmpty() || version.isEmpty() || versionId <= 0) {
|
||||
m_error = QCoreApplication::translate("UpdateLogic",
|
||||
"Current version manifest identity is incomplete. Stage: cache current version manifest. App: %1, channel: %2, version: %3, version id: %4.")
|
||||
.arg(appId, channel, version, QString::number(versionId));
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonObject response;
|
||||
int statusCode = 0;
|
||||
@@ -122,40 +124,58 @@ bool UpdateLogic::cacheManifest(const QString& appId, const QString& channel, co
|
||||
statusCode = code;
|
||||
response = resp;
|
||||
});
|
||||
|
||||
if (statusCode != 200) {
|
||||
const QJsonValue detail = response.value(QStringLiteral("detail"));
|
||||
const QString message = detail.isObject()
|
||||
? detail.toObject().value(QStringLiteral("msg")).toString()
|
||||
: detail.toString();
|
||||
m_error = QCoreApplication::translate("UpdateLogic",
|
||||
"Cannot download signed manifest for the current local version. Stage: cache current version manifest. HTTP status: %1. App: %2, channel: %3, version: %4, version id: %5.%6")
|
||||
.arg(QString::number(statusCode), appId, channel, version, QString::number(versionId),
|
||||
message.isEmpty() ? QString() : QCoreApplication::translate("UpdateLogic", "\nServer message: %1").arg(message));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (statusCode != 200) {
|
||||
m_error = QString("manifest request failed (HTTP %1)").arg(statusCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
const QJsonObject manifest = response.value("manifest").toObject();
|
||||
const QString manifestText = response.value("manifest_text").toString();
|
||||
if (manifest.isEmpty() || manifestText.isEmpty()) {
|
||||
m_error = "manifest response is incomplete";
|
||||
return false;
|
||||
}
|
||||
const QJsonObject manifest = response.value("manifest").toObject();
|
||||
const QString manifestText = response.value("manifest_text").toString();
|
||||
if (manifest.isEmpty() || manifestText.isEmpty()) {
|
||||
m_error = QCoreApplication::translate("UpdateLogic",
|
||||
"The signed manifest response for the current local version is incomplete. Stage: cache current version manifest. App: %1, channel: %2, version: %3, version id: %4.")
|
||||
.arg(appId, channel, version, QString::number(versionId));
|
||||
return false;
|
||||
}
|
||||
if (manifest.value("app_id").toString() != appId
|
||||
|| manifest.value("channel").toString() != channel
|
||||
|| manifest.value("version").toString() != version) {
|
||||
m_error = "manifest identity does not match current version";
|
||||
return false;
|
||||
}
|
||||
|| manifest.value("channel").toString() != channel
|
||||
|| manifest.value("version").toString() != version) {
|
||||
m_error = QCoreApplication::translate("UpdateLogic",
|
||||
"The signed manifest identity does not match the current local version. Stage: cache current version manifest. Expected app/channel/version: %1 / %2 / %3. Manifest app/channel/version: %4 / %5 / %6.")
|
||||
.arg(appId, channel, version,
|
||||
manifest.value("app_id").toString(),
|
||||
manifest.value("channel").toString(),
|
||||
manifest.value("version").toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
QDir dir(cacheDir);
|
||||
if (!dir.exists() && !dir.mkpath(".")) {
|
||||
m_error = "cannot create manifest cache directory";
|
||||
return false;
|
||||
}
|
||||
QDir dir(cacheDir);
|
||||
if (!dir.exists() && !dir.mkpath(".")) {
|
||||
m_error = QCoreApplication::translate("UpdateLogic",
|
||||
"Cannot create manifest cache directory. Stage: cache current version manifest. Directory: %1.")
|
||||
.arg(cacheDir);
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonObject wrapper;
|
||||
wrapper["manifest"] = manifest;
|
||||
wrapper["manifest_text"] = manifestText;
|
||||
QSaveFile file(dir.filePath("manifest_" + version + ".json"));
|
||||
const QByteArray bytes = QJsonDocument(wrapper).toJson(QJsonDocument::Indented);
|
||||
if (!file.open(QIODevice::WriteOnly) || file.write(bytes) != bytes.size() || !file.commit()) {
|
||||
m_error = "cannot save signed manifest cache";
|
||||
return false;
|
||||
}
|
||||
QSaveFile file(dir.filePath("manifest_" + version + ".json"));
|
||||
const QByteArray bytes = QJsonDocument(wrapper).toJson(QJsonDocument::Indented);
|
||||
if (!file.open(QIODevice::WriteOnly) || file.write(bytes) != bytes.size() || !file.commit()) {
|
||||
m_error = QCoreApplication::translate("UpdateLogic",
|
||||
"Cannot save signed manifest cache. Stage: cache current version manifest. File: %1. Error: %2.")
|
||||
.arg(file.fileName(), file.errorString());
|
||||
return false;
|
||||
}
|
||||
qDebug() << "Current version manifest cached to" << file.fileName();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user