-
Notifications
You must be signed in to change notification settings - Fork 1
/
getLatestRelease.ts
74 lines (68 loc) · 1.93 KB
/
getLatestRelease.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { GITHUB_RELEASE_URL } from './constants'
export type Release = {
platform: string
releaseUrl: string
downloadName: string | null
}
export type LatestReleaseResponse = {
assets: Array<ReleaseAsset>
}
export type ReleaseAsset = {
browser_download_url: string
name: string | null
}
export function getStoreRelease({ os }: { os: string }): Release | undefined {
const iosLink = {
platform: 'iOS',
releaseUrl: 'https://apps.apple.com/cl/app/mywitwallet/id6449979271',
downloadName: null,
}
const storeReleases: Record<string, Release> = {
iphone: iosLink,
ipad: iosLink,
android: {
platform: 'Android',
releaseUrl:
'https://play.google.com/store/apps/details?id=io.witnet.myWitWallet&hl=es_419&pli=1',
downloadName: null,
},
windows: {
platform: 'Windows',
releaseUrl: 'https://apps.microsoft.com/detail/9PN09DKWPL57',
downloadName: null,
},
}
if (storeReleases[os]) {
return storeReleases[os]
}
}
export function getLatestRelease({
os,
data,
}: {
os: string
data: LatestReleaseResponse | undefined
}): Release | null {
if (data) {
const macRelease: ReleaseAsset = data.assets.find((asset: ReleaseAsset) => {
return asset.browser_download_url.includes('myWitWallet.dmg')
}) ?? { browser_download_url: GITHUB_RELEASE_URL, name: null }
const linuxRelease: ReleaseAsset = data.assets.find((asset: ReleaseAsset) =>
asset.browser_download_url.includes('linux.tar.gz'),
) ?? { browser_download_url: GITHUB_RELEASE_URL, name: null }
const release: Record<string, Release> = {
linux: {
platform: 'GNU / Linux',
releaseUrl: linuxRelease.browser_download_url,
downloadName: linuxRelease.name,
},
macos: {
platform: 'Mac OS',
releaseUrl: macRelease.browser_download_url,
downloadName: macRelease.name,
},
}
return release[os]
}
return null
}