Skip to content

Commit 2cc305d

Browse files
authored
fix: update response shape, fix signature logic
1 parent 5eed622 commit 2cc305d

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/getPlatform.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,24 @@ function extname(filename: string) {
5959
export async function findAssetSignature(
6060
fileName: string,
6161
assets: any[],
62-
): Promise<string | null> {
62+
): Promise<string | undefined> {
6363
// check in our assets if we have a file: `fileName.sig`
6464
// by example fileName can be: App-1.0.0.zip
6565
const matches = [
6666
`${fileName.toLowerCase()}.gz.sig`,
67-
`${fileName.toLowerCase()}.zip.sig`,
67+
`${fileName.toLowerCase()}.sig`,
6868
]
6969
const foundSignature = assets.find((asset) =>
70-
matches.includes(asset.name.toLowerCase()),
70+
asset.name.toLowerCase() === `${fileName.toLowerCase()}.sig`,
7171
)
7272

7373
if (!foundSignature) {
74-
return null
74+
return undefined
7575
}
7676

7777
const response = await fetch(foundSignature.browser_download_url)
7878
if (response.status !== 200) {
79-
return null
79+
return undefined
8080
}
8181
const signature = await response.text()
8282
return signature

src/handler.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ import {
77
import semverValid from 'semver/functions/valid'
88
import semverGt from 'semver/functions/gt'
99

10+
11+
type TauriUpdateResponse = {
12+
url: string,
13+
version: string,
14+
notes?: string,
15+
pub_date?: string,
16+
signature?: string
17+
}
18+
1019
const GITHUB_ACCOUNT = 'killeencode'
1120
const GITHUB_REPO = 'brancato'
1221
export async function handleRequest(request: Request): Promise<Response> {
@@ -39,6 +48,7 @@ export async function handleRequest(request: Request): Promise<Response> {
3948
if (!remoteVersion || !semverValid(remoteVersion)) {
4049
return new Response('Not found', { status: 404 })
4150
}
51+
4252
const shouldUpdate = semverGt(remoteVersion, version)
4353
if (!shouldUpdate) {
4454
return new Response(null, { status: 204 })
@@ -53,15 +63,15 @@ export async function handleRequest(request: Request): Promise<Response> {
5363

5464
// try to find signature for this asset
5565
const signature = await findAssetSignature(name, release.assets)
56-
66+
const data : TauriUpdateResponse = {
67+
url: browser_download_url,
68+
version: remoteVersion,
69+
notes: release.body,
70+
pub_date: release.published_at,
71+
signature,
72+
}
5773
return new Response(
58-
JSON.stringify({
59-
name: release.tag_name,
60-
notes: release.body,
61-
pub_date: release.published_at,
62-
signature,
63-
url: browser_download_url,
64-
}),
74+
JSON.stringify(data),
6575
{ headers: { 'Content-Type': 'application/json; charset=utf-8' } },
6676
)
6777
}

0 commit comments

Comments
 (0)