Skip to content
This repository was archived by the owner on May 2, 2022. It is now read-only.

Commit dd8f2ce

Browse files
authored
Fix certificate has expired (replace node-fetch with electron-fetch) (#1533)
1 parent c463e8c commit dd8f2ce

File tree

7 files changed

+107
-28
lines changed

7 files changed

+107
-28
lines changed

main-src/libs/app-management/install-app-async/install-app-forked-electron-v2.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const icongen = require('icon-gen');
2323
const Jimp = process.env.NODE_ENV === 'production' ? require('jimp').default : require('jimp');
2424
const isUrl = require('is-url');
2525
const sudo = require('sudo-prompt');
26+
const fetch = process.env.NODE_ENV === 'production' ? require('node-fetch').default : require('node-fetch');
2627

2728
const execAsync = require('../../exec-async');
28-
const downloadAsync = require('../../download-async');
2929
const checkPathInUseAsync = require('../check-path-in-use-async');
3030
const getWvvmpElectronVersion = require('../../get-wvvmp-electron-version');
3131

@@ -104,6 +104,22 @@ const sudoAsync = (prompt) => new Promise((resolve, reject) => {
104104
});
105105
});
106106

107+
// https://github.com/node-fetch/node-fetch/issues/375#issuecomment-385751664
108+
const downloadAsync = (
109+
_url, dest, fetchOpts, ...fetchArgs
110+
) => fsExtra.ensureFile(dest)
111+
.then(() => fetch(_url, fetchOpts, ...fetchArgs))
112+
.then((res) => new Promise((resolve, reject) => {
113+
const fileStream = fsExtra.createWriteStream(dest);
114+
res.body.pipe(fileStream);
115+
res.body.on('error', (err) => {
116+
reject(err);
117+
});
118+
fileStream.on('finish', () => {
119+
resolve();
120+
});
121+
}));
122+
107123
Promise.resolve()
108124
.then(() => {
109125
if (process.platform === 'win32') {

main-src/libs/app-management/prepare-engine-async/prepare-engine-forked.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const fs = require('fs-extra');
2222
const hasha = require('hasha');
2323
const path = require('path');
2424
const semver = require('semver');
25+
const fetch = process.env.NODE_ENV === 'production' ? require('node-fetch').default : require('node-fetch');
2526

26-
const customizedFetch = require('../../customized-fetch');
2727
const formatBytes = require('../../format-bytes');
2828

2929
const argv = yargsParser(process.argv.slice(1));
@@ -48,7 +48,7 @@ Promise.resolve()
4848
return JSON.parse(templateInfoJson);
4949
}
5050

51-
return customizedFetch(`https://github.com/webcatalog/webcatalog-engine/releases/download/${tagName}/template-${platform}-${arch}.json`)
51+
return fetch(`https://github.com/webcatalog/webcatalog-engine/releases/download/${tagName}/template-${platform}-${arch}.json`)
5252
.then((res) => res.json());
5353
})
5454
.then((templateInfo) => Promise.resolve()

main-src/libs/customized-fetch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4-
const fetch = process.env.NODE_ENV === 'production' ? require('node-fetch').default : require('node-fetch');
4+
const fetch = require('electron-fetch').default;
55

66
const customizedFetch = (url, opts, ...args) => fetch(url, opts, ...args);
77

main-src/libs/download-async.js

-24
This file was deleted.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"electron": "13.5.0",
5454
"electron-builder": "22.11.11",
5555
"electron-context-menu": "3.1.1",
56+
"electron-fetch": "1.7.4",
5657
"electron-notarize": "1.1.1",
5758
"electron-packager": "15.4.0",
5859
"electron-settings": "4.0.2",

public/open-source-notices.txt

+72
Original file line numberDiff line numberDiff line change
@@ -9734,6 +9734,57 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
97349734

97359735
-----
97369736

9737+
The following software may be included in this product: electron-fetch. A copy of the source code may be downloaded from https://github.com/arantes555/electron-fetch.git. This software contains the following license and notice below:
9738+
9739+
The MIT License (MIT)
9740+
9741+
Copyright (c) 2016 Mehdi Kouhen
9742+
9743+
Permission is hereby granted, free of charge, to any person obtaining a copy
9744+
of this software and associated documentation files (the "Software"), to deal
9745+
in the Software without restriction, including without limitation the rights
9746+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9747+
copies of the Software, and to permit persons to whom the Software is
9748+
furnished to do so, subject to the following conditions:
9749+
9750+
The above copyright notice and this permission notice shall be included in all
9751+
copies or substantial portions of the Software.
9752+
9753+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9754+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9755+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9756+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9757+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9758+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
9759+
SOFTWARE.
9760+
9761+
9762+
Based on node-fetch, which has the following license:
9763+
9764+
The MIT License (MIT)
9765+
9766+
Copyright (c) 2016 David Frank
9767+
9768+
Permission is hereby granted, free of charge, to any person obtaining a copy
9769+
of this software and associated documentation files (the "Software"), to deal
9770+
in the Software without restriction, including without limitation the rights
9771+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9772+
copies of the Software, and to permit persons to whom the Software is
9773+
furnished to do so, subject to the following conditions:
9774+
9775+
The above copyright notice and this permission notice shall be included in all
9776+
copies or substantial portions of the Software.
9777+
9778+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9779+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9780+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9781+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9782+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9783+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
9784+
SOFTWARE.
9785+
9786+
-----
9787+
97379788
The following software may be included in this product: electron-notarize. A copy of the source code may be downloaded from https://github.com/electron/electron-notarize.git. This software contains the following license and notice below:
97389789

97399790
Copyright 2018 Samuel Attard and contributors
@@ -10037,6 +10088,27 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1003710088

1003810089
-----
1003910090

10091+
The following software may be included in this product: encoding. A copy of the source code may be downloaded from https://github.com/andris9/encoding.git. This software contains the following license and notice below:
10092+
10093+
Copyright (c) 2012-2014 Andris Reinman
10094+
10095+
Permission is hereby granted, free of charge, to any person obtaining a copy
10096+
of this software and associated documentation files (the "Software"), to deal
10097+
in the Software without restriction, including without limitation the rights
10098+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10099+
copies of the Software, and to permit persons to whom the Software is
10100+
furnished to do so, subject to the following conditions:
10101+
10102+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10103+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10104+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10105+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
10106+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10107+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10108+
SOFTWARE.
10109+
10110+
-----
10111+
1004010112
The following software may be included in this product: envinfo. A copy of the source code may be downloaded from https://github.com/tabrindle/envinfo. This software contains the following license and notice below:
1004110113

1004210114
MIT License

yarn.lock

+14
Original file line numberDiff line numberDiff line change
@@ -6567,6 +6567,13 @@ electron-dl@^3.2.1:
65676567
pupa "^2.0.1"
65686568
unused-filename "^2.1.0"
65696569

6570+
6571+
version "1.7.4"
6572+
resolved "https://registry.yarnpkg.com/electron-fetch/-/electron-fetch-1.7.4.tgz#af975ab92a14798bfaa025f88dcd2e54a7b0b769"
6573+
integrity sha512-+fBLXEy4CJWQ5bz8dyaeSG1hD6JJ15kBZyj3eh24pIVrd3hLM47H/umffrdQfS6GZ0falF0g9JT9f3Rs6AVUhw==
6574+
dependencies:
6575+
encoding "^0.1.13"
6576+
65706577
electron-is-dev@^2.0.0:
65716578
version "2.0.0"
65726579
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-2.0.0.tgz#833487a069b8dad21425c67a19847d9064ab19bd"
@@ -6738,6 +6745,13 @@ encodeurl@^1.0.2, encodeurl@~1.0.2:
67386745
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
67396746
integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=
67406747

6748+
encoding@^0.1.13:
6749+
version "0.1.13"
6750+
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.13.tgz#56574afdd791f54a8e9b2785c0582a2d26210fa9"
6751+
integrity sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==
6752+
dependencies:
6753+
iconv-lite "^0.6.2"
6754+
67416755
end-of-stream@^1.0.0, end-of-stream@^1.1.0:
67426756
version "1.4.4"
67436757
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"

0 commit comments

Comments
 (0)