electron-incremental-update 2.0.0-beta.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +307 -198
- package/dist/chunk-IABBXJFB.js +87 -0
- package/dist/{chunk-72ZAJ7AF.js → chunk-RCRKUKFX.js} +1 -1
- package/dist/index.cjs +110 -104
- package/dist/index.d.cts +139 -34
- package/dist/index.d.ts +139 -34
- package/dist/index.js +105 -102
- package/dist/provider.cjs +85 -54
- package/dist/provider.d.cts +62 -29
- package/dist/provider.d.ts +62 -29
- package/dist/provider.js +85 -55
- package/dist/types-BLdN9rkY.d.ts +72 -0
- package/dist/types-DkCn03M3.d.cts +72 -0
- package/dist/utils.cjs +25 -25
- package/dist/utils.d.cts +37 -24
- package/dist/utils.d.ts +37 -24
- package/dist/utils.js +2 -11
- package/dist/version-BYVQ367i.d.cts +62 -0
- package/dist/version-BYVQ367i.d.ts +62 -0
- package/dist/vite.d.ts +58 -94
- package/dist/vite.js +67 -55
- package/dist/{zip-DPF5IFkK.d.cts → zip-rm9ED9nU.d.cts} +23 -0
- package/dist/{zip-DPF5IFkK.d.ts → zip-rm9ED9nU.d.ts} +23 -0
- package/package.json +10 -7
- package/dist/chunk-4MH6ZXCY.js +0 -81
- package/dist/core-DJdvtwvU.d.ts +0 -134
- package/dist/core-ZUlLHadf.d.cts +0 -134
- package/dist/types-CItP6bL-.d.cts +0 -104
- package/dist/types-CItP6bL-.d.ts +0 -104
package/dist/provider.d.cts
CHANGED
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { URL } from 'node:url';
|
|
2
|
+
import { Promisable, Arrayable } from '@subframe7536/type-utils';
|
|
3
|
+
import { d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo } from './version-BYVQ367i.cjs';
|
|
4
|
+
import { I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-DkCn03M3.cjs';
|
|
5
|
+
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.cjs';
|
|
4
6
|
|
|
5
7
|
declare abstract class BaseProvider implements IProvider {
|
|
6
8
|
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* @inheritdoc
|
|
11
|
+
*/
|
|
7
12
|
isLowerVersion: typeof defaultIsLowerVersion;
|
|
13
|
+
/**
|
|
14
|
+
* @inheritdoc
|
|
15
|
+
*/
|
|
8
16
|
verifySignaure: typeof defaultVerifySignature;
|
|
17
|
+
/**
|
|
18
|
+
* @inheritdoc
|
|
19
|
+
*/
|
|
9
20
|
unzipFile: typeof defaultUnzipFile;
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @inheritdoc
|
|
23
|
+
*/
|
|
24
|
+
abstract downloadJSON(versionPath: string, signal: AbortSignal): Promise<UpdateJSON>;
|
|
25
|
+
/**
|
|
26
|
+
* @inheritdoc
|
|
27
|
+
*/
|
|
28
|
+
abstract downloadAsar(name: string, info: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
12
29
|
}
|
|
13
30
|
|
|
31
|
+
type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
|
|
14
32
|
interface GitHubProviderOptions {
|
|
15
33
|
/**
|
|
16
|
-
*
|
|
34
|
+
* Github user name
|
|
17
35
|
*/
|
|
18
|
-
|
|
36
|
+
user: string;
|
|
19
37
|
/**
|
|
20
|
-
*
|
|
38
|
+
* Github repo name
|
|
21
39
|
*/
|
|
22
40
|
repo: string;
|
|
23
41
|
/**
|
|
24
|
-
*
|
|
42
|
+
* Github branch name that fetch version
|
|
25
43
|
* @default 'HEAD'
|
|
26
44
|
*/
|
|
27
45
|
branch?: string;
|
|
28
46
|
/**
|
|
29
|
-
*
|
|
47
|
+
* Extra headers
|
|
30
48
|
*/
|
|
31
49
|
extraHeaders?: Record<string, string>;
|
|
32
50
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
|
|
51
|
+
* Custom url handler ({@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 some public CDN links})
|
|
36
52
|
* @example
|
|
37
|
-
* (url
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* return url
|
|
42
|
-
* }
|
|
53
|
+
* (url) => {
|
|
54
|
+
* url.hostname = 'mirror.ghproxy.com'
|
|
55
|
+
* url.pathname = 'https://github.com' + url.pathname
|
|
56
|
+
* return url
|
|
43
57
|
* }
|
|
44
58
|
*/
|
|
45
59
|
urlHandler?: URLHandler;
|
|
@@ -49,28 +63,47 @@ declare class GitHubProvider extends BaseProvider {
|
|
|
49
63
|
private options;
|
|
50
64
|
/**
|
|
51
65
|
* Update Provider for Github repo
|
|
52
|
-
* - download update json from `https://
|
|
66
|
+
* - download update json from `https://github.com/{user}/{repo}/raw/HEAD/{versionPath}`
|
|
53
67
|
* - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
|
|
54
68
|
*
|
|
55
|
-
* you can setup `urlHandler` in {@link GitHubProviderOptions}
|
|
69
|
+
* you can setup `urlHandler` in {@link GitHubProviderOptions} to modify url before request
|
|
56
70
|
* @param options provider options
|
|
57
71
|
*/
|
|
58
72
|
constructor(options: GitHubProviderOptions);
|
|
59
73
|
get urlHandler(): URLHandler | undefined;
|
|
60
74
|
set urlHandler(handler: URLHandler);
|
|
61
75
|
private parseURL;
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
/**
|
|
77
|
+
* @inheritdoc
|
|
78
|
+
*/
|
|
79
|
+
downloadJSON(versionPath: string, signal: AbortSignal): Promise<UpdateJSON>;
|
|
80
|
+
/**
|
|
81
|
+
* @inheritdoc
|
|
82
|
+
*/
|
|
83
|
+
downloadAsar(name: string, info: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
64
84
|
}
|
|
65
85
|
|
|
66
|
-
declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
|
|
67
86
|
/**
|
|
68
|
-
*
|
|
87
|
+
* Safe get value from header
|
|
88
|
+
* @param headers response header
|
|
89
|
+
* @param key target header key
|
|
90
|
+
*/
|
|
91
|
+
declare function getHeader(headers: Record<string, Arrayable<string>>, key: any): any;
|
|
92
|
+
/**
|
|
93
|
+
* Default function to download json and parse to UpdateJson
|
|
94
|
+
* @param url target url
|
|
95
|
+
* @param headers extra headers
|
|
96
|
+
* @param signal abort signal
|
|
69
97
|
*/
|
|
70
|
-
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any
|
|
98
|
+
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>, signal: AbortSignal): Promise<UpdateJSON>;
|
|
71
99
|
/**
|
|
72
|
-
* download asar buffer,
|
|
100
|
+
* Default function to download asar buffer,
|
|
101
|
+
* get total size from `Content-Length` header
|
|
102
|
+
* @param url target url
|
|
103
|
+
* @param headers extra headers
|
|
104
|
+
* @param signal abort signal
|
|
105
|
+
* @param onDownloading on downloading callback
|
|
73
106
|
*/
|
|
74
|
-
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
107
|
+
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
75
108
|
|
|
76
|
-
export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
|
|
109
|
+
export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, type URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { URL } from 'node:url';
|
|
2
|
+
import { Promisable, Arrayable } from '@subframe7536/type-utils';
|
|
3
|
+
import { d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo } from './version-BYVQ367i.js';
|
|
4
|
+
import { I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-BLdN9rkY.js';
|
|
5
|
+
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.js';
|
|
4
6
|
|
|
5
7
|
declare abstract class BaseProvider implements IProvider {
|
|
6
8
|
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* @inheritdoc
|
|
11
|
+
*/
|
|
7
12
|
isLowerVersion: typeof defaultIsLowerVersion;
|
|
13
|
+
/**
|
|
14
|
+
* @inheritdoc
|
|
15
|
+
*/
|
|
8
16
|
verifySignaure: typeof defaultVerifySignature;
|
|
17
|
+
/**
|
|
18
|
+
* @inheritdoc
|
|
19
|
+
*/
|
|
9
20
|
unzipFile: typeof defaultUnzipFile;
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @inheritdoc
|
|
23
|
+
*/
|
|
24
|
+
abstract downloadJSON(versionPath: string, signal: AbortSignal): Promise<UpdateJSON>;
|
|
25
|
+
/**
|
|
26
|
+
* @inheritdoc
|
|
27
|
+
*/
|
|
28
|
+
abstract downloadAsar(name: string, info: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
12
29
|
}
|
|
13
30
|
|
|
31
|
+
type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
|
|
14
32
|
interface GitHubProviderOptions {
|
|
15
33
|
/**
|
|
16
|
-
*
|
|
34
|
+
* Github user name
|
|
17
35
|
*/
|
|
18
|
-
|
|
36
|
+
user: string;
|
|
19
37
|
/**
|
|
20
|
-
*
|
|
38
|
+
* Github repo name
|
|
21
39
|
*/
|
|
22
40
|
repo: string;
|
|
23
41
|
/**
|
|
24
|
-
*
|
|
42
|
+
* Github branch name that fetch version
|
|
25
43
|
* @default 'HEAD'
|
|
26
44
|
*/
|
|
27
45
|
branch?: string;
|
|
28
46
|
/**
|
|
29
|
-
*
|
|
47
|
+
* Extra headers
|
|
30
48
|
*/
|
|
31
49
|
extraHeaders?: Record<string, string>;
|
|
32
50
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
|
|
51
|
+
* Custom url handler ({@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 some public CDN links})
|
|
36
52
|
* @example
|
|
37
|
-
* (url
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* return url
|
|
42
|
-
* }
|
|
53
|
+
* (url) => {
|
|
54
|
+
* url.hostname = 'mirror.ghproxy.com'
|
|
55
|
+
* url.pathname = 'https://github.com' + url.pathname
|
|
56
|
+
* return url
|
|
43
57
|
* }
|
|
44
58
|
*/
|
|
45
59
|
urlHandler?: URLHandler;
|
|
@@ -49,28 +63,47 @@ declare class GitHubProvider extends BaseProvider {
|
|
|
49
63
|
private options;
|
|
50
64
|
/**
|
|
51
65
|
* Update Provider for Github repo
|
|
52
|
-
* - download update json from `https://
|
|
66
|
+
* - download update json from `https://github.com/{user}/{repo}/raw/HEAD/{versionPath}`
|
|
53
67
|
* - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
|
|
54
68
|
*
|
|
55
|
-
* you can setup `urlHandler` in {@link GitHubProviderOptions}
|
|
69
|
+
* you can setup `urlHandler` in {@link GitHubProviderOptions} to modify url before request
|
|
56
70
|
* @param options provider options
|
|
57
71
|
*/
|
|
58
72
|
constructor(options: GitHubProviderOptions);
|
|
59
73
|
get urlHandler(): URLHandler | undefined;
|
|
60
74
|
set urlHandler(handler: URLHandler);
|
|
61
75
|
private parseURL;
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
/**
|
|
77
|
+
* @inheritdoc
|
|
78
|
+
*/
|
|
79
|
+
downloadJSON(versionPath: string, signal: AbortSignal): Promise<UpdateJSON>;
|
|
80
|
+
/**
|
|
81
|
+
* @inheritdoc
|
|
82
|
+
*/
|
|
83
|
+
downloadAsar(name: string, info: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
64
84
|
}
|
|
65
85
|
|
|
66
|
-
declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
|
|
67
86
|
/**
|
|
68
|
-
*
|
|
87
|
+
* Safe get value from header
|
|
88
|
+
* @param headers response header
|
|
89
|
+
* @param key target header key
|
|
90
|
+
*/
|
|
91
|
+
declare function getHeader(headers: Record<string, Arrayable<string>>, key: any): any;
|
|
92
|
+
/**
|
|
93
|
+
* Default function to download json and parse to UpdateJson
|
|
94
|
+
* @param url target url
|
|
95
|
+
* @param headers extra headers
|
|
96
|
+
* @param signal abort signal
|
|
69
97
|
*/
|
|
70
|
-
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any
|
|
98
|
+
declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>, signal: AbortSignal): Promise<UpdateJSON>;
|
|
71
99
|
/**
|
|
72
|
-
* download asar buffer,
|
|
100
|
+
* Default function to download asar buffer,
|
|
101
|
+
* get total size from `Content-Length` header
|
|
102
|
+
* @param url target url
|
|
103
|
+
* @param headers extra headers
|
|
104
|
+
* @param signal abort signal
|
|
105
|
+
* @param onDownloading on downloading callback
|
|
73
106
|
*/
|
|
74
|
-
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
107
|
+
declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
75
108
|
|
|
76
|
-
export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
|
|
109
|
+
export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, type URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
|
package/dist/provider.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { defaultVerifySignature, defaultUnzipFile } from './chunk-KZSYEXLO.js';
|
|
2
|
-
import { defaultIsLowerVersion, isUpdateJSON } from './chunk-
|
|
2
|
+
import { defaultIsLowerVersion, isUpdateJSON } from './chunk-RCRKUKFX.js';
|
|
3
3
|
import { URL } from 'node:url';
|
|
4
|
-
import
|
|
4
|
+
import electron from 'electron';
|
|
5
5
|
|
|
6
|
-
function getHeader(
|
|
7
|
-
const value =
|
|
6
|
+
function getHeader(headers, key) {
|
|
7
|
+
const value = headers[key];
|
|
8
8
|
if (Array.isArray(value)) {
|
|
9
9
|
return value.length === 0 ? null : value[value.length - 1];
|
|
10
10
|
} else {
|
|
11
11
|
return value;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
async function downloadFn(url, headers, onResponse) {
|
|
15
|
-
await app.whenReady();
|
|
14
|
+
async function downloadFn(url, headers, signal, onResponse) {
|
|
15
|
+
await electron.app.whenReady();
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
17
|
-
const request = net.request({ url, method: "GET", redirect: "follow" });
|
|
18
|
-
|
|
17
|
+
const request = electron.net.request({ url, method: "GET", redirect: "follow", headers, cache: "no-cache" });
|
|
18
|
+
signal.addEventListener("abort", () => request.abort(), { once: true });
|
|
19
19
|
request.on("response", (resp) => {
|
|
20
20
|
resp.on("aborted", () => reject(new Error("aborted")));
|
|
21
21
|
resp.on("error", () => reject(new Error("download error")));
|
|
@@ -25,53 +25,72 @@ async function downloadFn(url, headers, onResponse) {
|
|
|
25
25
|
request.end();
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
async function defaultDownloadUpdateJSON(url, headers) {
|
|
29
|
-
return await downloadFn(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
async function defaultDownloadUpdateJSON(url, headers, signal) {
|
|
29
|
+
return await downloadFn(
|
|
30
|
+
url,
|
|
31
|
+
headers,
|
|
32
|
+
signal,
|
|
33
|
+
(resp, resolve, reject) => {
|
|
34
|
+
let data = "";
|
|
35
|
+
resp.on("data", (chunk) => data += chunk);
|
|
36
|
+
resp.on("end", () => {
|
|
37
|
+
try {
|
|
38
|
+
const json = JSON.parse(data);
|
|
39
|
+
if (isUpdateJSON(json)) {
|
|
40
|
+
resolve(json);
|
|
41
|
+
} else {
|
|
42
|
+
throw Error;
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
reject(new Error(`Invalid update json, "${data}"`));
|
|
39
46
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
);
|
|
45
50
|
}
|
|
46
|
-
async function defaultDownloadAsar(url, headers, onDownloading) {
|
|
51
|
+
async function defaultDownloadAsar(url, headers, signal, onDownloading) {
|
|
47
52
|
let transferred = 0;
|
|
48
53
|
let time = Date.now();
|
|
49
|
-
return await downloadFn(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
return await downloadFn(
|
|
55
|
+
url,
|
|
56
|
+
headers,
|
|
57
|
+
signal,
|
|
58
|
+
(resp, resolve) => {
|
|
59
|
+
const total = +getHeader(resp.headers, "content-length") || -1;
|
|
60
|
+
const data = [];
|
|
61
|
+
resp.on("data", (chunk) => {
|
|
62
|
+
const delta = chunk.length;
|
|
63
|
+
transferred += delta;
|
|
64
|
+
const current = Date.now();
|
|
65
|
+
onDownloading?.({
|
|
66
|
+
percent: total ? +(transferred / total).toFixed(2) * 100 : -1,
|
|
67
|
+
total,
|
|
68
|
+
transferred,
|
|
69
|
+
delta,
|
|
70
|
+
bps: delta / (current - time)
|
|
71
|
+
});
|
|
72
|
+
time = current;
|
|
73
|
+
data.push(chunk);
|
|
62
74
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
67
|
-
});
|
|
75
|
+
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
76
|
+
}
|
|
77
|
+
);
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
// src/provider/base.ts
|
|
71
81
|
var BaseProvider = class {
|
|
72
82
|
name = "BaseProvider";
|
|
83
|
+
/**
|
|
84
|
+
* @inheritdoc
|
|
85
|
+
*/
|
|
73
86
|
isLowerVersion = defaultIsLowerVersion;
|
|
87
|
+
/**
|
|
88
|
+
* @inheritdoc
|
|
89
|
+
*/
|
|
74
90
|
verifySignaure = defaultVerifySignature;
|
|
91
|
+
/**
|
|
92
|
+
* @inheritdoc
|
|
93
|
+
*/
|
|
75
94
|
unzipFile = defaultUnzipFile;
|
|
76
95
|
};
|
|
77
96
|
|
|
@@ -81,15 +100,18 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
81
100
|
options;
|
|
82
101
|
/**
|
|
83
102
|
* Update Provider for Github repo
|
|
84
|
-
* - download update json from `https://
|
|
103
|
+
* - download update json from `https://github.com/{user}/{repo}/raw/HEAD/{versionPath}`
|
|
85
104
|
* - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
|
|
86
105
|
*
|
|
87
|
-
* you can setup `urlHandler` in {@link GitHubProviderOptions}
|
|
106
|
+
* you can setup `urlHandler` in {@link GitHubProviderOptions} to modify url before request
|
|
88
107
|
* @param options provider options
|
|
89
108
|
*/
|
|
90
109
|
constructor(options) {
|
|
91
110
|
super();
|
|
92
111
|
this.options = options;
|
|
112
|
+
if (!options.branch) {
|
|
113
|
+
this.options.branch = "HEAD";
|
|
114
|
+
}
|
|
93
115
|
}
|
|
94
116
|
get urlHandler() {
|
|
95
117
|
return this.options.urlHandler;
|
|
@@ -97,23 +119,31 @@ var GitHubProvider = class extends BaseProvider {
|
|
|
97
119
|
set urlHandler(handler) {
|
|
98
120
|
this.options.urlHandler = handler;
|
|
99
121
|
}
|
|
100
|
-
async parseURL(
|
|
122
|
+
async parseURL(extraPath) {
|
|
101
123
|
const url = new URL(
|
|
102
|
-
`/${this.options.
|
|
103
|
-
"https://
|
|
124
|
+
`/${this.options.user}/${this.options.repo}/${extraPath}`,
|
|
125
|
+
"https://github.com"
|
|
104
126
|
);
|
|
105
|
-
return (await this.urlHandler?.(url
|
|
127
|
+
return (await this.urlHandler?.(url) || url).toString();
|
|
106
128
|
}
|
|
107
|
-
|
|
129
|
+
/**
|
|
130
|
+
* @inheritdoc
|
|
131
|
+
*/
|
|
132
|
+
async downloadJSON(versionPath, signal) {
|
|
108
133
|
return await defaultDownloadUpdateJSON(
|
|
109
|
-
await this.parseURL(
|
|
110
|
-
{
|
|
134
|
+
await this.parseURL(`raw/${this.options.branch}/${versionPath}`),
|
|
135
|
+
{ Accept: "application/json", ...this.options.extraHeaders },
|
|
136
|
+
signal
|
|
111
137
|
);
|
|
112
138
|
}
|
|
113
|
-
|
|
139
|
+
/**
|
|
140
|
+
* @inheritdoc
|
|
141
|
+
*/
|
|
142
|
+
async downloadAsar(name, info, signal, onDownloading) {
|
|
114
143
|
return await defaultDownloadAsar(
|
|
115
|
-
await this.parseURL(
|
|
116
|
-
{
|
|
144
|
+
await this.parseURL(`releases/download/v${info.version}/${name}-${info.version}.asar.gz`),
|
|
145
|
+
{ Accept: "application/octet-stream", ...this.options.extraHeaders },
|
|
146
|
+
signal,
|
|
117
147
|
onDownloading
|
|
118
148
|
);
|
|
119
149
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { a as UpdateJSON, U as UpdateInfo } from './version-BYVQ367i.js';
|
|
3
|
+
|
|
4
|
+
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
5
|
+
interface DownloadingInfo {
|
|
6
|
+
/**
|
|
7
|
+
* Download buffer delta
|
|
8
|
+
*/
|
|
9
|
+
delta: number;
|
|
10
|
+
/**
|
|
11
|
+
* Downloaded percent, 0 ~ 100
|
|
12
|
+
*
|
|
13
|
+
* If no `Content-Length` header, will be -1
|
|
14
|
+
*/
|
|
15
|
+
percent: number;
|
|
16
|
+
/**
|
|
17
|
+
* Total size
|
|
18
|
+
*
|
|
19
|
+
* If not `Content-Length` header, will be -1
|
|
20
|
+
*/
|
|
21
|
+
total: number;
|
|
22
|
+
/**
|
|
23
|
+
* Downloaded size
|
|
24
|
+
*/
|
|
25
|
+
transferred: number;
|
|
26
|
+
/**
|
|
27
|
+
* Download speed, bytes per second
|
|
28
|
+
*/
|
|
29
|
+
bps: number;
|
|
30
|
+
}
|
|
31
|
+
interface IProvider {
|
|
32
|
+
/**
|
|
33
|
+
* Provider name
|
|
34
|
+
*/
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* Download update json
|
|
38
|
+
* @param versionPath parsed version path in project
|
|
39
|
+
* @param signal abort signal
|
|
40
|
+
*/
|
|
41
|
+
downloadJSON: (versionPath: string, signal: AbortSignal) => Promise<UpdateJSON>;
|
|
42
|
+
/**
|
|
43
|
+
* Download update asar
|
|
44
|
+
* @param name app name
|
|
45
|
+
* @param updateInfo existing update info
|
|
46
|
+
* @param signal abort signal
|
|
47
|
+
* @param onDownloading hook for on downloading
|
|
48
|
+
*/
|
|
49
|
+
downloadAsar: (name: string, updateInfo: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
50
|
+
/**
|
|
51
|
+
* Check the old version is less than new version
|
|
52
|
+
* @param oldVer old version string
|
|
53
|
+
* @param newVer new version string
|
|
54
|
+
*/
|
|
55
|
+
isLowerVersion: (oldVer: string, newVer: string) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Function to decompress file using brotli
|
|
58
|
+
* @param buffer compressed file buffer
|
|
59
|
+
*/
|
|
60
|
+
unzipFile: (buffer: Buffer) => Promise<Buffer>;
|
|
61
|
+
/**
|
|
62
|
+
* Verify asar signature,
|
|
63
|
+
* if signature is valid, returns the version, otherwise returns `undefined`
|
|
64
|
+
* @param buffer file buffer
|
|
65
|
+
* @param version target version
|
|
66
|
+
* @param signature signature
|
|
67
|
+
* @param cert certificate
|
|
68
|
+
*/
|
|
69
|
+
verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type { DownloadingInfo as D, IProvider as I, OnDownloading as O };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { a as UpdateJSON, U as UpdateInfo } from './version-BYVQ367i.cjs';
|
|
3
|
+
|
|
4
|
+
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
5
|
+
interface DownloadingInfo {
|
|
6
|
+
/**
|
|
7
|
+
* Download buffer delta
|
|
8
|
+
*/
|
|
9
|
+
delta: number;
|
|
10
|
+
/**
|
|
11
|
+
* Downloaded percent, 0 ~ 100
|
|
12
|
+
*
|
|
13
|
+
* If no `Content-Length` header, will be -1
|
|
14
|
+
*/
|
|
15
|
+
percent: number;
|
|
16
|
+
/**
|
|
17
|
+
* Total size
|
|
18
|
+
*
|
|
19
|
+
* If not `Content-Length` header, will be -1
|
|
20
|
+
*/
|
|
21
|
+
total: number;
|
|
22
|
+
/**
|
|
23
|
+
* Downloaded size
|
|
24
|
+
*/
|
|
25
|
+
transferred: number;
|
|
26
|
+
/**
|
|
27
|
+
* Download speed, bytes per second
|
|
28
|
+
*/
|
|
29
|
+
bps: number;
|
|
30
|
+
}
|
|
31
|
+
interface IProvider {
|
|
32
|
+
/**
|
|
33
|
+
* Provider name
|
|
34
|
+
*/
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* Download update json
|
|
38
|
+
* @param versionPath parsed version path in project
|
|
39
|
+
* @param signal abort signal
|
|
40
|
+
*/
|
|
41
|
+
downloadJSON: (versionPath: string, signal: AbortSignal) => Promise<UpdateJSON>;
|
|
42
|
+
/**
|
|
43
|
+
* Download update asar
|
|
44
|
+
* @param name app name
|
|
45
|
+
* @param updateInfo existing update info
|
|
46
|
+
* @param signal abort signal
|
|
47
|
+
* @param onDownloading hook for on downloading
|
|
48
|
+
*/
|
|
49
|
+
downloadAsar: (name: string, updateInfo: UpdateInfo, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
50
|
+
/**
|
|
51
|
+
* Check the old version is less than new version
|
|
52
|
+
* @param oldVer old version string
|
|
53
|
+
* @param newVer new version string
|
|
54
|
+
*/
|
|
55
|
+
isLowerVersion: (oldVer: string, newVer: string) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Function to decompress file using brotli
|
|
58
|
+
* @param buffer compressed file buffer
|
|
59
|
+
*/
|
|
60
|
+
unzipFile: (buffer: Buffer) => Promise<Buffer>;
|
|
61
|
+
/**
|
|
62
|
+
* Verify asar signature,
|
|
63
|
+
* if signature is valid, returns the version, otherwise returns `undefined`
|
|
64
|
+
* @param buffer file buffer
|
|
65
|
+
* @param version target version
|
|
66
|
+
* @param signature signature
|
|
67
|
+
* @param cert certificate
|
|
68
|
+
*/
|
|
69
|
+
verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type { DownloadingInfo as D, IProvider as I, OnDownloading as O };
|