@@ -4,27 +4,35 @@ import { validateUpdateInfo } from "./GenericProvider"
4
4
import * as path from "path"
5
5
import { HttpError , request } from "electron-builder-http"
6
6
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
7
+ import * as url from "url"
8
+ import { RequestOptions } from "http"
7
9
8
10
export class GitHubProvider extends Provider < VersionInfo > {
11
+ // so, we don't need to parse port (because node http doesn't support host as url does)
12
+ private readonly baseUrl : RequestOptions
13
+
9
14
constructor ( private readonly options : GithubOptions ) {
10
15
super ( )
16
+
17
+ const baseUrl = url . parse ( `${ options . protocol || "https:" } //${ options . host || "github.com" } ` )
18
+ this . baseUrl = {
19
+ protocol : baseUrl . protocol ,
20
+ hostname : baseUrl . hostname ,
21
+ port : < any > baseUrl . port ,
22
+ }
11
23
}
12
24
13
25
async getLatestVersion ( ) : Promise < UpdateInfo > {
14
26
const basePath = this . getBasePath ( )
15
27
let version
16
28
17
29
const cancellationToken = new CancellationToken ( )
18
- const host = this . options . host || "github.com"
19
- const protocol = `${ this . options . protocol || "https" } :`
20
30
try {
21
31
// do not use API to avoid limit
22
- const releaseInfo = ( await request < GithubReleaseInfo > ( {
23
- protocol : protocol ,
24
- host : host ,
32
+ const releaseInfo = ( await request < GithubReleaseInfo > ( Object . assign ( {
25
33
path : `${ basePath } /latest` ,
26
34
headers : Object . assign ( { Accept : "application/json" } , this . requestHeaders )
27
- } , cancellationToken ) )
35
+ } , this . baseUrl ) , cancellationToken ) )
28
36
version = ( releaseInfo . tag_name . startsWith ( "v" ) ) ? releaseInfo . tag_name . substring ( 1 ) : releaseInfo . tag_name
29
37
}
30
38
catch ( e ) {
@@ -35,7 +43,7 @@ export class GitHubProvider extends Provider<VersionInfo> {
35
43
const channelFile = getChannelFilename ( getDefaultChannelName ( ) )
36
44
const channelFileUrlPath = `${ basePath } /download/v${ version } /${ channelFile } `
37
45
try {
38
- result = await request < UpdateInfo > ( { protocol : protocol , host : host , path : channelFileUrlPath , headers : this . requestHeaders || undefined } , cancellationToken )
46
+ result = await request < UpdateInfo > ( Object . assign ( { path : channelFileUrlPath , headers : this . requestHeaders || undefined } , this . baseUrl ) , cancellationToken )
39
47
}
40
48
catch ( e ) {
41
49
if ( e instanceof HttpError && e . response . statusCode === 404 ) {
@@ -65,7 +73,7 @@ export class GitHubProvider extends Provider<VersionInfo> {
65
73
const name = versionInfo . githubArtifactName || path . posix . basename ( versionInfo . path ) . replace ( / / g, "-" )
66
74
return {
67
75
name : name ,
68
- url : `https://github.com ${ basePath } /download/v${ versionInfo . version } /${ name } `,
76
+ url : url . format ( Object . assign ( { pathname : ` ${ basePath } /download/v${ versionInfo . version } /${ name } `} , this . baseUrl ) ) ,
69
77
sha2 : versionInfo . sha2 ,
70
78
}
71
79
}
0 commit comments