1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-23 13:04:23 +00:00

WebUI: Assign a version to the Web API and allow to get it

New GET methods:
 * version/api: current API version
 * version/api_min: min API version supported

The API version is an integer and it's returned as plain text.

Whenever the API is changed, the api version is increased.

Whenever the API is changed in a way that is not backward compatible,
api_min is increased.
This commit is contained in:
Gabriele 2014-11-22 20:32:04 +01:00
parent 1154ea3873
commit 8b5512c244
2 changed files with 19 additions and 1 deletions

View File

@ -51,6 +51,9 @@
using namespace libtorrent;
static const int API_VERSION = 2;
static const int API_VERSION_MIN = 2;
const QString WWW_FOLDER = ":/www/public/";
const QString PRIVATE_FOLDER = ":/www/private/";
const QString DEFAULT_SCOPE = "public";
@ -58,6 +61,7 @@ const QString SCOPE_IMAGES = "images";
const QString SCOPE_THEME = "theme";
const QString DEFAULT_ACTION = "index";
const QString WEBUI_ACTION = "webui";
const QString VERSION_INFO = "version";
#define ADD_ACTION(scope, action) actions[#scope][#action] = &RequestHandler::action_##scope##_##action
@ -102,6 +106,8 @@ QMap<QString, QMap<QString, RequestHandler::Action> > RequestHandler::initialize
ADD_ACTION(command, topPrio);
ADD_ACTION(command, bottomPrio);
ADD_ACTION(command, recheck);
ADD_ACTION(version, api);
ADD_ACTION(version, api_min);
return actions;
}
@ -209,6 +215,16 @@ void RequestHandler::action_json_propertiesFiles()
print(btjson::getFilesForTorrent(args_.front()), CONTENT_TYPE_JS);
}
void RequestHandler::action_version_api()
{
print(QString::number(API_VERSION), CONTENT_TYPE_TXT);
}
void RequestHandler::action_version_api_min()
{
print(QString::number(API_VERSION_MIN), CONTENT_TYPE_TXT);
}
void RequestHandler::action_command_shutdown()
{
qDebug() << "Shutdown request from Web UI";
@ -489,7 +505,7 @@ void RequestHandler::action_command_recheck()
bool RequestHandler::isPublicScope()
{
return (scope_ == DEFAULT_SCOPE);
return (scope_ == DEFAULT_SCOPE || scope_ == VERSION_INFO);
}
void RequestHandler::processRequest()

View File

@ -81,6 +81,8 @@ private:
void action_command_topPrio();
void action_command_bottomPrio();
void action_command_recheck();
void action_version_api();
void action_version_api_min();
typedef void (RequestHandler::*Action)();