@@ -134,16 +134,17 @@ public extension HubApi {
134134
135135 switch response. statusCode {
136136 case 200 ..< 400 : break // Allow redirects to pass through to the redirect delegate
137- case 400 ..< 500 : throw Hub . HubClientError. authorizationRequired
137+ case 401 , 403 : throw Hub . HubClientError. authorizationRequired
138+ case 404 : throw Hub . HubClientError. fileNotFound ( url. lastPathComponent)
138139 default : throw Hub . HubClientError. httpStatusCode ( response. statusCode)
139140 }
140141
141142 return ( data, response)
142143 }
143144
144- func getFilenames( from repo: Repo , matching globs: [ String ] = [ ] ) async throws -> [ String ] {
145+ func getFilenames( from repo: Repo , revision : String = " main " , matching globs: [ String ] = [ ] ) async throws -> [ String ] {
145146 // Read repo info and only parse "siblings"
146- let url = URL ( string: " \( endpoint) /api/ \( repo. type) / \( repo. id) " ) !
147+ let url = URL ( string: " \( endpoint) /api/ \( repo. type) / \( repo. id) /revision/ \( revision ) " ) !
147148 let ( data, _) = try await httpGet ( for: url)
148149 let response = try JSONDecoder ( ) . decode ( SiblingsResponse . self, from: data)
149150 let filenames = response. siblings. map { $0. rfilename }
@@ -335,6 +336,7 @@ public extension HubApi {
335336 struct HubFileDownloader {
336337 let hub : HubApi
337338 let repo : Repo
339+ let revision : String
338340 let repoDestination : URL
339341 let repoMetadataDestination : URL
340342 let relativeFilename : String
@@ -349,7 +351,7 @@ public extension HubApi {
349351 url = url. appending ( component: repo. type. rawValue)
350352 }
351353 url = url. appending ( path: repo. id)
352- url = url. appending ( path: " resolve/main " ) // TODO: revisions
354+ url = url. appending ( path: " resolve/ \( revision ) " )
353355 url = url. appending ( path: relativeFilename)
354356 return url
355357 }
@@ -462,7 +464,7 @@ public extension HubApi {
462464 }
463465
464466 @discardableResult
465- func snapshot( from repo: Repo , matching globs: [ String ] = [ ] , progressHandler: @escaping ( Progress ) -> Void = { _ in } ) async throws -> URL {
467+ func snapshot( from repo: Repo , revision : String = " main " , matching globs: [ String ] = [ ] , progressHandler: @escaping ( Progress ) -> Void = { _ in } ) async throws -> URL {
466468 let repoDestination = localRepoLocation ( repo)
467469 let repoMetadataDestination = repoDestination
468470 . appendingPathComponent ( " .cache " )
@@ -504,13 +506,14 @@ public extension HubApi {
504506 return repoDestination
505507 }
506508
507- let filenames = try await getFilenames ( from: repo, matching: globs)
509+ let filenames = try await getFilenames ( from: repo, revision : revision , matching: globs)
508510 let progress = Progress ( totalUnitCount: Int64 ( filenames. count) )
509511 for filename in filenames {
510512 let fileProgress = Progress ( totalUnitCount: 100 , parent: progress, pendingUnitCount: 1 )
511513 let downloader = HubFileDownloader (
512514 hub: self ,
513515 repo: repo,
516+ revision: revision,
514517 repoDestination: repoDestination,
515518 repoMetadataDestination: repoMetadataDestination,
516519 relativeFilename: filename,
@@ -529,18 +532,18 @@ public extension HubApi {
529532 }
530533
531534 @discardableResult
532- func snapshot( from repoId: String , matching globs: [ String ] = [ ] , progressHandler: @escaping ( Progress ) -> Void = { _ in } ) async throws -> URL {
533- try await snapshot ( from: Repo ( id: repoId) , matching: globs, progressHandler: progressHandler)
535+ func snapshot( from repoId: String , revision : String = " main " , matching globs: [ String ] = [ ] , progressHandler: @escaping ( Progress ) -> Void = { _ in } ) async throws -> URL {
536+ try await snapshot ( from: Repo ( id: repoId) , revision : revision , matching: globs, progressHandler: progressHandler)
534537 }
535538
536539 @discardableResult
537- func snapshot( from repo: Repo , matching glob: String , progressHandler: @escaping ( Progress ) -> Void = { _ in } ) async throws -> URL {
538- try await snapshot ( from: repo, matching: [ glob] , progressHandler: progressHandler)
540+ func snapshot( from repo: Repo , revision : String = " main " , matching glob: String , progressHandler: @escaping ( Progress ) -> Void = { _ in } ) async throws -> URL {
541+ try await snapshot ( from: repo, revision : revision , matching: [ glob] , progressHandler: progressHandler)
539542 }
540543
541544 @discardableResult
542- func snapshot( from repoId: String , matching glob: String , progressHandler: @escaping ( Progress ) -> Void = { _ in } ) async throws -> URL {
543- try await snapshot ( from: Repo ( id: repoId) , matching: [ glob] , progressHandler: progressHandler)
545+ func snapshot( from repoId: String , revision : String = " main " , matching glob: String , progressHandler: @escaping ( Progress ) -> Void = { _ in } ) async throws -> URL {
546+ try await snapshot ( from: Repo ( id: repoId) , revision : revision , matching: [ glob] , progressHandler: progressHandler)
544547 }
545548}
546549
@@ -596,9 +599,9 @@ public extension HubApi {
596599 )
597600 }
598601
599- func getFileMetadata( from repo: Repo , matching globs: [ String ] = [ ] ) async throws -> [ FileMetadata ] {
602+ func getFileMetadata( from repo: Repo , revision : String = " main " , matching globs: [ String ] = [ ] ) async throws -> [ FileMetadata ] {
600603 let files = try await getFilenames ( from: repo, matching: globs)
601- let url = URL ( string: " \( endpoint) / \( repo. id) /resolve/main " ) ! // TODO: revisions
604+ let url = URL ( string: " \( endpoint) / \( repo. id) /resolve/ \( revision ) " ) !
602605 var selectedMetadata : [ FileMetadata ] = [ ]
603606 for file in files {
604607 let fileURL = url. appending ( path: file)
@@ -607,16 +610,16 @@ public extension HubApi {
607610 return selectedMetadata
608611 }
609612
610- func getFileMetadata( from repoId: String , matching globs: [ String ] = [ ] ) async throws -> [ FileMetadata ] {
611- try await getFileMetadata ( from: Repo ( id: repoId) , matching: globs)
613+ func getFileMetadata( from repoId: String , revision : String = " main " , matching globs: [ String ] = [ ] ) async throws -> [ FileMetadata ] {
614+ try await getFileMetadata ( from: Repo ( id: repoId) , revision : revision , matching: globs)
612615 }
613616
614- func getFileMetadata( from repo: Repo , matching glob: String ) async throws -> [ FileMetadata ] {
615- try await getFileMetadata ( from: repo, matching: [ glob] )
617+ func getFileMetadata( from repo: Repo , revision : String = " main " , matching glob: String ) async throws -> [ FileMetadata ] {
618+ try await getFileMetadata ( from: repo, revision : revision , matching: [ glob] )
616619 }
617620
618- func getFileMetadata( from repoId: String , matching glob: String ) async throws -> [ FileMetadata ] {
619- try await getFileMetadata ( from: Repo ( id: repoId) , matching: [ glob] )
621+ func getFileMetadata( from repoId: String , revision : String = " main " , matching glob: String ) async throws -> [ FileMetadata ] {
622+ try await getFileMetadata ( from: Repo ( id: repoId) , revision : revision , matching: [ glob] )
620623 }
621624}
622625
0 commit comments