@@ -120,28 +120,49 @@ final class LicensesService: Loggable {
120120 onProgress: { onProgress ( . percent( Float ( $0) ) ) }
121121 ) . get ( )
122122
123- var hints = FormatHints ( )
124- if let type = license. link ( for: . publication) ? . mediaType {
125- hints. mediaTypes. append ( type)
126- }
127- if let type = download. mediaType {
128- hints. mediaTypes. append ( type)
129- }
130-
131- let asset = try await assetRetriever. retrieve ( url: download. location, hints: hints)
132- . mapError { LCPError . licenseContainer ( ContainerError . openFailed ( $0) ) }
133- . get ( )
134-
135- try await injectLicense ( license, in: asset)
123+ let format = try await injectLicenseAndGetFormat (
124+ license,
125+ in: download. location,
126+ mediaTypeHint: download. mediaType
127+ )
136128
137129 return LCPAcquiredPublication (
138130 localURL: download. location,
139- format: asset . format,
140- suggestedFilename: asset . format. fileExtension. appendedToFilename ( license. id) ,
131+ format: format,
132+ suggestedFilename: format. fileExtension. appendedToFilename ( license. id) ,
141133 licenseDocument: license
142134 )
143135 }
144136
137+ func injectLicense(
138+ _ license: LicenseDocument ,
139+ in url: FileURL
140+ ) async throws {
141+ let _ = try await injectLicenseAndGetFormat ( license, in: url, mediaTypeHint: nil )
142+ }
143+
144+ private func injectLicenseAndGetFormat(
145+ _ license: LicenseDocument ,
146+ in url: FileURL ,
147+ mediaTypeHint: MediaType ? = nil
148+ ) async throws -> Format {
149+ var formatHints = FormatHints ( )
150+ if let type = license. publicationLink. mediaType {
151+ formatHints. mediaTypes. append ( type)
152+ }
153+ if let type = mediaTypeHint {
154+ formatHints. mediaTypes. append ( type)
155+ }
156+
157+ let asset = try await assetRetriever. retrieve ( url: url, hints: formatHints)
158+ . mapError { LCPError . licenseContainer ( ContainerError . openFailed ( $0) ) }
159+ . get ( )
160+
161+ try await injectLicense ( license, in: asset)
162+
163+ return asset. format
164+ }
165+
145166 private func readLicense( from lcpl: LicenseDocumentSource ) async throws -> LicenseDocument ? {
146167 switch lcpl {
147168 case let . data( data) :
0 commit comments