Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
修复了一处可能会泄漏的异常
Browse files Browse the repository at this point in the history
  • Loading branch information
skykeyjoker committed Apr 18, 2022
1 parent 031b7c7 commit 9b32bc6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 62 deletions.
46 changes: 20 additions & 26 deletions src/BilibiliMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ BiliBiliMessageRes BiliBiliMessage::messageQuery(const QString& url) {
* JSON_THROW(std::out_of_range("key not found"));
*/

if (doc.contains("data") && doc["data"].contains("cards")) {
try {
Json cardArr = doc["data"]["cards"];
int uid = cardArr[0]["desc"]["uid"].get<int>();
QString nickname = QString::fromStdString(cardArr[0]["desc"]["user_profile"]["info"]["uname"].get<std::string>());
Expand All @@ -121,32 +121,26 @@ BiliBiliMessageRes BiliBiliMessage::messageQuery(const QString& url) {
Json currentCardJson = cardArr[i];
BilibiliDynamicCard currentMessageCard;

try {
type = currentCardJson["desc"]["type"].get<int>();
dynamic_id_str = QString::fromStdString(currentCardJson["desc"]["dynamic_id_str"].get<std::string>());

currentMessageCard.uid = uid;
currentMessageCard.type = type;
currentMessageCard.dynamic_id_str = dynamic_id_str;
currentMessageCard.nickname = nickname;

qDebug() << "【哔哩哔哩】Message Query: " << currentMessageCard.uid << currentMessageCard.nickname << currentMessageCard.type << currentMessageCard.dynamic_id_str;
m_logger->info("【哔哩哔哩】动态消息卡片:UID:{},昵称:{},类型:{},动态ID:{}", currentMessageCard.uid, currentMessageCard.nickname.toStdString(), currentMessageCard.type, currentMessageCard.dynamic_id_str.toStdString());

res.push_back(currentMessageCard);
} catch (Json::exception& ex) {
qDebug() << "【哔哩哔哩】Message Query Error. Exception occurred when parsing the json. Exception:" << ex.what();
m_logger->error("【哔哩哔哩】查询成员动态时发生错误,解析获取的JSON时发生异常:{}", ex.what());
return res;
} catch (...) {
qDebug() << "【哔哩哔哩】Message Query Error. Unknown Exception occurred when parsing the json.";
m_logger->error("【哔哩哔哩】查询成员动态时发生错误,解析获取的JSON时发生未知异常");
return res;
}
type = currentCardJson["desc"]["type"].get<int>();
dynamic_id_str = QString::fromStdString(currentCardJson["desc"]["dynamic_id_str"].get<std::string>());

currentMessageCard.uid = uid;
currentMessageCard.type = type;
currentMessageCard.dynamic_id_str = dynamic_id_str;
currentMessageCard.nickname = nickname;

qDebug() << "【哔哩哔哩】Message Query: " << currentMessageCard.uid << currentMessageCard.nickname << currentMessageCard.type << currentMessageCard.dynamic_id_str;
m_logger->info("【哔哩哔哩】动态消息卡片:UID:{},昵称:{},类型:{},动态ID:{}", currentMessageCard.uid, currentMessageCard.nickname.toStdString(), currentMessageCard.type, currentMessageCard.dynamic_id_str.toStdString());

res.push_back(currentMessageCard);
}
} else {
qDebug() << "【哔哩哔哩】Message Query Error. Reason: The json can not be parsed. [data]or[cards] not exists.";
m_logger->error("【哔哩哔哩】查询成员动态时发生错误,未能解析获取的JSON,[data]或[cards]字段不存在。");
} catch (Json::exception& ex) {
qDebug() << "【哔哩哔哩】Message Query Error. Exception occurred when parsing the json. Exception:" << ex.what();
m_logger->error("【哔哩哔哩】查询成员动态时发生错误,解析获取的JSON时发生异常:{}", ex.what());
return res;
} catch (...) {
qDebug() << "【哔哩哔哩】Message Query Error. Unknown Exception occurred when parsing the json.";
m_logger->error("【哔哩哔哩】查询成员动态时发生错误,解析获取的JSON时发生未知异常");
return res;
}

Expand Down
63 changes: 28 additions & 35 deletions src/DouyinMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ DouyinDynamicRes DouyinMessage::dynamicQuery(const QString &url) {
/* []操作符理应有异常机制,对异常机制进行处理
* JSON_THROW(std::out_of_range("key not found"));
*/

if (doc.contains("aweme_list")) {
try {
Json aweme_list = doc["aweme_list"];

QString uid = QString::fromStdString(aweme_list[0]["author"]["unique_id"].get<std::string>());
Expand All @@ -109,40 +108,34 @@ DouyinDynamicRes DouyinMessage::dynamicQuery(const QString &url) {
Json currentDynamicCardJson = aweme_list[i];
DouyinDynamicCard currentDynamicCard;

try {
type = currentDynamicCardJson["aweme_type"].get<int>();
aweme_id = QString::fromStdString(currentDynamicCardJson["aweme_id"].get<std::string>());
desc = QString::fromStdString(currentDynamicCardJson["desc"].get<std::string>());

currentDynamicCard.uid = uid;
currentDynamicCard.type = type;
currentDynamicCard.aweme_id = aweme_id;
currentDynamicCard.nickname = nickname;
currentDynamicCard.desc = desc;

qDebug() << "【抖音】Message Query: " << currentDynamicCard.uid << currentDynamicCard.nickname
<< currentDynamicCard.type << currentDynamicCard.aweme_id << currentDynamicCard.desc;
m_logger->info("【抖音】动态消息卡片:UID:{},昵称:{},类型:{},动态ID:{},标题:{}",
currentDynamicCard.uid.toStdString(),
currentDynamicCard.nickname.toStdString(),
currentDynamicCard.type,
currentDynamicCard.aweme_id.toStdString(),
currentDynamicCard.desc.toStdString());

res.push_back(currentDynamicCard);
} catch (Json::exception &ex) {
qDebug() << "【抖音】Message Query Error. Exception occurred when parsing the json. Exception:{}" << ex.what();
m_logger->error("【抖音】查询成员动态时发生错误,解析获取的JSON时发生异常:{}", ex.what());
return res;
} catch (...) {
qDebug() << "【抖音】Message Query Error. Unknown exception occurred when parsing the json.";
m_logger->error("【抖音】铲鲟成员动态时发生错误,解析获取的JSON时发生未知异常");
return res;
}
type = currentDynamicCardJson["aweme_type"].get<int>();
aweme_id = QString::fromStdString(currentDynamicCardJson["aweme_id"].get<std::string>());
desc = QString::fromStdString(currentDynamicCardJson["desc"].get<std::string>());

currentDynamicCard.uid = uid;
currentDynamicCard.type = type;
currentDynamicCard.aweme_id = aweme_id;
currentDynamicCard.nickname = nickname;
currentDynamicCard.desc = desc;

qDebug() << "【抖音】Message Query: " << currentDynamicCard.uid << currentDynamicCard.nickname
<< currentDynamicCard.type << currentDynamicCard.aweme_id << currentDynamicCard.desc;
m_logger->info("【抖音】动态消息卡片:UID:{},昵称:{},类型:{},动态ID:{},标题:{}",
currentDynamicCard.uid.toStdString(),
currentDynamicCard.nickname.toStdString(),
currentDynamicCard.type,
currentDynamicCard.aweme_id.toStdString(),
currentDynamicCard.desc.toStdString());

res.push_back(currentDynamicCard);
}
} else {
qDebug() << "【抖音】Message Query Error. Reason: The json can not be parsed. [aweme_list] not exists.";
m_logger->error("【抖音】查询成员动态时发生错误,未能解析获取的JSON,[aweme_list]段不存在。");
} catch (Json::exception &ex) {
qDebug() << "【抖音】Message Query Error. Exception occurred when parsing the json. Exception:{}" << ex.what();
m_logger->error("【抖音】查询成员动态时发生错误,解析获取的JSON时发生异常:{}", ex.what());
return res;
} catch (...) {
qDebug() << "【抖音】Message Query Error. Unknown exception occurred when parsing the json.";
m_logger->error("【抖音】查询成员动态时发生错误,解析获取的JSON时发生未知异常");
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Essential.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <QString>
#include <QStringList>

const QString VERSION = "3.1.0";
const QString VERSION = "3.2.0";

const QString BDYNAMICQUERY("https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=");
const QString BLIVEQUERY("https://api.bilibili.com/x/space/acc/info?mid=");
Expand Down
30 changes: 30 additions & 0 deletions src/member.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,36 @@
"sec_uid": "MS4wLjABAAAAflgvVQ5O1K4RfgUu3k0A2erAZSK7RsdiqPAvxcObn93x2vk4SKk1eUb6l_D4MX-n",
"nickname": "五个魂儿呀",
"avatar": "ASOULofficial.jpg"
},
{
"uid": "ASOULxiangwan",
"sec_uid": "MS4wLjABAAAAxOXMMwlShWjp4DONMwfEEfloRYiC1rXwQ64eydoZ0ORPFVGysZEd4zMt8AjsTbyt",
"nickname": "向晚",
"avatar": "ava.jpg"
},
{
"uid": "ASOULbeila",
"sec_uid": "MS4wLjABAAAAlpnJ0bXVDV6BNgbHUYVWnnIagRqeeZyNyXB84JXTqAS5tgGjAtw0ZZkv0KSHYyhP",
"nickname": "贝拉",
"avatar": "bella.jpg"
},
{
"uid": "ASOULjiale",
"sec_uid": "MS4wLjABAAAAuZHC7vwqRhPzdeTb24HS7So91u9ucl9c8JjpOS2CPK-9Kg2D32Sj7-mZYvUCJCya",
"nickname": "珈乐",
"avatar": "carol.jpg"
},
{
"uid": "ASOULjiaran",
"sec_uid": "MS4wLjABAAAA5ZrIrbgva_HMeHuNn64goOD2XYnk4ItSypgRHlbSh1c",
"nickname": "嘉然",
"avatar": "diana.jpg"
},
{
"uid": "ASOULnailin",
"sec_uid": "MS4wLjABAAAAxCiIYlaaKaMz_J1QaIAmHGgc3bTerIpgTzZjm0na8w5t2KTPrCz4bm_5M5EMPy92",
"nickname": "乃琳",
"avatar": "eileen.jpg"
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"versions": [
{
"version": "v3.2.0",
"url": "https://github.com/skykeyjoker/A-Soul-Notification/releases/tag/v3.2.0"
},
{
"version": "v3.1.0",
"url": "https://github.com/skykeyjoker/A-Soul-Notification/releases/tag/v3.1.0"
Expand Down

0 comments on commit 9b32bc6

Please sign in to comment.