@@ -4,27 +4,35 @@ import { validateUpdateInfo } from "./GenericProvider"
44import * as path from "path"
55import { HttpError , request } from "electron-builder-http"
66import { CancellationToken } from "electron-builder-http/out/CancellationToken"
7+ import * as url from "url"
8+ import { RequestOptions } from "http"
79
810export 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+
914 constructor ( private readonly options : GithubOptions ) {
1015 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+ }
1123 }
1224
1325 async getLatestVersion ( ) : Promise < UpdateInfo > {
1426 const basePath = this . getBasePath ( )
1527 let version
1628
1729 const cancellationToken = new CancellationToken ( )
18- const host = this . options . host || "github.com"
19- const protocol = `${ this . options . protocol || "https" } :`
2030 try {
2131 // 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 ( {
2533 path : `${ basePath } /latest` ,
2634 headers : Object . assign ( { Accept : "application/json" } , this . requestHeaders )
27- } , cancellationToken ) )
35+ } , this . baseUrl ) , cancellationToken ) )
2836 version = ( releaseInfo . tag_name . startsWith ( "v" ) ) ? releaseInfo . tag_name . substring ( 1 ) : releaseInfo . tag_name
2937 }
3038 catch ( e ) {
@@ -35,7 +43,7 @@ export class GitHubProvider extends Provider<VersionInfo> {
3543 const channelFile = getChannelFilename ( getDefaultChannelName ( ) )
3644 const channelFileUrlPath = `${ basePath } /download/v${ version } /${ channelFile } `
3745 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 )
3947 }
4048 catch ( e ) {
4149 if ( e instanceof HttpError && e . response . statusCode === 404 ) {
@@ -65,7 +73,7 @@ export class GitHubProvider extends Provider<VersionInfo> {
6573 const name = versionInfo . githubArtifactName || path . posix . basename ( versionInfo . path ) . replace ( / / g, "-" )
6674 return {
6775 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 ) ) ,
6977 sha2 : versionInfo . sha2 ,
7078 }
7179 }
0 commit comments