MCPcopy Create free account
hub / github.com/fontsource/fontsource / buildDownloadArtifacts

Function buildDownloadArtifacts

api/container/src/artifacts.ts:203–292  ·  view source on GitHub ↗
(
	request: BuildDownloadRequest,
)

Source from the content-addressed store, hash-verified

201};
202
203const buildDownloadArtifacts = async (
204 request: BuildDownloadRequest,
205): Promise<number> => {
206 const { id } = request.metadata;
207 const [staticPackage, variablePackage] = await Promise.all([
208 request.staticVersion
209 ? readPackageArchive(id, request.staticVersion, false)
210 : undefined,
211 request.variableVersion
212 ? readPackageArchive(id, request.variableVersion, true)
213 : undefined,
214 ]);
215 const packageWithLicense = staticPackage ?? variablePackage;
216 if (!packageWithLicense) {
217 throw new Error(`No package versions provided for ${id}`);
218 }
219 const license = getPackageFile(packageWithLicense, 'LICENSE');
220 const staticArtifacts =
221 request.staticVersion && staticPackage
222 ? await buildStaticArtifacts(
223 { id, version: request.staticVersion },
224 staticPackage,
225 )
226 : [];
227 const variableArtifacts =
228 request.variableVersion && variablePackage
229 ? buildVariableArtifacts(
230 { id, version: request.variableVersion },
231 variablePackage,
232 )
233 : [];
234 if (request.staticVersion && staticArtifacts.length === 0) {
235 throw new Error(
236 `No static artifacts published for ${id}@${request.staticVersion}`,
237 );
238 }
239 if (request.variableVersion && variableArtifacts.length === 0) {
240 throw new Error(
241 `No variable artifacts published for ${id}@${request.variableVersion}`,
242 );
243 }
244
245 const artifacts = [...staticArtifacts, ...variableArtifacts];
246 const archive = zipSync(
247 Object.fromEntries([
248 ...staticArtifacts.map((artifact) => [
249 `static/${id}-${artifact.filename}`,
250 artifact.extension === 'ttf'
251 ? artifact.bytes
252 : [artifact.bytes, { level: 0 }],
253 ]),
254 ...variableArtifacts.map((artifact) => [
255 `variable/${id}-${artifact.filename}`,
256 [artifact.bytes, { level: 0 }],
257 ]),
258 ['LICENSE', license],
259 ]),
260 );

Callers 1

buildArtifactsFunction · 0.85

Calls 8

putObjectFunction · 0.90
getDownloadKeyFunction · 0.90
readPackageArchiveFunction · 0.85
getPackageFileFunction · 0.85
buildStaticArtifactsFunction · 0.85
buildVariableArtifactsFunction · 0.85
uploadArtifactsFunction · 0.85
errorMethod · 0.65

Tested by

no test coverage detected