mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Extend a bit filesharing JSON API v2
This commit is contained in:
parent
186617fc2b
commit
5a301734a9
@ -37,6 +37,16 @@ FileSharingHandler::FileSharingHandler(StateTokenServer *sts, RsFiles *files,
|
||||
addResourceHandler("get_dir_parent", this, &FileSharingHandler::handleGetDirectoryParent);
|
||||
addResourceHandler("get_dir_childs", this, &FileSharingHandler::handleGetDirectoryChilds);
|
||||
|
||||
addResourceHandler( "get_download_directory", this,
|
||||
&FileSharingHandler::handleGetDownloadDirectory );
|
||||
addResourceHandler( "set_download_directory", this,
|
||||
&FileSharingHandler::handleSetDownloadDirectory );
|
||||
|
||||
addResourceHandler( "get_partials_directory", this,
|
||||
&FileSharingHandler::handleGetPartialsDirectory );
|
||||
addResourceHandler( "set_partials_directory", this,
|
||||
&FileSharingHandler::handleSetPartialsDirectory );
|
||||
|
||||
addResourceHandler("is_dl_dir_shared", this, &FileSharingHandler::handleIsDownloadDirShared);
|
||||
addResourceHandler("share_dl_dir", this, &FileSharingHandler::handleShareDownloadDirectory);
|
||||
|
||||
@ -513,4 +523,48 @@ void FileSharingHandler::handleDownload(Request& req, Response& resp)
|
||||
resp.setFail("Couldn't download file");
|
||||
}
|
||||
|
||||
void FileSharingHandler::handleGetDownloadDirectory( Request& /*req*/,
|
||||
Response& resp )
|
||||
{
|
||||
std::string dlDir = mRsFiles->getDownloadDirectory();
|
||||
resp.mDataStream << makeKeyValueReference("download_directory", dlDir);
|
||||
resp.setOk();
|
||||
}
|
||||
|
||||
void FileSharingHandler::handleSetDownloadDirectory( Request& req,
|
||||
Response& resp )
|
||||
{
|
||||
std::string dlDir;
|
||||
req.mStream << makeKeyValueReference("download_directory", dlDir);
|
||||
|
||||
if(dlDir.empty()) resp.setFail("missing download_directory");
|
||||
else
|
||||
{
|
||||
mRsFiles->setDownloadDirectory(dlDir);
|
||||
resp.setOk();
|
||||
}
|
||||
}
|
||||
|
||||
void FileSharingHandler::handleGetPartialsDirectory( Request& /*req*/,
|
||||
Response& resp )
|
||||
{
|
||||
std::string partialsDir = mRsFiles->getPartialsDirectory();
|
||||
resp.mDataStream << makeKeyValueReference("partials_directory", partialsDir);
|
||||
resp.setOk();
|
||||
}
|
||||
|
||||
void FileSharingHandler::handleSetPartialsDirectory( Request& req,
|
||||
Response& resp )
|
||||
{
|
||||
std::string partialsDir;
|
||||
req.mStream << makeKeyValueReference("partials_directory", partialsDir);
|
||||
|
||||
if(partialsDir.empty()) resp.setFail("missing partials_directory");
|
||||
else
|
||||
{
|
||||
mRsFiles->setPartialsDirectory(partialsDir);
|
||||
resp.setOk();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace resource_api
|
||||
|
@ -57,6 +57,12 @@ private:
|
||||
|
||||
void handleDownload(Request& req, Response& resp);
|
||||
|
||||
void handleGetDownloadDirectory(Request& req, Response& resp);
|
||||
void handleSetDownloadDirectory(Request& req, Response& resp);
|
||||
|
||||
void handleGetPartialsDirectory(Request& req, Response& resp);
|
||||
void handleSetPartialsDirectory(Request& req, Response& resp);
|
||||
|
||||
/// Token indicating change in local shared files
|
||||
StateToken mLocalDirStateToken;
|
||||
|
||||
|
@ -15,6 +15,14 @@ TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeer
|
||||
addResourceHandler("downloads", this, &TransfersHandler::handleDownloads);
|
||||
addResourceHandler("uploads", this, &TransfersHandler::handleUploads);
|
||||
addResourceHandler("control_download", this, &TransfersHandler::handleControlDownload);
|
||||
|
||||
addResourceHandler( "set_file_destination_directory", this,
|
||||
&TransfersHandler::handleSetFileDestinationDirectory );
|
||||
addResourceHandler( "set_file_destination_name", this,
|
||||
&TransfersHandler::handleSetFileDestinationName );
|
||||
addResourceHandler( "set_file_chunk_strategy", this,
|
||||
&TransfersHandler::handleSetFileChunkStrategy );
|
||||
|
||||
mStateToken = mStateTokenServer->getNewToken();
|
||||
mStateTokenServer->registerTickClient(this);
|
||||
mNotify.registerNotifyClient(this);
|
||||
@ -288,4 +296,58 @@ void TransfersHandler::handleUploads(Request & /* req */, Response &resp)
|
||||
resp.setOk();
|
||||
}
|
||||
|
||||
void TransfersHandler::handleSetFileDestinationDirectory( Request& req,
|
||||
Response& resp )
|
||||
{
|
||||
mStateTokenServer->replaceToken(mStateToken);
|
||||
|
||||
std::string hashString;
|
||||
std::string newPath;
|
||||
req.mStream << makeKeyValueReference("path", newPath);
|
||||
req.mStream << makeKeyValueReference("hash", hashString);
|
||||
RsFileHash hash(hashString);
|
||||
|
||||
if (mFiles->setDestinationDirectory(hash, newPath)) resp.setOk();
|
||||
else resp.setFail();
|
||||
}
|
||||
|
||||
void TransfersHandler::handleSetFileDestinationName( Request& req,
|
||||
Response& resp )
|
||||
{
|
||||
mStateTokenServer->replaceToken(mStateToken);
|
||||
|
||||
std::string hashString;
|
||||
std::string newName;
|
||||
req.mStream << makeKeyValueReference("name", newName);
|
||||
req.mStream << makeKeyValueReference("hash", hashString);
|
||||
RsFileHash hash(hashString);
|
||||
|
||||
if (mFiles->setDestinationName(hash, newName)) resp.setOk();
|
||||
else resp.setFail();
|
||||
}
|
||||
|
||||
void TransfersHandler::handleSetFileChunkStrategy(Request& req, Response& resp)
|
||||
{
|
||||
mStateTokenServer->replaceToken(mStateToken);
|
||||
|
||||
std::string hashString;
|
||||
std::string newChunkStrategyStr;
|
||||
req.mStream << makeKeyValueReference("chuck_stategy", newChunkStrategyStr);
|
||||
req.mStream << makeKeyValueReference("hash", hashString);
|
||||
|
||||
RsFileHash hash(hashString);
|
||||
FileChunksInfo::ChunkStrategy newStrategy =
|
||||
FileChunksInfo::CHUNK_STRATEGY_PROGRESSIVE;
|
||||
|
||||
if ( newChunkStrategyStr == "streaming" )
|
||||
newStrategy = FileChunksInfo::CHUNK_STRATEGY_STREAMING;
|
||||
else if ( newChunkStrategyStr == "random" )
|
||||
newStrategy = FileChunksInfo::CHUNK_STRATEGY_RANDOM;
|
||||
else if ( newChunkStrategyStr == "progressive" )
|
||||
newStrategy = FileChunksInfo::CHUNK_STRATEGY_PROGRESSIVE;
|
||||
|
||||
if (mFiles->setChunkStrategy(hash, newStrategy)) resp.setOk();
|
||||
else resp.setFail();
|
||||
}
|
||||
|
||||
} // namespace resource_api
|
||||
|
@ -30,6 +30,9 @@ private:
|
||||
void handleControlDownload(Request& req, Response& resp);
|
||||
void handleDownloads(Request& req, Response& resp);
|
||||
void handleUploads(Request& req, Response& resp);
|
||||
void handleSetFileDestinationDirectory(Request& req, Response& resp);
|
||||
void handleSetFileDestinationName(Request& req, Response& resp);
|
||||
void handleSetFileChunkStrategy(Request& req, Response& resp);
|
||||
|
||||
StateTokenServer* mStateTokenServer;
|
||||
RsFiles* mFiles;
|
||||
|
@ -168,10 +168,9 @@ public:
|
||||
|
||||
class RsFiles
|
||||
{
|
||||
public:
|
||||
|
||||
RsFiles() { return; }
|
||||
virtual ~RsFiles() { return; }
|
||||
public:
|
||||
RsFiles() {}
|
||||
virtual ~RsFiles() {}
|
||||
|
||||
/**
|
||||
* Provides file data for the gui: media streaming or rpc clients.
|
||||
|
Loading…
Reference in New Issue
Block a user