1
1
import {
2
+ Asset ,
2
3
checkPlatform ,
3
4
findAssetSignature ,
4
5
sanitizeVersion ,
@@ -7,17 +8,19 @@ import {
7
8
import semverValid from 'semver/functions/valid'
8
9
import semverGt from 'semver/functions/gt'
9
10
10
-
11
11
type TauriUpdateResponse = {
12
- url : string ,
13
- version : string ,
14
- notes ?: string ,
15
- pub_date ?: string ,
12
+ url : string
13
+ version : string
14
+ notes ?: string
15
+ pub_date ?: string
16
16
signature ?: string
17
17
}
18
18
19
- const GITHUB_ACCOUNT = 'killeencode'
20
- const GITHUB_REPO = 'brancato'
19
+ declare global {
20
+ const GITHUB_ACCOUNT : string
21
+ const GITHUB_REPO : string
22
+ }
23
+
21
24
export async function handleRequest ( request : Request ) : Promise < Response > {
22
25
const path = new URL ( request . url ) . pathname
23
26
const [ platform , version ] = path . slice ( 1 ) . split ( '/' )
@@ -36,8 +39,8 @@ export async function handleRequest(request: Request): Promise<Response> {
36
39
37
40
const release = ( await releaseResponse . clone ( ) . json ( ) ) as {
38
41
tag_name : string
39
- assets : any
40
- body : any
42
+ assets : Asset [ ]
43
+ body : string
41
44
published_at : string
42
45
}
43
46
if ( ! platform || ! validatePlatform ( platform ) || ! version ) {
@@ -48,7 +51,7 @@ export async function handleRequest(request: Request): Promise<Response> {
48
51
if ( ! remoteVersion || ! semverValid ( remoteVersion ) ) {
49
52
return new Response ( 'Not found' , { status : 404 } )
50
53
}
51
-
54
+
52
55
const shouldUpdate = semverGt ( remoteVersion , version )
53
56
if ( ! shouldUpdate ) {
54
57
return new Response ( null , { status : 204 } )
@@ -63,17 +66,16 @@ export async function handleRequest(request: Request): Promise<Response> {
63
66
64
67
// try to find signature for this asset
65
68
const signature = await findAssetSignature ( name , release . assets )
66
- const data : TauriUpdateResponse = {
69
+ const data : TauriUpdateResponse = {
67
70
url : browser_download_url ,
68
71
version : remoteVersion ,
69
72
notes : release . body ,
70
73
pub_date : release . published_at ,
71
74
signature,
72
75
}
73
- return new Response (
74
- JSON . stringify ( data ) ,
75
- { headers : { 'Content-Type' : 'application/json; charset=utf-8' } } ,
76
- )
76
+ return new Response ( JSON . stringify ( data ) , {
77
+ headers : { 'Content-Type' : 'application/json; charset=utf-8' } ,
78
+ } )
77
79
}
78
80
79
81
return new Response ( JSON . stringify ( { remoteVersion, version, shouldUpdate } ) )
0 commit comments