From b1dd8cbf7189b702ec35fb08694e7b4844a3194b Mon Sep 17 00:00:00 2001 From: maksis Date: Tue, 19 Jan 2016 12:13:47 +0200 Subject: [PATCH] Squashed 'airdcpp-webapi/' changes from 37374d6..69a499b 69a499b Prevent queuing the same file for viewing multiple times 4bb96f6 API: don't showm message spam in console 20f5ffe ListViewController: use stable sort, insert new items at the end of the equal item range git-subtree-dir: airdcpp-webapi git-subtree-split: 69a499ba0934a278fbe0499cffbd3ca6434b8a87 --- api/HubInfo.cpp | 2 +- api/HubInfo.h | 2 +- api/QueueApi.cpp | 10 ++-------- api/QueueApi.h | 4 ++-- api/ViewFileApi.cpp | 13 +++++++------ api/common/ListViewController.h | 4 ++-- web-server/WebServerManager.cpp | 2 +- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/api/HubInfo.cpp b/api/HubInfo.cpp index f751f3ac..e26082d7 100644 --- a/api/HubInfo.cpp +++ b/api/HubInfo.cpp @@ -255,7 +255,7 @@ namespace webserver { }); } - void HubInfo::onUserUpdated(const OnlineUserPtr& aUser, PropertyIdSet aUpdatedProperties) noexcept { + void HubInfo::onUserUpdated(const OnlineUserPtr& aUser, const PropertyIdSet& aUpdatedProperties) noexcept { if (!aUser->isHidden()) { view.onItemUpdated(aUser, aUpdatedProperties); } diff --git a/api/HubInfo.h b/api/HubInfo.h index f3d3d2a3..4037bdf7 100644 --- a/api/HubInfo.h +++ b/api/HubInfo.h @@ -119,7 +119,7 @@ namespace webserver { OnlineUserList getUsers() noexcept; void onUserUpdated(const OnlineUserPtr& ou) noexcept; - void onUserUpdated(const OnlineUserPtr& ou, PropertyIdSet aUpdatedProperties) noexcept; + void onUserUpdated(const OnlineUserPtr& ou, const PropertyIdSet& aUpdatedProperties) noexcept; void onFlagsUpdated(const UserPtr& aUser) noexcept; json previousCounts; diff --git a/api/QueueApi.cpp b/api/QueueApi.cpp index 3e435b01..15ec351e 100644 --- a/api/QueueApi.cpp +++ b/api/QueueApi.cpp @@ -272,19 +272,13 @@ namespace webserver { QueueManager::getInstance()->setBundlePriority(b, Deserializer::deserializePriority(reqJson, false)); } - // Target - //auto target = reqJson.find("target"); - //if (target != reqJson.end()) { - // QueueManager::getInstance()->moveBundle(b, *target, true); - //} - return websocketpp::http::status_code::ok; } // TEMP ITEMS - api_return QueueApi::handleAddTempItem(ApiRequest& aRequest) { + /*api_return QueueApi::handleAddTempItem(ApiRequest& aRequest) { const auto& reqJson = aRequest.getRequestBody(); try { @@ -324,7 +318,7 @@ namespace webserver { } return websocketpp::http::status_code::ok; - } + }*/ // FILES (COMMON) diff --git a/api/QueueApi.h b/api/QueueApi.h index 483b796c..f01ab5b0 100644 --- a/api/QueueApi.h +++ b/api/QueueApi.h @@ -102,8 +102,8 @@ namespace webserver { api_return handleGetBundle(ApiRequest& aRequest); - api_return handleAddFilelist(ApiRequest& aRequest); - api_return handleAddTempItem(ApiRequest& aRequest); + //api_return handleAddFilelist(ApiRequest& aRequest); + //api_return handleAddTempItem(ApiRequest& aRequest); api_return handleAddDirectoryBundle(ApiRequest& aRequest); api_return handleAddFileBundle(ApiRequest& aRequest); diff --git a/api/ViewFileApi.cpp b/api/ViewFileApi.cpp index abe2048d..fab30664 100644 --- a/api/ViewFileApi.cpp +++ b/api/ViewFileApi.cpp @@ -81,23 +81,24 @@ namespace webserver { const auto& j = aRequest.getRequestBody(); auto tth = Deserializer::deserializeTTH(j); - if (ViewFileManager::getInstance()->getFile(tth)) { - aRequest.setResponseErrorStr("File with the same TTH is open already"); - return websocketpp::http::status_code::bad_request; - } - auto name = JsonUtil::getField("name", j, false); auto size = JsonUtil::getField("size", j); auto user = Deserializer::deserializeHintedUser(j); auto isText = JsonUtil::getOptionalFieldDefault("text", j, false); + bool added = false; try { - QueueManager::getInstance()->addOpenedItem(name, size, tth, user, true, isText); + added = ViewFileManager::getInstance()->addFileThrow(name, size, tth, user, isText); } catch (const Exception& e) { aRequest.setResponseErrorStr(e.getError()); return websocketpp::http::status_code::internal_server_error; } + if (!added) { + aRequest.setResponseErrorStr("File with the same TTH is open already"); + return websocketpp::http::status_code::bad_request; + } + return websocketpp::http::status_code::ok; } diff --git a/api/common/ListViewController.h b/api/common/ListViewController.h index d711c893..48b4e8d3 100644 --- a/api/common/ListViewController.h +++ b/api/common/ListViewController.h @@ -677,7 +677,7 @@ namespace webserver { auto start = GET_TICK(); WLock l(cs); - std::sort(matchingItems.begin(), matchingItems.end(), + std::stable_sort(matchingItems.begin(), matchingItems.end(), std::bind(&ListViewController::itemSort, std::placeholders::_1, std::placeholders::_2, @@ -716,7 +716,7 @@ namespace webserver { WLock l(cs); allItems.emplace(aItem); if (matches) { - auto iter = matchingItems.insert(std::lower_bound( + auto iter = matchingItems.insert(std::upper_bound( matchingItems.begin(), matchingItems.end(), aItem, diff --git a/web-server/WebServerManager.cpp b/web-server/WebServerManager.cpp index e63931ca..66781d50 100644 --- a/web-server/WebServerManager.cpp +++ b/web-server/WebServerManager.cpp @@ -82,7 +82,7 @@ namespace webserver { void setEndpointLogSettings(T& aEndpoint, std::ostream& aStream) { // Access aEndpoint.set_access_channels(websocketpp::log::alevel::all); - //aEndpoint.clear_access_channels(websocketpp::log::alevel::frame_payload | websocketpp::log::alevel::message_payload); + aEndpoint.clear_access_channels(websocketpp::log::alevel::frame_payload | websocketpp::log::alevel::frame_header); aEndpoint.get_alog().set_ostream(&aStream); // Errors