From 0aadeb07760b4c85a066454ede7fd35ae07b4454 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sun, 24 Mar 2024 19:11:24 +0000 Subject: [PATCH] feat: Add signature asset find and include in response --- .../tauri/[version]/[target]/[arch]/route.ts | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/apps/web/app/api/releases/tauri/[version]/[target]/[arch]/route.ts b/apps/web/app/api/releases/tauri/[version]/[target]/[arch]/route.ts index acdac9e3..f8a38bd0 100644 --- a/apps/web/app/api/releases/tauri/[version]/[target]/[arch]/route.ts +++ b/apps/web/app/api/releases/tauri/[version]/[target]/[arch]/route.ts @@ -28,7 +28,6 @@ export async function GET( ? new Date(release.published_at).toISOString() : null; - // Filter the assets based on version, target, and arch const asset = release.assets.find((asset) => { const isVersionMatch = asset.name.includes(version); const isArchMatch = asset.name.includes(params.arch); @@ -48,14 +47,38 @@ export async function GET( return isVersionMatch && isArchMatch && isTargetMatch; }); - const url = asset ? asset.browser_download_url : null; + if (!asset) { + return new Response(null, { + status: 204, + }); + } - return new Response(JSON.stringify({ version, notes, pub_date, url }), { - status: 200, - headers: { - "Content-Type": "application/json", - }, - }); + const rawAssetName = asset.name.split(".").slice(0, -1).join("."); + + const url = asset.browser_download_url; + const signatureAsset = release.assets.find( + ({ name }: any) => name === `${rawAssetName}.sig` + ); + + if (!signatureAsset) { + return new Response(null, { + status: 204, + }); + } + + const signature = await fetch(signatureAsset.browser_download_url).then( + (r) => r.text() + ); + + return new Response( + JSON.stringify({ version, notes, pub_date, url, signature }), + { + status: 200, + headers: { + "Content-Type": "application/json", + }, + } + ); } catch (error) { console.error("Error fetching latest release:", error); return new Response(JSON.stringify({ error: "Missing required fields" }), {