( c: Context<AppEnv>, id: string, )
| 249 | }; |
| 250 | |
| 251 | export const getDownloadAsset = async ( |
| 252 | c: Context<AppEnv>, |
| 253 | id: string, |
| 254 | ): Promise<Response> => { |
| 255 | const metadata = await getFontById(c, id); |
| 256 | if (!metadata) { |
| 257 | throw notFound('Not Found. Font does not exist.'); |
| 258 | } |
| 259 | |
| 260 | const axes = metadata.variable || undefined; |
| 261 | const [staticVersions, variableVersions] = await Promise.all([ |
| 262 | getPublishedVersions(id, false), |
| 263 | axes ? getPublishedVersions(id, true) : undefined, |
| 264 | ]); |
| 265 | const staticVersion = |
| 266 | staticVersions.length > 0 |
| 267 | ? resolveVersionTag('latest', staticVersions) |
| 268 | : undefined; |
| 269 | const variableVersion = variableVersions?.length |
| 270 | ? resolveVersionTag('latest', variableVersions) |
| 271 | : undefined; |
| 272 | const versions = staticVersion |
| 273 | ? { staticVersion, variableVersion } |
| 274 | : variableVersion |
| 275 | ? { variableVersion } |
| 276 | : undefined; |
| 277 | if (!versions) { |
| 278 | throw notFound( |
| 279 | 'Unable to resolve download: no published versions available', |
| 280 | ); |
| 281 | } |
| 282 | const downloadKey = getDownloadKey( |
| 283 | id, |
| 284 | versions.staticVersion, |
| 285 | versions.variableVersion, |
| 286 | ); |
| 287 | const readDownload = () => |
| 288 | getStoredBinaryObject(c, downloadKey, c.req.raw.headers); |
| 289 | const respond = (asset: StoredBinaryAsset) => |
| 290 | respondWithBinary(asset, { |
| 291 | cachePolicy: { |
| 292 | ...CACHE_POLICIES.floating, |
| 293 | 'Cache-Control': 'public, no-cache', |
| 294 | }, |
| 295 | contentType: 'zip', |
| 296 | filename: `${id}.zip`, |
| 297 | }); |
| 298 | |
| 299 | const existing = await readDownload(); |
| 300 | if (existing) { |
| 301 | return respond(existing); |
| 302 | } |
| 303 | |
| 304 | const build = await startDownloadBuild(c, { |
| 305 | mode: 'download', |
| 306 | ...versions, |
| 307 | metadata, |
| 308 | }); |
no test coverage detected