Skip to content

Commit

Permalink
Merge commit 'b4f7e2e446dbc9775eb34b5b873a9ab877043f9e' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
maksis committed Sep 5, 2024
2 parents 405e14f + b4f7e2e commit c26771b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 47 deletions.
3 changes: 1 addition & 2 deletions airdcpp-webapi/api/QueueBundleUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <api/common/Format.h>
#include <api/common/Serializer.h>

#include <airdcpp/AirUtil.h>
#include <airdcpp/Bundle.h>
#include <airdcpp/PathUtil.h>
#include <airdcpp/QueueItem.h>
Expand Down Expand Up @@ -60,7 +59,7 @@ namespace webserver {
case PROP_TARGET: return b->getTarget();
case PROP_TYPE: return formatBundleType(b);
case PROP_STATUS: return b->getStatusString();
case PROP_PRIORITY: return AirUtil::getPrioText(b->getPriority());
case PROP_PRIORITY: return Util::formatPriority(b->getPriority());
case PROP_SOURCES: return formatBundleSources(b);
default: dcassert(0); return Util::emptyString;
}
Expand Down
3 changes: 1 addition & 2 deletions airdcpp-webapi/api/QueueFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <api/common/Format.h>
#include <api/common/Serializer.h>

#include <airdcpp/AirUtil.h>
#include <airdcpp/Bundle.h>
#include <airdcpp/PathUtil.h>
#include <airdcpp/QueueItem.h>
Expand Down Expand Up @@ -66,7 +65,7 @@ namespace webserver {
case PROP_TARGET: return aItem->getTarget();
case PROP_TYPE: return Util::formatFileType(aItem->getTarget());
case PROP_STATUS: return formatDisplayStatus(aItem);
case PROP_PRIORITY: return AirUtil::getPrioText(aItem->getPriority());
case PROP_PRIORITY: return Util::formatPriority(aItem->getPriority());
case PROP_SOURCES: return formatFileSources(aItem);
case PROP_TTH: return aItem->getTTH().toBase32();
default: dcassert(0); return Util::emptyString;
Expand Down
20 changes: 11 additions & 9 deletions airdcpp-webapi/api/ShareApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <airdcpp/ShareManager.h>
#include <airdcpp/SharePathValidator.h>
#include <airdcpp/StringTokenizer.h>
#include <airdcpp/TempShareManager.h>
#include <airdcpp/ValueGenerator.h>

namespace webserver {
Expand Down Expand Up @@ -205,12 +206,12 @@ namespace webserver {
int64_t totalSize = 0;
aDirectory->getContentInfo(totalSize, contentInfo);

auto realPath = aDirectory->getRealPath();
auto realPath = aDirectory->getRealPathUnsafe();
return {
{ "id", ValueGenerator::generatePathId(realPath) },
{ "name", aDirectory->getRealName().getNormal() },
{ "path", realPath },
{ "virtual_path", aDirectory->getAdcPath() },
{ "virtual_path", aDirectory->getAdcPathUnsafe() },
{ "size", totalSize },
{ "tth", Util::emptyString },
{ "time", aDirectory->getLastWrite() },
Expand Down Expand Up @@ -299,8 +300,9 @@ namespace webserver {

{
unique_ptr<SearchQuery> matcher(SearchQuery::getSearch(s));
ShareSearch search(*matcher, profile, nullptr, s->path);
try {
ShareManager::getInstance()->search(results, *matcher, profile, nullptr, s->path);
ShareManager::getInstance()->search(results, search);
} catch (...) {}
}

Expand Down Expand Up @@ -389,7 +391,7 @@ namespace webserver {
}

auto shareProfileToken = optionalClient ? optionalClient->get(HubSettings::ShareProfile) : SETTING(DEFAULT_SP);
auto item = ShareManager::getInstance()->addTempShare(tth, name, filePath, size, shareProfileToken, user);
auto item = TempShareManager::getInstance()->addTempShare(tth, name, filePath, size, shareProfileToken, user);

aRequest.setResponseBody({
{ "magnet", Magnet::makeMagnet(tth, name, size) },
Expand All @@ -401,7 +403,7 @@ namespace webserver {

api_return ShareApi::handleRemoveTempShare(ApiRequest& aRequest) {
auto token = aRequest.getTokenParam();
if (!ShareManager::getInstance()->removeTempShare(token)) {
if (!TempShareManager::getInstance()->removeTempShare(token)) {
aRequest.setResponseErrorStr("Temp share item " + Util::toString(token) + " was not found");
return websocketpp::http::status_code::bad_request;
}
Expand All @@ -413,7 +415,7 @@ namespace webserver {
return {
{ "id", aInfo.id },
{ "name", aInfo.name },
{ "path", aInfo.path },
{ "path", aInfo.realPath },
{ "size", aInfo.size },
{ "tth", aInfo.tth.toBase32() },
{ "time_added", aInfo.timeAdded },
Expand All @@ -423,7 +425,7 @@ namespace webserver {
}

api_return ShareApi::handleGetTempShares(ApiRequest& aRequest) {
const auto tempShares = ShareManager::getInstance()->getTempShares();
const auto tempShares = TempShareManager::getInstance()->getTempShares();

aRequest.setResponseBody(Serializer::serializeList(tempShares, serializeTempShare));
return websocketpp::http::status_code::ok;
Expand Down Expand Up @@ -469,13 +471,13 @@ namespace webserver {
}


void ShareApi::on(ShareManagerListener::TempFileAdded, const TempShareInfo& aFile) noexcept {
void ShareApi::on(TempShareManagerListener::TempFileAdded, const TempShareInfo& aFile) noexcept {
maybeSend("share_temp_item_added", [&] {
return serializeTempShare(aFile);
});
}

void ShareApi::on(ShareManagerListener::TempFileRemoved, const TempShareInfo& aFile) noexcept {
void ShareApi::on(TempShareManagerListener::TempFileRemoved, const TempShareInfo& aFile) noexcept {
maybeSend("share_temp_item_removed", [&] {
return serializeTempShare(aFile);
});
Expand Down
7 changes: 4 additions & 3 deletions airdcpp-webapi/api/ShareApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
#include <airdcpp/typedefs.h>
#include <airdcpp/ShareDirectory.h>
#include <airdcpp/ShareManagerListener.h>
#include <airdcpp/TempShareManagerListener.h>
#include <airdcpp/ShareRefreshTask.h>

namespace webserver {
class ShareApi : public HookApiModule, private ShareManagerListener {
class ShareApi : public HookApiModule, private ShareManagerListener, private TempShareManagerListener {
public:
ShareApi(Session* aSession);
~ShareApi();
Expand Down Expand Up @@ -87,8 +88,8 @@ namespace webserver {
void on(ShareManagerListener::ExcludeAdded, const string& aPath) noexcept override;
void on(ShareManagerListener::ExcludeRemoved, const string& aPath) noexcept override;

void on(ShareManagerListener::TempFileAdded, const TempShareInfo& aFile) noexcept override;
void on(ShareManagerListener::TempFileRemoved, const TempShareInfo& aFile) noexcept override;
void on(TempShareManagerListener::TempFileAdded, const TempShareInfo& aFile) noexcept override;
void on(TempShareManagerListener::TempFileRemoved, const TempShareInfo& aFile) noexcept override;

static string refreshTypeToString(ShareRefreshType aType) noexcept;

Expand Down
34 changes: 18 additions & 16 deletions airdcpp-webapi/api/ShareProfileApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <web-server/JsonUtil.h>

#include <airdcpp/ShareManager.h>
#include <airdcpp/ShareProfileManager.h>

namespace webserver {
ShareProfileApi::ShareProfileApi(Session* aSession) :
Expand All @@ -35,7 +36,8 @@ namespace webserver {
"share_profile_updated",
"share_profile_removed"
}
)
),
mgr(ShareManager::getInstance()->getProfileMgr())
{
METHOD_HANDLER(Access::ANY, METHOD_GET, (), ShareProfileApi::handleGetProfiles);

Expand All @@ -47,11 +49,11 @@ namespace webserver {
METHOD_HANDLER(Access::SETTINGS_EDIT, METHOD_DELETE, (TOKEN_PARAM), ShareProfileApi::handleRemoveProfile);
METHOD_HANDLER(Access::SETTINGS_EDIT, METHOD_POST, (TOKEN_PARAM, EXACT_PARAM("default")), ShareProfileApi::handleSetDefaultProfile);

ShareManager::getInstance()->addListener(this);
mgr.addListener(this);
}

ShareProfileApi::~ShareProfileApi() {
ShareManager::getInstance()->removeListener(this);
mgr.removeListener(this);
}

json ShareProfileApi::serializeShareProfile(const ShareProfilePtr& aProfile) noexcept {
Expand All @@ -71,7 +73,7 @@ namespace webserver {

ShareProfilePtr ShareProfileApi::parseProfileToken(ApiRequest& aRequest, bool aAllowHidden) {
auto profileId = aRequest.getTokenParam();
auto profile = ShareManager::getInstance()->getShareProfile(profileId);
auto profile = mgr.getShareProfile(profileId);
if (!profile) {
throw RequestException(websocketpp::http::status_code::not_found, "Share profile " + Util::toString(profileId) + " was not found");
}
Expand All @@ -90,7 +92,7 @@ namespace webserver {
}

api_return ShareProfileApi::handleGetDefaultProfile(ApiRequest& aRequest) {
auto profile = ShareManager::getInstance()->getShareProfile(SETTING(DEFAULT_SP));
auto profile = mgr.getShareProfile(SETTING(DEFAULT_SP));
if (!profile) {
return websocketpp::http::status_code::internal_server_error;
}
Expand All @@ -102,28 +104,28 @@ namespace webserver {
api_return ShareProfileApi::handleSetDefaultProfile(ApiRequest& aRequest) {
auto profile = parseProfileToken(aRequest, true);

ShareManager::getInstance()->setDefaultProfile(profile->getToken());
mgr.setDefaultProfile(profile->getToken());
return websocketpp::http::status_code::no_content;
}

void ShareProfileApi::on(ShareManagerListener::ProfileAdded, ProfileToken aProfile) noexcept {
void ShareProfileApi::on(ShareProfileManagerListener::ProfileAdded, ProfileToken aProfile) noexcept {
maybeSend("share_profile_added", [&] {
return serializeShareProfile(ShareManager::getInstance()->getShareProfile(aProfile));
return serializeShareProfile(mgr.getShareProfile(aProfile));
});
}

void ShareProfileApi::on(ShareManagerListener::ProfileUpdated, ProfileToken aProfile, bool aIsMajorChange) noexcept {
void ShareProfileApi::on(ShareProfileManagerListener::ProfileUpdated, ProfileToken aProfile, bool aIsMajorChange) noexcept {
if (!aIsMajorChange) {
// Don't spam when files are hashed
return;
}

maybeSend("share_profile_updated", [&] {
return serializeShareProfile(ShareManager::getInstance()->getShareProfile(aProfile));
return serializeShareProfile(mgr.getShareProfile(aProfile));
});
}

void ShareProfileApi::on(ShareManagerListener::ProfileRemoved, ProfileToken aProfile) noexcept {
void ShareProfileApi::on(ShareProfileManagerListener::ProfileRemoved, ProfileToken aProfile) noexcept {
maybeSend("share_profile_removed", [&] {
return json({ "id", aProfile });
});
Expand All @@ -132,7 +134,7 @@ namespace webserver {
void ShareProfileApi::updateProfileProperties(ShareProfilePtr& aProfile, const json& j) {
auto name = JsonUtil::getField<string>("name", j, false);

auto token = ShareManager::getInstance()->getProfileByName(name);
auto token = mgr.getProfileByName(name);
if (token && token != aProfile->getToken()) {
JsonUtil::throwError("name", JsonUtil::ERROR_EXISTS, "Profile with the same name exists");
}
Expand All @@ -146,7 +148,7 @@ namespace webserver {
auto profile = std::make_shared<ShareProfile>();
updateProfileProperties(profile, reqJson);

ShareManager::getInstance()->addProfile(profile);
mgr.addProfile(profile);

aRequest.setResponseBody(serializeShareProfile(profile));
return websocketpp::http::status_code::ok;
Expand All @@ -158,7 +160,7 @@ namespace webserver {
auto profile = parseProfileToken(aRequest, false);

updateProfileProperties(profile, reqJson);
ShareManager::getInstance()->updateProfile(profile);
mgr.updateProfile(profile);

aRequest.setResponseBody(serializeShareProfile(profile));
return websocketpp::http::status_code::ok;
Expand All @@ -171,12 +173,12 @@ namespace webserver {
return websocketpp::http::status_code::bad_request;
}

ShareManager::getInstance()->removeProfile(profile->getToken());
mgr.removeProfile(profile->getToken());
return websocketpp::http::status_code::no_content;
}

api_return ShareProfileApi::handleGetProfiles(ApiRequest& aRequest) {
auto profiles = ShareManager::getInstance()->getProfiles();
auto profiles = mgr.getProfiles();

auto j = Serializer::serializeList(profiles, serializeShareProfile);
aRequest.setResponseBody(j);
Expand Down
16 changes: 11 additions & 5 deletions airdcpp-webapi/api/ShareProfileApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
#include <api/base/ApiModule.h>

#include <airdcpp/typedefs.h>
#include <airdcpp/ShareManagerListener.h>
#include <airdcpp/ShareProfileManagerListener.h>

namespace dcpp {
class ShareProfileManager;
}

namespace webserver {
class ShareProfileApi : public SubscribableApiModule, private ShareManagerListener {
class ShareProfileApi : public SubscribableApiModule, private ShareProfileManagerListener {
public:
ShareProfileApi(Session* aSession);
~ShareProfileApi();
Expand All @@ -44,11 +48,13 @@ namespace webserver {

void updateProfileProperties(ShareProfilePtr& aProfile, const json& j);

void on(ShareManagerListener::ProfileAdded, ProfileToken aProfile) noexcept override;
void on(ShareManagerListener::ProfileUpdated, ProfileToken aProfile, bool aIsMajorChange) noexcept override;
void on(ShareManagerListener::ProfileRemoved, ProfileToken aProfile) noexcept override;
void on(ShareProfileManagerListener::ProfileAdded, ProfileToken aProfile) noexcept override;
void on(ShareProfileManagerListener::ProfileUpdated, ProfileToken aProfile, bool aIsMajorChange) noexcept override;
void on(ShareProfileManagerListener::ProfileRemoved, ProfileToken aProfile) noexcept override;

ShareProfilePtr parseProfileToken(ApiRequest& aRequest, bool aAllowHidden);

ShareProfileManager& mgr;
};
}

Expand Down
4 changes: 2 additions & 2 deletions airdcpp-webapi/api/common/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <web-server/WebUser.h>

#include <airdcpp/AirUtil.h>
#include <airdcpp/Bundle.h>
#include <airdcpp/Client.h>
#include <airdcpp/ClientManager.h>
Expand All @@ -40,6 +39,7 @@
#include <airdcpp/SearchResult.h>
#include <airdcpp/SearchTypes.h>
#include <airdcpp/ShareManager.h>
#include <airdcpp/ShareProfile.h>

namespace webserver {
// USERS
Expand Down Expand Up @@ -365,7 +365,7 @@ namespace webserver {
json Serializer::serializePriority(const QueueItemBase& aItem) noexcept {
return {
{ "id", serializePriorityId(aItem.getPriority()) },
{ "str", AirUtil::getPrioText(aItem.getPriority()) },
{ "str", Util::formatPriority(aItem.getPriority()) },
{ "auto", aItem.getAutoPriority() }
};
}
Expand Down
16 changes: 8 additions & 8 deletions airdcpp-webapi/web-server/ApiSettingItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <web-server/ApiSettingItem.h>
#include <web-server/JsonUtil.h>

#include <airdcpp/AirUtil.h>
#include <airdcpp/AutoLimitUtil.h>
#include <airdcpp/ConnectionManager.h>
#include <airdcpp/ConnectivityManager.h>
#include <airdcpp/Localization.h>
Expand Down Expand Up @@ -330,15 +330,15 @@ namespace webserver {
case SettingsManager::IP_UPDATE6:
case SettingsManager::NO_IP_OVERRIDE6: return ConnectivityManager::getInstance()->get(static_cast<SettingsManager::BoolSetting>(si.key));

case SettingsManager::DOWNLOAD_SLOTS: return AirUtil::getSlots(true, Util::toDouble(SETTING(DOWNLOAD_SPEED)));
case SettingsManager::MAX_DOWNLOAD_SPEED: return AirUtil::getSpeedLimitKbps(true, Util::toDouble(SETTING(DOWNLOAD_SPEED)));
case SettingsManager::DOWNLOAD_SLOTS: return AutoLimitUtil::getSlots(true, Util::toDouble(SETTING(DOWNLOAD_SPEED)));
case SettingsManager::MAX_DOWNLOAD_SPEED: return AutoLimitUtil::getSpeedLimitKbps(true, Util::toDouble(SETTING(DOWNLOAD_SPEED)));

case SettingsManager::UPLOAD_SLOTS: return AirUtil::getSlots(false, Util::toDouble(SETTING(UPLOAD_SPEED)));
case SettingsManager::MIN_UPLOAD_SPEED: return AirUtil::getSpeedLimitKbps(false, Util::toDouble(SETTING(UPLOAD_SPEED)));
case SettingsManager::AUTO_SLOTS: return AirUtil::getMaxAutoOpened(Util::toDouble(SETTING(UPLOAD_SPEED)));
case SettingsManager::UPLOAD_SLOTS: return AutoLimitUtil::getSlots(false, Util::toDouble(SETTING(UPLOAD_SPEED)));
case SettingsManager::MIN_UPLOAD_SPEED: return AutoLimitUtil::getSpeedLimitKbps(false, Util::toDouble(SETTING(UPLOAD_SPEED)));
case SettingsManager::AUTO_SLOTS: return AutoLimitUtil::getMaxAutoOpened(Util::toDouble(SETTING(UPLOAD_SPEED)));

case SettingsManager::MAX_MCN_DOWNLOADS: return AirUtil::getSlotsPerUser(true, Util::toDouble(SETTING(DOWNLOAD_SPEED)));
case SettingsManager::MAX_MCN_UPLOADS: return AirUtil::getSlotsPerUser(false, Util::toDouble(SETTING(UPLOAD_SPEED)));
case SettingsManager::MAX_MCN_DOWNLOADS: return AutoLimitUtil::getSlotsPerUser(true, Util::toDouble(SETTING(DOWNLOAD_SPEED)));
case SettingsManager::MAX_MCN_UPLOADS: return AutoLimitUtil::getSlotsPerUser(false, Util::toDouble(SETTING(UPLOAD_SPEED)));
}

return ApiSettingItem::getAutoValue();
Expand Down

0 comments on commit c26771b

Please sign in to comment.