-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
KeygenProvider.ts
49 lines (43 loc) · 1.94 KB
/
KeygenProvider.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
import { CancellationToken, KeygenOptions, newError, UpdateInfo } from "builder-util-runtime"
import { AppUpdater } from "../AppUpdater"
import { ResolvedUpdateFileInfo } from "../main"
import { getChannelFilename, newBaseUrl, newUrlFromBase } from "../util"
import { parseUpdateInfo, Provider, ProviderRuntimeOptions, resolveFiles } from "./Provider"
export class KeygenProvider extends Provider<UpdateInfo> {
private readonly baseUrl: URL
constructor(private readonly configuration: KeygenOptions, private readonly updater: AppUpdater, runtimeOptions: ProviderRuntimeOptions) {
super({
...runtimeOptions,
isUseMultipleRangeRequest: false,
})
this.baseUrl = newBaseUrl(`https://api.keygen.sh/v1/accounts/${this.configuration.account}/artifacts`)
}
private get channel(): string {
return this.updater.channel || this.configuration.channel || "stable"
}
async getLatestVersion(): Promise<UpdateInfo> {
const cancellationToken = new CancellationToken()
const channelFile = getChannelFilename(this.getCustomChannelName(this.channel))
const channelUrl = newUrlFromBase(channelFile, this.baseUrl, this.updater.isAddNoCacheQuery)
try {
const updateInfo = await this.httpRequest(
channelUrl,
{
Accept: "application/vnd.api+json",
"Keygen-Version": "1.0",
},
cancellationToken
)
return parseUpdateInfo(updateInfo, channelFile, channelUrl)
} catch (e) {
throw newError(`Unable to find latest version on ${this.toString()}, please ensure release exists: ${e.stack || e.message}`, "ERR_UPDATER_LATEST_VERSION_NOT_FOUND")
}
}
resolveFiles(updateInfo: UpdateInfo): Array<ResolvedUpdateFileInfo> {
return resolveFiles(updateInfo, this.baseUrl)
}
toString() {
const { account, product, platform } = this.configuration
return `Keygen (account: ${account}, product: ${product}, platform: ${platform}, channel: ${this.channel})`
}
}