(app: Application, protocolPath: string)
| 99 | * artifact they want. |
| 100 | */ |
| 101 | export function mountProtocolRoutes(app: Application, protocolPath: string): void { |
| 102 | app.get("/protocol/", async (_req, res) => { |
| 103 | try { |
| 104 | const entries = await fs.readdir(protocolPath, { withFileTypes: true }); |
| 105 | const tarballs = entries |
| 106 | .filter( |
| 107 | (e) => |
| 108 | e.isFile() && |
| 109 | e.name.endsWith(".tgz") && |
| 110 | (e.name === "latest.tgz" || |
| 111 | semver.valid(e.name.replace(/\.tgz$/, "")) !== null), |
| 112 | ) |
| 113 | .map((e) => e.name); |
| 114 | |
| 115 | const versioned = tarballs |
| 116 | .filter((name) => name !== "latest.tgz") |
| 117 | .sort((a, b) => semver.rcompare(a.replace(/\.tgz$/, ""), b.replace(/\.tgz$/, ""))); |
| 118 | |
| 119 | const sidecarFiles = new Set( |
| 120 | entries.filter((e) => e.isFile()).map((e) => e.name), |
| 121 | ); |
| 122 | const sidecarsFor = (tarballName: string) => { |
| 123 | const sigName = `${tarballName}.sig`; |
| 124 | const crtName = `${tarballName}.crt`; |
| 125 | return { |
| 126 | signature: sidecarFiles.has(sigName) |
| 127 | ? `/protocol/${sigName}` |
| 128 | : undefined, |
| 129 | certificate: sidecarFiles.has(crtName) |
| 130 | ? `/protocol/${crtName}` |
| 131 | : undefined, |
| 132 | }; |
| 133 | }; |
| 134 | |
| 135 | let latestBlock: { |
| 136 | tarball: string; |
| 137 | checksum: string; |
| 138 | signature?: string; |
| 139 | certificate?: string; |
| 140 | adcp_version?: string; |
| 141 | generated_at?: string; |
| 142 | note: string; |
| 143 | } | null = null; |
| 144 | if (tarballs.includes("latest.tgz")) { |
| 145 | const latestPath = `${protocolPath}/latest.tgz`; |
| 146 | let generatedAt: string | undefined; |
| 147 | try { |
| 148 | const stat = await fs.stat(latestPath); |
| 149 | generatedAt = stat.mtime.toISOString(); |
| 150 | } catch { |
| 151 | // ignore — absent file is already handled upstream |
| 152 | } |
| 153 | const latestSidecars = sidecarsFor("latest.tgz"); |
| 154 | latestBlock = { |
| 155 | tarball: "/protocol/latest.tgz", |
| 156 | checksum: "/protocol/latest.tgz.sha256", |
| 157 | ...(latestSidecars.signature && { signature: latestSidecars.signature }), |
| 158 | ...(latestSidecars.certificate && { certificate: latestSidecars.certificate }), |
no test coverage detected