mirror of https://github.com/vitalif/grive2
fetching the next link
parent
b90e032cda
commit
1eeaede474
|
@ -50,22 +50,32 @@ Drive::Drive( OAuth2& auth ) :
|
||||||
m_http_hdr.push_back( "Authorization: Bearer " + m_auth.AccessToken() ) ;
|
m_http_hdr.push_back( "Authorization: Bearer " + m_auth.AccessToken() ) ;
|
||||||
m_http_hdr.push_back( "GData-Version: 3.0" ) ;
|
m_http_hdr.push_back( "GData-Version: 3.0" ) ;
|
||||||
|
|
||||||
Json resp = Json::Parse( http::Get( root_url + "?alt=json&showfolders=true", m_http_hdr )) ;
|
ConstructDirTree( ) ;
|
||||||
|
|
||||||
|
Json resp = Json::Parse( http::Get( root_url + "?alt=json", m_http_hdr )) ;
|
||||||
|
|
||||||
Json resume_link ;
|
Json resume_link ;
|
||||||
if ( resp["feed"]["link"].FindInArray( "rel", "http://schemas.google.com/g/2005#resumable-create-media", resume_link ) )
|
if ( resp["feed"]["link"].FindInArray( "rel", "http://schemas.google.com/g/2005#resumable-create-media", resume_link ) )
|
||||||
m_resume_link = resume_link["href"].As<std::string>() ;
|
m_resume_link = resume_link["href"].As<std::string>() ;
|
||||||
|
|
||||||
Json::Array entries = resp["feed"]["entry"].As<Json::Array>() ;
|
bool has_next = false ;
|
||||||
ConstructDirTree( entries ) ;
|
do
|
||||||
|
|
||||||
for ( Json::Array::iterator i = entries.begin() ; i != entries.end() ; ++i )
|
|
||||||
{
|
{
|
||||||
if ( !Collection::IsCollection( *i ) )
|
Json::Array entries = resp["feed"]["entry"].As<Json::Array>() ;
|
||||||
|
for ( Json::Array::iterator i = entries.begin() ; i != entries.end() ; ++i )
|
||||||
{
|
{
|
||||||
UpdateFile( *i ) ;
|
if ( !Collection::IsCollection( *i ) )
|
||||||
|
{
|
||||||
|
UpdateFile( *i ) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Json next ;
|
||||||
|
has_next = resp["feed"]["link"].FindInArray( "rel", "next", next ) ;
|
||||||
|
|
||||||
|
if ( has_next )
|
||||||
|
resp = Json::Parse( http::Get( next["href"].Str(), m_http_hdr ) ) ;
|
||||||
|
} while ( has_next ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Drive::~Drive( )
|
Drive::~Drive( )
|
||||||
|
@ -93,24 +103,36 @@ Drive::FolderListIterator Drive::FindFolder( const std::string& href )
|
||||||
return (it != m_coll.end() && it->Href() == href) ? it : m_coll.end() ;
|
return (it != m_coll.end() && it->Href() == href) ? it : m_coll.end() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drive::ConstructDirTree( const std::vector<Json>& entries )
|
void Drive::ConstructDirTree( )
|
||||||
{
|
{
|
||||||
|
Json resp = Json::Parse( http::Get( root_url + "/-/folder?alt=json", m_http_hdr )) ;
|
||||||
assert( m_coll.empty() ) ;
|
assert( m_coll.empty() ) ;
|
||||||
|
|
||||||
std::map<std::string, std::string> parent_href ;
|
std::map<std::string, std::string> parent_href ;
|
||||||
|
while ( true )
|
||||||
// first, get all collections from the query result
|
|
||||||
for ( Json::Array::const_iterator i = entries.begin() ; i != entries.end() ; ++i )
|
|
||||||
{
|
{
|
||||||
if ( Collection::IsCollection( *i ) )
|
Json::Array entries = resp["feed"]["entry"].As<Json::Array>() ;
|
||||||
|
|
||||||
|
// first, get all collections from the query result
|
||||||
|
for ( Json::Array::const_iterator i = entries.begin() ; i != entries.end() ; ++i )
|
||||||
{
|
{
|
||||||
m_coll.push_back( Collection( *i ) ) ;
|
if ( Collection::IsCollection( *i ) )
|
||||||
parent_href.insert(
|
{
|
||||||
std::make_pair(
|
m_coll.push_back( Collection( *i ) ) ;
|
||||||
m_coll.back().Href(),
|
parent_href.insert(
|
||||||
Collection::ParentHref( *i ) ) ) ;
|
std::make_pair(
|
||||||
|
m_coll.back().Href(),
|
||||||
|
Collection::ParentHref( *i ) ) ) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
assert( m_coll.size() == parent_href.size() ) ;
|
||||||
|
|
||||||
|
Json next ;
|
||||||
|
if ( !resp["feed"]["link"].FindInArray( "rel", "next", next ) )
|
||||||
|
break ;
|
||||||
|
|
||||||
|
resp = Json::Parse( http::Get( next["href"].Str(), m_http_hdr ) ) ;
|
||||||
}
|
}
|
||||||
assert( m_coll.size() == parent_href.size() ) ;
|
|
||||||
|
|
||||||
// second, build up linkage between parent and child
|
// second, build up linkage between parent and child
|
||||||
std::sort( m_coll.begin(), m_coll.end(), SortCollectionByHref() ) ;
|
std::sort( m_coll.begin(), m_coll.end(), SortCollectionByHref() ) ;
|
||||||
|
|
|
@ -42,7 +42,7 @@ public :
|
||||||
private :
|
private :
|
||||||
void UpdateFile( const Json& entry ) ;
|
void UpdateFile( const Json& entry ) ;
|
||||||
|
|
||||||
void ConstructDirTree( const std::vector<Json>& entries ) ;
|
void ConstructDirTree( ) ;
|
||||||
|
|
||||||
FolderListIterator FindFolder( const std::string& href ) ;
|
FolderListIterator FindFolder( const std::string& href ) ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue