Add API call to create links to extra files

This commit is contained in:
Gioacchino Mazzurco 2020-03-22 15:13:09 +01:00
parent 55aab6c447
commit 1fd6e7e97a
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
3 changed files with 66 additions and 17 deletions

View file

@ -2217,16 +2217,14 @@ const noexcept
}
}
std::error_condition ftServer::exportFilesLink(
std::string& link, std::uintptr_t handle, bool fragSneak,
const std::string& baseUrl )
std::error_condition ftServer::dirDetailsToLink(
std::string& link,
const DirDetails& dirDetails, bool fragSneak, const std::string& baseUrl )
{
DirDetails tDirDet;
if(!requestDirDetails(tDirDet, handle))
return RsFilesErrorNum::FILES_HANDLE_NOT_FOUND;
std::unique_ptr<RsFileTree> tFileTree =
RsFileTree::fromDirDetails(tDirDet, false);
RsFileTree::fromDirDetails(dirDetails, false);
if(!tFileTree) return std::errc::invalid_argument;
link = tFileTree->toBase64();
if(!baseUrl.empty())
@ -2234,7 +2232,7 @@ std::error_condition ftServer::exportFilesLink(
RsUrl tUrl(baseUrl);
tUrl.setQueryKV(FILES_URL_COUNT_FIELD,
std::to_string(tFileTree->mTotalFiles) )
.setQueryKV(FILES_URL_NAME_FIELD, tDirDet.name)
.setQueryKV(FILES_URL_NAME_FIELD, dirDetails.name)
.setQueryKV( FILES_URL_SIZE_FIELD,
std::to_string(tFileTree->mTotalSize) );
if(fragSneak)
@ -2247,6 +2245,34 @@ std::error_condition ftServer::exportFilesLink(
return std::error_condition();
}
std::error_condition ftServer::exportCollectionLink(
std::string& link, std::uintptr_t handle, bool fragSneak,
const std::string& baseUrl )
{
DirDetails tDirDet;
if(!requestDirDetails(tDirDet, handle))
return RsFilesErrorNum::FILES_HANDLE_NOT_FOUND;
return dirDetailsToLink(link, tDirDet, fragSneak, baseUrl);
}
/// @see RsFiles
std::error_condition ftServer::exportFileLink(
std::string& link, const RsFileHash& fileHash, uint64_t fileSize,
const std::string& fileName, bool fragSneak, const std::string& baseUrl )
{
if(fileHash.isNull() || !fileSize || fileName.empty())
return std::errc::invalid_argument;
DirDetails tDirDet;
tDirDet.type = DIR_TYPE_FILE;
tDirDet.name = fileName;
tDirDet.hash = fileHash;
tDirDet.count = fileSize;
return dirDetailsToLink(link, tDirDet, fragSneak, baseUrl);
}
std::error_condition ftServer::parseFilesLink(
const std::string& link, RsFileTree& collection )
{

View file

@ -224,11 +224,18 @@ public:
virtual TurtleSearchRequestId turtleSearch(const RsRegularExpression::LinearizedExpression& expr) ;
/// @see RsFiles
std::error_condition exportFilesLink(
std::error_condition exportCollectionLink(
std::string& link, std::uintptr_t handle, bool fragSneak = false,
const std::string& baseUrl = RsFiles::DEFAULT_FILES_BASE_URL
) override;
/// @see RsFiles
std::error_condition exportFileLink(
std::string& link, const RsFileHash& fileHash, uint64_t fileSize,
const std::string& fileName, bool fragSneak = false,
const std::string& baseUrl = RsFiles::DEFAULT_FILES_BASE_URL
) override;
/// @see RsFiles
std::error_condition parseFilesLink(
const std::string& link, RsFileTree& collection ) override;
@ -383,11 +390,11 @@ protected:
bool findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash);
bool checkUploadLimit(const RsPeerId& pid,const RsFileHash& hash);
private:
/**** INTERNAL FUNCTIONS ***/
//virtual int reScanDirs();
//virtual int check_dBUpdate();
std::error_condition dirDetailsToLink(
std::string& link,
const DirDetails& dirDetails, bool fragSneak,
const std::string& baseUrl );
private: