electron-incremental-update 1.3.0 → 2.0.0-beta.2
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 +7 -3
- package/dist/chunk-BG22XZAB.js +257 -0
- package/dist/decrypt-D9WdXYjH.d.cts +4 -0
- package/dist/decrypt-D9WdXYjH.d.ts +4 -0
- package/dist/index.cjs +164 -303
- package/dist/index.d.cts +81 -182
- package/dist/index.d.ts +81 -182
- package/dist/index.js +132 -237
- package/dist/provider.cjs +236 -0
- package/dist/provider.d.cts +37 -0
- package/dist/provider.d.ts +37 -0
- package/dist/provider.js +107 -0
- package/dist/types-COqp44eg.d.cts +69 -0
- package/dist/types-CPq1MrYZ.d.ts +69 -0
- package/dist/utils.cjs +159 -125
- package/dist/utils.d.cts +32 -77
- package/dist/utils.d.ts +32 -77
- package/dist/utils.js +35 -11
- package/dist/{pure-GoN_3MEj.d.cts → version-CffZWDhZ.d.cts} +8 -7
- package/dist/{pure-GoN_3MEj.d.ts → version-CffZWDhZ.d.ts} +8 -7
- package/dist/vite.js +101 -136
- package/package.json +13 -7
- package/provider.d.ts +1 -0
- package/provider.js +1 -0
- package/dist/chunk-7ET4GMTZ.js +0 -236
- package/dist/chunk-CXHA5TF7.js +0 -236
- package/dist/chunk-HWUYTDEF.js +0 -236
- package/dist/chunk-RQCTJY4L.js +0 -236
- package/dist/chunk-SBPTSLG7.js +0 -235
- package/dist/vite.d.ts +0 -372
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/provider/index.ts
|
|
21
|
+
var provider_exports = {};
|
|
22
|
+
__export(provider_exports, {
|
|
23
|
+
GitHubProvider: () => GitHubProvider,
|
|
24
|
+
downloadAsarBufferDefault: () => downloadAsarBufferDefault,
|
|
25
|
+
downloadUpdateJSONDefault: () => downloadUpdateJSONDefault
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(provider_exports);
|
|
28
|
+
|
|
29
|
+
// src/utils/electron.ts
|
|
30
|
+
var import_node_fs = require("fs");
|
|
31
|
+
var import_node_path = require("path");
|
|
32
|
+
var import_electron = require("electron");
|
|
33
|
+
var isDev = __EIU_IS_DEV__;
|
|
34
|
+
var isWin = process.platform === "win32";
|
|
35
|
+
var isMac = process.platform === "darwin";
|
|
36
|
+
var isLinux = process.platform === "linux";
|
|
37
|
+
function waitAppReady(timeout = 1e3) {
|
|
38
|
+
return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
39
|
+
const _ = setTimeout(() => {
|
|
40
|
+
reject(new Error("app is not ready"));
|
|
41
|
+
}, timeout);
|
|
42
|
+
import_electron.app.whenReady().then(() => {
|
|
43
|
+
clearTimeout(_);
|
|
44
|
+
resolve();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/utils/zip.ts
|
|
50
|
+
var import_node_fs2 = require("fs");
|
|
51
|
+
var import_node_zlib = require("zlib");
|
|
52
|
+
|
|
53
|
+
// src/utils/unzip.ts
|
|
54
|
+
var import_node_fs3 = require("fs");
|
|
55
|
+
var import_node_zlib2 = require("zlib");
|
|
56
|
+
|
|
57
|
+
// src/utils/version.ts
|
|
58
|
+
function parseVersion(version) {
|
|
59
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
|
|
60
|
+
if (!match) {
|
|
61
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
62
|
+
}
|
|
63
|
+
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
64
|
+
const ret = {
|
|
65
|
+
major,
|
|
66
|
+
minor,
|
|
67
|
+
patch,
|
|
68
|
+
stage: "",
|
|
69
|
+
stageVersion: -1
|
|
70
|
+
};
|
|
71
|
+
if (match[4]) {
|
|
72
|
+
let [stage, _v] = match[4].split(".");
|
|
73
|
+
ret.stage = stage;
|
|
74
|
+
ret.stageVersion = Number(_v) || -1;
|
|
75
|
+
}
|
|
76
|
+
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
77
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
78
|
+
}
|
|
79
|
+
return ret;
|
|
80
|
+
}
|
|
81
|
+
function isLowerVersionDefault(oldVer, newVer) {
|
|
82
|
+
const oldV = parseVersion(oldVer);
|
|
83
|
+
const newV = parseVersion(newVer);
|
|
84
|
+
function compareStrings(str1, str2) {
|
|
85
|
+
if (str1 === "") {
|
|
86
|
+
return str2 !== "";
|
|
87
|
+
} else if (str2 === "") {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return str1 < str2;
|
|
91
|
+
}
|
|
92
|
+
for (let key of Object.keys(oldV)) {
|
|
93
|
+
if (key === "stage" && compareStrings(oldV[key], newV[key])) {
|
|
94
|
+
return true;
|
|
95
|
+
} else if (oldV[key] !== newV[key]) {
|
|
96
|
+
return oldV[key] < newV[key];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
function isUpdateJSON(json) {
|
|
102
|
+
const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
103
|
+
return is(json) && is(json?.beta);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/utils/crypto/decrypt.ts
|
|
107
|
+
var import_node_crypto2 = require("crypto");
|
|
108
|
+
|
|
109
|
+
// src/utils/crypto/utils.ts
|
|
110
|
+
var import_node_crypto = require("crypto");
|
|
111
|
+
function hashString(data, length) {
|
|
112
|
+
const hash = (0, import_node_crypto.createHash)("SHA256").update(data).digest("binary");
|
|
113
|
+
return Buffer.from(hash).subarray(0, length);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/utils/crypto/decrypt.ts
|
|
117
|
+
function decrypt(encryptedText, key, iv) {
|
|
118
|
+
const decipher = (0, import_node_crypto2.createDecipheriv)("aes-256-cbc", key, iv);
|
|
119
|
+
let decrypted = decipher.update(encryptedText, "base64url", "utf8");
|
|
120
|
+
decrypted += decipher.final("utf8");
|
|
121
|
+
return decrypted;
|
|
122
|
+
}
|
|
123
|
+
function verifySignatureDefault(buffer, signature, cert) {
|
|
124
|
+
try {
|
|
125
|
+
const [sig, version] = decrypt(signature, hashString(cert, 32), hashString(buffer, 16)).split("%");
|
|
126
|
+
const result = (0, import_node_crypto2.createVerify)("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
127
|
+
return result ? version : void 0;
|
|
128
|
+
} catch {
|
|
129
|
+
return void 0;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/utils/crypto/encrypt.ts
|
|
134
|
+
var import_node_crypto3 = require("crypto");
|
|
135
|
+
|
|
136
|
+
// src/provider/download.ts
|
|
137
|
+
var import_electron2 = require("electron");
|
|
138
|
+
async function downlaodFn(url, headers, onResponse) {
|
|
139
|
+
await waitAppReady();
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
const request = import_electron2.net.request({ url, method: "GET", redirect: "follow" });
|
|
142
|
+
Object.keys(headers).forEach((key) => request.setHeader(key, headers[key]));
|
|
143
|
+
request.on("response", (resp) => {
|
|
144
|
+
resp.on("aborted", () => reject(new Error("aborted")));
|
|
145
|
+
resp.on("error", () => reject(new Error("download error")));
|
|
146
|
+
onResponse(resp, resolve, reject);
|
|
147
|
+
});
|
|
148
|
+
request.on("error", reject);
|
|
149
|
+
request.end();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async function downloadUpdateJSONDefault(url, headers) {
|
|
153
|
+
return await downlaodFn(url, headers, (resp, resolve, reject) => {
|
|
154
|
+
let data = "";
|
|
155
|
+
resp.on("data", (chunk) => data += chunk);
|
|
156
|
+
resp.on("end", () => {
|
|
157
|
+
try {
|
|
158
|
+
const json = JSON.parse(data);
|
|
159
|
+
if (isUpdateJSON(json)) {
|
|
160
|
+
resolve(json);
|
|
161
|
+
} else {
|
|
162
|
+
throw Error;
|
|
163
|
+
}
|
|
164
|
+
} catch {
|
|
165
|
+
reject(new Error("invalid update json"));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
async function downloadAsarBufferDefault(url, headers, total, onDownloading) {
|
|
171
|
+
let transferred = 0;
|
|
172
|
+
let time = Date.now();
|
|
173
|
+
return await downlaodFn(url, headers, (resp, resolve) => {
|
|
174
|
+
let data = [];
|
|
175
|
+
resp.on("data", (chunk) => {
|
|
176
|
+
transferred += chunk.length;
|
|
177
|
+
const current = Date.now();
|
|
178
|
+
onDownloading?.({
|
|
179
|
+
percent: +(transferred / total).toFixed(2) * 100,
|
|
180
|
+
total,
|
|
181
|
+
transferred,
|
|
182
|
+
delta: chunk.length,
|
|
183
|
+
bps: chunk.length / ((current - time) * 1e3)
|
|
184
|
+
});
|
|
185
|
+
time = current;
|
|
186
|
+
data.push(chunk);
|
|
187
|
+
});
|
|
188
|
+
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/provider/github.ts
|
|
193
|
+
var GitHubProvider = class {
|
|
194
|
+
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
|
|
195
|
+
name = "GithubProvider";
|
|
196
|
+
urlHandler;
|
|
197
|
+
url;
|
|
198
|
+
extraHeaders;
|
|
199
|
+
constructor(options) {
|
|
200
|
+
this.url = new URL(options.url);
|
|
201
|
+
this.extraHeaders = options.extraHeaders;
|
|
202
|
+
this.urlHandler = options.urlHandler;
|
|
203
|
+
if (this.url.host !== "github.com") {
|
|
204
|
+
throw new Error(`${this.name}: invalid github url: ${options.url}`);
|
|
205
|
+
}
|
|
206
|
+
if (!this.url.pathname.endsWith("/")) {
|
|
207
|
+
this.url.pathname += "/";
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
parseURL(isDownloadAsar, path) {
|
|
211
|
+
const url = this.url.href + path;
|
|
212
|
+
return this.urlHandler ? this.urlHandler(url, isDownloadAsar) : url;
|
|
213
|
+
}
|
|
214
|
+
isLowerVersion = isLowerVersionDefault;
|
|
215
|
+
verifySignaure = verifySignatureDefault;
|
|
216
|
+
async downloadJSON(versionPath) {
|
|
217
|
+
return await downloadUpdateJSONDefault(
|
|
218
|
+
this.parseURL(false, `HEAD/${versionPath}`),
|
|
219
|
+
{ userAgent: this.ua, accept: "application/json", ...this.extraHeaders }
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
async downloadAsar(name, { version, size }, onDownloading) {
|
|
223
|
+
return await downloadAsarBufferDefault(
|
|
224
|
+
this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
|
|
225
|
+
{ userAgent: this.ua, accept: "application/octet-stream", ...this.extraHeaders },
|
|
226
|
+
size,
|
|
227
|
+
onDownloading
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
232
|
+
0 && (module.exports = {
|
|
233
|
+
GitHubProvider,
|
|
234
|
+
downloadAsarBufferDefault,
|
|
235
|
+
downloadUpdateJSONDefault
|
|
236
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { i as isLowerVersionDefault, U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.cjs';
|
|
2
|
+
import { v as verifySignatureDefault } from './decrypt-D9WdXYjH.cjs';
|
|
3
|
+
import { U as URLHandler, I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-COqp44eg.cjs';
|
|
4
|
+
import '@subframe7536/type-utils';
|
|
5
|
+
|
|
6
|
+
interface GitHubProviderOptions {
|
|
7
|
+
/**
|
|
8
|
+
* github repo root url
|
|
9
|
+
* @example 'https://github.com/electron/electron'
|
|
10
|
+
*/
|
|
11
|
+
url: string;
|
|
12
|
+
extraHeaders?: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* custom url handler
|
|
15
|
+
*
|
|
16
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
|
|
17
|
+
*/
|
|
18
|
+
urlHandler?: URLHandler;
|
|
19
|
+
}
|
|
20
|
+
declare class GitHubProvider implements IProvider {
|
|
21
|
+
private ua;
|
|
22
|
+
name: string;
|
|
23
|
+
urlHandler?: URLHandler;
|
|
24
|
+
private url;
|
|
25
|
+
private extraHeaders?;
|
|
26
|
+
constructor(options: GitHubProviderOptions);
|
|
27
|
+
private parseURL;
|
|
28
|
+
isLowerVersion: typeof isLowerVersionDefault;
|
|
29
|
+
verifySignaure: typeof verifySignatureDefault;
|
|
30
|
+
downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
31
|
+
downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare function downloadUpdateJSONDefault(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
|
|
35
|
+
declare function downloadAsarBufferDefault(url: string, headers: Record<string, any>, total: number, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
36
|
+
|
|
37
|
+
export { DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, downloadAsarBufferDefault, downloadUpdateJSONDefault };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { i as isLowerVersionDefault, U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.js';
|
|
2
|
+
import { v as verifySignatureDefault } from './decrypt-D9WdXYjH.js';
|
|
3
|
+
import { U as URLHandler, I as IProvider, D as DownloadingInfo, O as OnDownloading } from './types-CPq1MrYZ.js';
|
|
4
|
+
import '@subframe7536/type-utils';
|
|
5
|
+
|
|
6
|
+
interface GitHubProviderOptions {
|
|
7
|
+
/**
|
|
8
|
+
* github repo root url
|
|
9
|
+
* @example 'https://github.com/electron/electron'
|
|
10
|
+
*/
|
|
11
|
+
url: string;
|
|
12
|
+
extraHeaders?: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* custom url handler
|
|
15
|
+
*
|
|
16
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
|
|
17
|
+
*/
|
|
18
|
+
urlHandler?: URLHandler;
|
|
19
|
+
}
|
|
20
|
+
declare class GitHubProvider implements IProvider {
|
|
21
|
+
private ua;
|
|
22
|
+
name: string;
|
|
23
|
+
urlHandler?: URLHandler;
|
|
24
|
+
private url;
|
|
25
|
+
private extraHeaders?;
|
|
26
|
+
constructor(options: GitHubProviderOptions);
|
|
27
|
+
private parseURL;
|
|
28
|
+
isLowerVersion: typeof isLowerVersionDefault;
|
|
29
|
+
verifySignaure: typeof verifySignatureDefault;
|
|
30
|
+
downloadJSON(versionPath: string): Promise<UpdateJSON>;
|
|
31
|
+
downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare function downloadUpdateJSONDefault(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
|
|
35
|
+
declare function downloadAsarBufferDefault(url: string, headers: Record<string, any>, total: number, onDownloading?: OnDownloading): Promise<Buffer>;
|
|
36
|
+
|
|
37
|
+
export { DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, downloadAsarBufferDefault, downloadUpdateJSONDefault };
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isLowerVersionDefault,
|
|
3
|
+
isUpdateJSON,
|
|
4
|
+
verifySignatureDefault,
|
|
5
|
+
waitAppReady
|
|
6
|
+
} from "./chunk-BG22XZAB.js";
|
|
7
|
+
|
|
8
|
+
// src/provider/download.ts
|
|
9
|
+
import { net } from "electron";
|
|
10
|
+
async function downlaodFn(url, headers, onResponse) {
|
|
11
|
+
await waitAppReady();
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const request = net.request({ url, method: "GET", redirect: "follow" });
|
|
14
|
+
Object.keys(headers).forEach((key) => request.setHeader(key, headers[key]));
|
|
15
|
+
request.on("response", (resp) => {
|
|
16
|
+
resp.on("aborted", () => reject(new Error("aborted")));
|
|
17
|
+
resp.on("error", () => reject(new Error("download error")));
|
|
18
|
+
onResponse(resp, resolve, reject);
|
|
19
|
+
});
|
|
20
|
+
request.on("error", reject);
|
|
21
|
+
request.end();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function downloadUpdateJSONDefault(url, headers) {
|
|
25
|
+
return await downlaodFn(url, headers, (resp, resolve, reject) => {
|
|
26
|
+
let data = "";
|
|
27
|
+
resp.on("data", (chunk) => data += chunk);
|
|
28
|
+
resp.on("end", () => {
|
|
29
|
+
try {
|
|
30
|
+
const json = JSON.parse(data);
|
|
31
|
+
if (isUpdateJSON(json)) {
|
|
32
|
+
resolve(json);
|
|
33
|
+
} else {
|
|
34
|
+
throw Error;
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
reject(new Error("invalid update json"));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async function downloadAsarBufferDefault(url, headers, total, onDownloading) {
|
|
43
|
+
let transferred = 0;
|
|
44
|
+
let time = Date.now();
|
|
45
|
+
return await downlaodFn(url, headers, (resp, resolve) => {
|
|
46
|
+
let data = [];
|
|
47
|
+
resp.on("data", (chunk) => {
|
|
48
|
+
transferred += chunk.length;
|
|
49
|
+
const current = Date.now();
|
|
50
|
+
onDownloading?.({
|
|
51
|
+
percent: +(transferred / total).toFixed(2) * 100,
|
|
52
|
+
total,
|
|
53
|
+
transferred,
|
|
54
|
+
delta: chunk.length,
|
|
55
|
+
bps: chunk.length / ((current - time) * 1e3)
|
|
56
|
+
});
|
|
57
|
+
time = current;
|
|
58
|
+
data.push(chunk);
|
|
59
|
+
});
|
|
60
|
+
resp.on("end", () => resolve(Buffer.concat(data)));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/provider/github.ts
|
|
65
|
+
var GitHubProvider = class {
|
|
66
|
+
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
|
|
67
|
+
name = "GithubProvider";
|
|
68
|
+
urlHandler;
|
|
69
|
+
url;
|
|
70
|
+
extraHeaders;
|
|
71
|
+
constructor(options) {
|
|
72
|
+
this.url = new URL(options.url);
|
|
73
|
+
this.extraHeaders = options.extraHeaders;
|
|
74
|
+
this.urlHandler = options.urlHandler;
|
|
75
|
+
if (this.url.host !== "github.com") {
|
|
76
|
+
throw new Error(`${this.name}: invalid github url: ${options.url}`);
|
|
77
|
+
}
|
|
78
|
+
if (!this.url.pathname.endsWith("/")) {
|
|
79
|
+
this.url.pathname += "/";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
parseURL(isDownloadAsar, path) {
|
|
83
|
+
const url = this.url.href + path;
|
|
84
|
+
return this.urlHandler ? this.urlHandler(url, isDownloadAsar) : url;
|
|
85
|
+
}
|
|
86
|
+
isLowerVersion = isLowerVersionDefault;
|
|
87
|
+
verifySignaure = verifySignatureDefault;
|
|
88
|
+
async downloadJSON(versionPath) {
|
|
89
|
+
return await downloadUpdateJSONDefault(
|
|
90
|
+
this.parseURL(false, `HEAD/${versionPath}`),
|
|
91
|
+
{ userAgent: this.ua, accept: "application/json", ...this.extraHeaders }
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
async downloadAsar(name, { version, size }, onDownloading) {
|
|
95
|
+
return await downloadAsarBufferDefault(
|
|
96
|
+
this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
|
|
97
|
+
{ userAgent: this.ua, accept: "application/octet-stream", ...this.extraHeaders },
|
|
98
|
+
size,
|
|
99
|
+
onDownloading
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
export {
|
|
104
|
+
GitHubProvider,
|
|
105
|
+
downloadAsarBufferDefault,
|
|
106
|
+
downloadUpdateJSONDefault
|
|
107
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.cjs';
|
|
3
|
+
|
|
4
|
+
type URLHandler = (url: string, isDownloadAsar: boolean) => string;
|
|
5
|
+
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
6
|
+
interface DownloadingInfo {
|
|
7
|
+
/**
|
|
8
|
+
* download delta
|
|
9
|
+
*/
|
|
10
|
+
delta: number;
|
|
11
|
+
/**
|
|
12
|
+
* downloaded percent, 0 ~ 100
|
|
13
|
+
*/
|
|
14
|
+
percent: number;
|
|
15
|
+
/**
|
|
16
|
+
* total size
|
|
17
|
+
*/
|
|
18
|
+
total: number;
|
|
19
|
+
/**
|
|
20
|
+
* downloaded size
|
|
21
|
+
*/
|
|
22
|
+
transferred: number;
|
|
23
|
+
/**
|
|
24
|
+
* download speed, bytes per second
|
|
25
|
+
*/
|
|
26
|
+
bps: number;
|
|
27
|
+
}
|
|
28
|
+
interface IProvider {
|
|
29
|
+
/**
|
|
30
|
+
* provider name
|
|
31
|
+
*/
|
|
32
|
+
name: string;
|
|
33
|
+
/**
|
|
34
|
+
* custom url handler
|
|
35
|
+
*
|
|
36
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
|
|
37
|
+
*/
|
|
38
|
+
urlHandler?: URLHandler;
|
|
39
|
+
onDownloading?: OnDownloading;
|
|
40
|
+
/**
|
|
41
|
+
* download update json
|
|
42
|
+
* @param versionPath parsed version path
|
|
43
|
+
*/
|
|
44
|
+
downloadJSON: (versionPath: string) => Promise<UpdateJSON>;
|
|
45
|
+
/**
|
|
46
|
+
* download update asar
|
|
47
|
+
* @param name app name
|
|
48
|
+
* @param updateInfo existing update info
|
|
49
|
+
* @param onDownloading hook for on downloading
|
|
50
|
+
*/
|
|
51
|
+
downloadAsar: (name: string, updateInfo: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
52
|
+
/**
|
|
53
|
+
* compare version
|
|
54
|
+
* @param oldVer old version string
|
|
55
|
+
* @param newVer new version string
|
|
56
|
+
* @returns if version1 < version2
|
|
57
|
+
*/
|
|
58
|
+
isLowerVersion: (oldVer: string, newVer: string) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* verify asar signature
|
|
61
|
+
* @param buffer file buffer
|
|
62
|
+
* @param signature signature
|
|
63
|
+
* @param cert certificate
|
|
64
|
+
* @returns if signature is valid, returns the version, otherwise returns `undefined`
|
|
65
|
+
*/
|
|
66
|
+
verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, URLHandler as U };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { U as UpdateJSON, a as UpdateInfo } from './version-CffZWDhZ.js';
|
|
3
|
+
|
|
4
|
+
type URLHandler = (url: string, isDownloadAsar: boolean) => string;
|
|
5
|
+
type OnDownloading = (progress: DownloadingInfo) => void;
|
|
6
|
+
interface DownloadingInfo {
|
|
7
|
+
/**
|
|
8
|
+
* download delta
|
|
9
|
+
*/
|
|
10
|
+
delta: number;
|
|
11
|
+
/**
|
|
12
|
+
* downloaded percent, 0 ~ 100
|
|
13
|
+
*/
|
|
14
|
+
percent: number;
|
|
15
|
+
/**
|
|
16
|
+
* total size
|
|
17
|
+
*/
|
|
18
|
+
total: number;
|
|
19
|
+
/**
|
|
20
|
+
* downloaded size
|
|
21
|
+
*/
|
|
22
|
+
transferred: number;
|
|
23
|
+
/**
|
|
24
|
+
* download speed, bytes per second
|
|
25
|
+
*/
|
|
26
|
+
bps: number;
|
|
27
|
+
}
|
|
28
|
+
interface IProvider {
|
|
29
|
+
/**
|
|
30
|
+
* provider name
|
|
31
|
+
*/
|
|
32
|
+
name: string;
|
|
33
|
+
/**
|
|
34
|
+
* custom url handler
|
|
35
|
+
*
|
|
36
|
+
* for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
|
|
37
|
+
*/
|
|
38
|
+
urlHandler?: URLHandler;
|
|
39
|
+
onDownloading?: OnDownloading;
|
|
40
|
+
/**
|
|
41
|
+
* download update json
|
|
42
|
+
* @param versionPath parsed version path
|
|
43
|
+
*/
|
|
44
|
+
downloadJSON: (versionPath: string) => Promise<UpdateJSON>;
|
|
45
|
+
/**
|
|
46
|
+
* download update asar
|
|
47
|
+
* @param name app name
|
|
48
|
+
* @param updateInfo existing update info
|
|
49
|
+
* @param onDownloading hook for on downloading
|
|
50
|
+
*/
|
|
51
|
+
downloadAsar: (name: string, updateInfo: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
|
|
52
|
+
/**
|
|
53
|
+
* compare version
|
|
54
|
+
* @param oldVer old version string
|
|
55
|
+
* @param newVer new version string
|
|
56
|
+
* @returns if version1 < version2
|
|
57
|
+
*/
|
|
58
|
+
isLowerVersion: (oldVer: string, newVer: string) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* verify asar signature
|
|
61
|
+
* @param buffer file buffer
|
|
62
|
+
* @param signature signature
|
|
63
|
+
* @param cert certificate
|
|
64
|
+
* @returns if signature is valid, returns the version, otherwise returns `undefined`
|
|
65
|
+
*/
|
|
66
|
+
verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, URLHandler as U };
|