mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 17:21:27 -05:00
Expose JSON API for ExtraFiles management
This commit is contained in:
parent
3ffb57f998
commit
354739fa0f
@ -968,16 +968,18 @@ int p3FileDatabase::getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3FileDatabase::removeExtraFile(const RsFileHash& hash)
|
bool p3FileDatabase::removeExtraFile(const RsFileHash& hash)
|
||||||
{
|
{
|
||||||
|
bool ret = false;
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mFLSMtx) ;
|
RS_STACK_MUTEX(mFLSMtx) ;
|
||||||
|
|
||||||
mExtraFiles->removeExtraFile(hash);
|
ret = mExtraFiles->removeExtraFile(hash);
|
||||||
mLastExtraFilesCacheUpdate = 0 ; // forced cache reload
|
mLastExtraFilesCacheUpdate = 0 ; // forced cache reload
|
||||||
}
|
}
|
||||||
|
|
||||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
|
RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIndex e,DirDetails& d) const
|
void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIndex e,DirDetails& d) const
|
||||||
|
@ -109,8 +109,8 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub
|
|||||||
virtual int SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) ;
|
virtual int SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) ;
|
||||||
virtual int SearchBoolExp(RsRegularExpression::Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
|
virtual int SearchBoolExp(RsRegularExpression::Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
|
||||||
|
|
||||||
// Extra file list
|
// Extra file list
|
||||||
virtual void removeExtraFile(const RsFileHash& hash);
|
virtual bool removeExtraFile(const RsFileHash& hash);
|
||||||
|
|
||||||
// Interface for browsing dir hierarchy
|
// Interface for browsing dir hierarchy
|
||||||
//
|
//
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
* *
|
* *
|
||||||
* libretroshare: retroshare core library *
|
* libretroshare: retroshare core library *
|
||||||
* *
|
* *
|
||||||
* Copyright 2008 by Robert Fernie <retroshare@lunamutt.com> *
|
* Copyright (C) 2008 Robert Fernie <retroshare@lunamutt.com> *
|
||||||
|
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU Lesser General Public License as *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
@ -272,7 +273,8 @@ bool ftExtraList::cleanupEntry(std::string /*path*/, TransferRequestFlags /*flag
|
|||||||
* file is removed after period.
|
* file is removed after period.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
bool ftExtraList::hashExtraFile(std::string path, uint32_t period, TransferRequestFlags flags)
|
bool ftExtraList::hashExtraFile(
|
||||||
|
std::string path, uint32_t period, TransferRequestFlags flags )
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_ELIST
|
#ifdef DEBUG_ELIST
|
||||||
std::cerr << "ftExtraList::hashExtraFile() path: " << path;
|
std::cerr << "ftExtraList::hashExtraFile() path: " << path;
|
||||||
@ -282,12 +284,25 @@ bool ftExtraList::hashExtraFile(std::string path, uint32_t period, TransferRequ
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* add into queue */
|
auto failure = [](std::string errMsg)
|
||||||
RS_STACK_MUTEX(extMutex);
|
{
|
||||||
|
RsErr() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!RsDirUtil::fileExists(path))
|
||||||
|
return failure("file: " + path + "not found");
|
||||||
|
|
||||||
|
if(RsDirUtil::checkDirectory(path))
|
||||||
|
return failure("Cannot add a directory: " + path + "as extra file");
|
||||||
|
|
||||||
FileDetails details(path, period, flags);
|
FileDetails details(path, period, flags);
|
||||||
details.info.age = time(NULL) + period;
|
details.info.age = static_cast<int>(time(nullptr) + period);
|
||||||
mToHash.push_back(details);
|
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(extMutex);
|
||||||
|
mToHash.push_back(details); /* add into queue */
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -678,14 +678,13 @@ bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ftServer::ExtraFileRemove(const RsFileHash& hash)
|
bool ftServer::ExtraFileRemove(const RsFileHash& hash)
|
||||||
{
|
{ return mFileDatabase->removeExtraFile(hash); }
|
||||||
mFileDatabase->removeExtraFile(hash);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags)
|
bool ftServer::ExtraFileHash(
|
||||||
|
std::string localpath, rstime_t period, TransferRequestFlags flags )
|
||||||
{
|
{
|
||||||
return mFtExtra->hashExtraFile(localpath, period, flags);
|
return mFtExtra->hashExtraFile(
|
||||||
|
localpath, static_cast<uint32_t>(period), flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info)
|
bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info)
|
||||||
|
@ -181,7 +181,7 @@ public:
|
|||||||
***/
|
***/
|
||||||
virtual bool ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
virtual bool ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||||
virtual bool ExtraFileRemove(const RsFileHash& hash);
|
virtual bool ExtraFileRemove(const RsFileHash& hash);
|
||||||
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags);
|
virtual bool ExtraFileHash(std::string localpath, rstime_t period, TransferRequestFlags flags);
|
||||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
||||||
virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath);
|
virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath);
|
||||||
|
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
* *
|
* *
|
||||||
* libretroshare: retroshare core library *
|
* libretroshare: retroshare core library *
|
||||||
* *
|
* *
|
||||||
* Copyright 2008-2008 by Robert Fernie <retroshare@lunamutt.com> *
|
* Copyright (C) 2008 Robert Fernie <retroshare@lunamutt.com> *
|
||||||
|
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||||
* *
|
* *
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU Lesser General Public License as *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
@ -422,22 +423,47 @@ public:
|
|||||||
* @brief Get details about the upload with given hash
|
* @brief Get details about the upload with given hash
|
||||||
* @jsonapi{development}
|
* @jsonapi{development}
|
||||||
* @param[in] hash file identifier
|
* @param[in] hash file identifier
|
||||||
* @param[in] peer_id peer identifier
|
* @param[in] peerId peer identifier
|
||||||
* @param[out] map storage for chunk info
|
* @param[out] map storage for chunk info
|
||||||
* @return true if file found, false otherwise
|
* @return true if file found, false otherwise
|
||||||
*/
|
*/
|
||||||
virtual bool FileUploadChunksDetails(
|
virtual bool FileUploadChunksDetails(
|
||||||
const RsFileHash& hash, const RsPeerId& peer_id,
|
const RsFileHash& hash, const RsPeerId& peerId,
|
||||||
CompressedChunkMap& map ) = 0;
|
CompressedChunkMap& map ) = 0;
|
||||||
|
|
||||||
/***
|
/**
|
||||||
* Extra List Access
|
* @brief Remove file from extra fila shared list
|
||||||
***/
|
* @jsonapi{development}
|
||||||
//virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags) = 0;
|
* @param[in] hash hash of the file to remove
|
||||||
virtual bool ExtraFileRemove(const RsFileHash& hash) = 0;
|
* @return return false on error, true otherwise
|
||||||
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags) = 0;
|
*/
|
||||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
|
virtual bool ExtraFileRemove(const RsFileHash& hash) = 0;
|
||||||
virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath) = 0;
|
|
||||||
|
/**
|
||||||
|
* @brief Add file to extra shared file list
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] localpath path of the file
|
||||||
|
* @param[in] period how much time the file will be kept in extra list in
|
||||||
|
* seconds
|
||||||
|
* @param[in] flags sharing policy flags ex: RS_FILE_REQ_ANONYMOUS_ROUTING
|
||||||
|
* @return false on error, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool ExtraFileHash(
|
||||||
|
std::string localpath, rstime_t period, TransferRequestFlags flags
|
||||||
|
) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get extra file information
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] localpath path of the file
|
||||||
|
* @param[out] info storage for the file information
|
||||||
|
* @return false on error, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
|
||||||
|
|
||||||
|
virtual bool ExtraFileMove(
|
||||||
|
std::string fname, const RsFileHash& hash, uint64_t size,
|
||||||
|
std::string destpath ) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Request directory details, subsequent multiple call may be used to
|
* @brief Request directory details, subsequent multiple call may be used to
|
||||||
|
@ -1852,12 +1852,8 @@ bool p3GxsChannels::ExtraFileHash(const std::string& path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool p3GxsChannels::ExtraFileRemove(const RsFileHash &hash)
|
bool p3GxsChannels::ExtraFileRemove(const RsFileHash& hash)
|
||||||
{
|
{ return rsFiles->ExtraFileRemove(hash); }
|
||||||
//TransferRequestFlags tflags = RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA;
|
|
||||||
RsFileHash fh = RsFileHash(hash);
|
|
||||||
return rsFiles->ExtraFileRemove(fh);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user