mirror of
https://github.com/aria2/aria2.git
synced 2025-01-04 09:03:46 +00:00
Add aria2.saveSession RPC method
This method saves the current session to a file specified by --save-session option. This method returns "OK" if it succeeds.
This commit is contained in:
parent
1a24020e63
commit
a8319a8b78
@ -3209,6 +3209,12 @@ For *secret* parameter, see :ref:`rpc_auth`.
|
||||
except that any actions which takes time such as contacting BitTorrent
|
||||
tracker are skipped. This method returns ``OK``.
|
||||
|
||||
.. function:: aria2.saveSession([secret])
|
||||
|
||||
This method saves the current session to a file specified by
|
||||
:option:`--save-session` option. This method returns ``OK`` if it
|
||||
succeeds.
|
||||
|
||||
.. function:: system.multicall(methods)
|
||||
|
||||
This methods encapsulates multiple method calls in a single request.
|
||||
|
@ -273,6 +273,7 @@ Usage: #{program_name} addUri URI... [options]
|
||||
#{program_name} shutdown [options]
|
||||
#{program_name} forceShutdown [options]
|
||||
#{program_name} getGlobalStat [options]
|
||||
#{program_name} saveSession [options]
|
||||
#{program_name} appendUri GID fileIndex URI... [options]
|
||||
This command calls aria2.changeUri(GID, fileIndex, [], [URI,...])
|
||||
internally.
|
||||
@ -394,6 +395,8 @@ elsif command == "forceShutdown" then
|
||||
result=client_call(client, secret, "aria2."+command)
|
||||
elsif command == "getGlobalStat" then
|
||||
result=client_call(client, secret, "aria2."+command)
|
||||
elsif command == "saveSession" then
|
||||
result=client_call(client, secret, "aria2."+command)
|
||||
elsif command == "appendUri" then
|
||||
result=client_call(client, secret, "aria2.changeUri", resources[0],
|
||||
resources[1].to_i(), [], resources[2..-1])
|
||||
|
@ -126,6 +126,8 @@ createMethod(const std::string& methodName)
|
||||
return make_unique<ForceShutdownRpcMethod>();
|
||||
} else if(methodName == GetGlobalStatRpcMethod::getMethodName()) {
|
||||
return make_unique<GetGlobalStatRpcMethod>();
|
||||
} else if(methodName == SaveSessionRpcMethod::getMethodName()) {
|
||||
return make_unique<SaveSessionRpcMethod>();
|
||||
} else if(methodName == SystemMulticallRpcMethod::getMethodName()) {
|
||||
return make_unique<SystemMulticallRpcMethod>();
|
||||
} else {
|
||||
|
@ -65,6 +65,7 @@
|
||||
#include "PeerStat.h"
|
||||
#include "base64.h"
|
||||
#include "BitfieldMan.h"
|
||||
#include "SessionSerializer.h"
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "MessageDigest.h"
|
||||
# include "message_digest_helper.h"
|
||||
@ -1347,6 +1348,23 @@ std::unique_ptr<ValueBase> GetGlobalStatRpcMethod::process
|
||||
return std::move(res);
|
||||
}
|
||||
|
||||
std::unique_ptr<ValueBase> SaveSessionRpcMethod::process
|
||||
(const RpcRequest& req, DownloadEngine* e)
|
||||
{
|
||||
const std::string& filename = e->getOption()->get(PREF_SAVE_SESSION);
|
||||
if(filename.empty()) {
|
||||
throw DL_ABORT_EX("Filename is not given.");
|
||||
}
|
||||
SessionSerializer sessionSerializer(e->getRequestGroupMan().get());
|
||||
if(sessionSerializer.save(filename)) {
|
||||
A2_LOG_NOTICE(fmt(_("Serialized session to '%s' successfully."),
|
||||
filename.c_str()));
|
||||
return createOKResponse();
|
||||
}
|
||||
throw DL_ABORT_EX(fmt("Failed to serialize session to '%s'.",
|
||||
filename.c_str()));
|
||||
}
|
||||
|
||||
std::unique_ptr<ValueBase> SystemMulticallRpcMethod::process
|
||||
(const RpcRequest& req, DownloadEngine* e)
|
||||
{
|
||||
|
@ -567,6 +567,17 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SaveSessionRpcMethod:public RpcMethod {
|
||||
protected:
|
||||
virtual std::unique_ptr<ValueBase> process
|
||||
(const RpcRequest& req, DownloadEngine* e) CXX11_OVERRIDE;
|
||||
public:
|
||||
static const char* getMethodName()
|
||||
{
|
||||
return "aria2.saveSession";
|
||||
}
|
||||
};
|
||||
|
||||
class SystemMulticallRpcMethod:public RpcMethod {
|
||||
protected:
|
||||
virtual std::unique_ptr<ValueBase> process
|
||||
|
Loading…
Reference in New Issue
Block a user