@@ -183,17 +183,30 @@ public function getRepositoryTree(string $owner, string $repositoryName, string
183183 $ url = "/projects/ {$ projectPath }/repository/tree?ref= " . urlencode ($ branch );
184184
185185 if ($ recursive ) {
186- $ url .= "&recursive=true&per_page=100 " ;
186+ $ page = 1 ;
187+ $ allItems = [];
188+ do {
189+ $ pagedUrl = $ url . "&recursive=true&per_page=100&page= {$ page }" ;
190+ $ response = $ this ->call (self ::METHOD_GET , $ pagedUrl , ['PRIVATE-TOKEN ' => $ this ->accessToken ]);
191+ $ responseHeaders = $ response ['headers ' ] ?? [];
192+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
193+ if ($ responseHeadersStatusCode >= 400 ) {
194+ return [];
195+ }
196+ $ responseBody = $ response ['body ' ] ?? [];
197+ if (!is_array ($ responseBody ) || empty ($ responseBody )) {
198+ break ;
199+ }
200+ $ allItems = array_merge ($ allItems , $ responseBody );
201+ $ page ++;
202+ } while (count ($ responseBody ) === 100 );
203+ return array_column ($ allItems , 'path ' );
187204 }
188205
189206 $ response = $ this ->call (self ::METHOD_GET , $ url , ['PRIVATE-TOKEN ' => $ this ->accessToken ]);
190207
191208 $ responseHeaders = $ response ['headers ' ] ?? [];
192209 $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
193- if ($ responseHeadersStatusCode === 404 ) {
194- return [];
195- }
196-
197210 if ($ responseHeadersStatusCode >= 400 ) {
198211 return [];
199212 }
@@ -211,7 +224,7 @@ public function getRepositoryContent(string $owner, string $repositoryName, stri
211224 $ ownerPath = $ this ->getOwnerPath ($ owner );
212225 $ projectPath = urlencode ("{$ ownerPath }/ {$ repositoryName }" );
213226 $ encodedPath = urlencode ($ path );
214- $ url = "/projects/ {$ projectPath }/repository/files/ {$ encodedPath }?ref= " . urlencode (empty ($ ref ) ? 'main ' : $ ref );
227+ $ url = "/projects/ {$ projectPath }/repository/files/ {$ encodedPath }?ref= " . urlencode (empty ($ ref ) ? 'HEAD ' : $ ref );
215228
216229 $ response = $ this ->call (self ::METHOD_GET , $ url , ['PRIVATE-TOKEN ' => $ this ->accessToken ]);
217230
@@ -225,7 +238,11 @@ public function getRepositoryContent(string $owner, string $repositoryName, stri
225238
226239 $ content = '' ;
227240 if (($ responseBody ['encoding ' ] ?? '' ) === 'base64 ' ) {
228- $ content = base64_decode ($ responseBody ['content ' ] ?? '' );
241+ $ rawContent = $ responseBody ['content ' ] ?? '' ;
242+ $ content = base64_decode ($ rawContent , true );
243+ if ($ content === false ) {
244+ throw new \Utopia \VCS \Exception \FileNotFound ();
245+ }
229246 } else {
230247 throw new \Utopia \VCS \Exception \FileNotFound ();
231248 }
@@ -241,10 +258,10 @@ public function listRepositoryContents(string $owner, string $repositoryName, st
241258 {
242259 $ ownerPath = $ this ->getOwnerPath ($ owner );
243260 $ projectPath = urlencode ("{$ ownerPath }/ {$ repositoryName }" );
244- $ url = "/projects/ {$ projectPath }/repository/tree?ref= " . urlencode (empty ($ ref ) ? 'main ' : $ ref );
261+ $ url = "/projects/ {$ projectPath }/repository/tree " . (empty ($ ref ) ? '' : ' ?ref= ' . urlencode ( $ ref) );
245262
246263 if (!empty ($ path )) {
247- $ url .= " & path=" . urlencode ($ path );
264+ $ url .= ( empty ( $ ref ) ? ' ? ' : ' & ' ) . ' path= ' . urlencode ($ path );
248265 }
249266
250267 $ response = $ this ->call (self ::METHOD_GET , $ url , ['PRIVATE-TOKEN ' => $ this ->accessToken ]);
0 commit comments