This commit is contained in:
Micooz 2018-07-01 14:24:35 +08:00
parent 6467f51723
commit de7a62f6a5
5 changed files with 1541 additions and 374 deletions

View File

@ -1,9 +1,15 @@
language: node_js
sudo: required
node_js:
- "lts/*"
- "node"
before_install:
- ./ci-install-curl.sh
- curl --version
before_deploy:
- export NEXT_VERSION=3.3.4
- export COMMIT_HASH=$(git log --format=%h -1)

17
ci-install-curl.sh Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Install any build dependencies needed for curl
sudo apt-get build-dep curl
# Get latest curl
wget http://curl.haxx.se/download/curl-7.54.0.tar.bz2
tar -xvjf curl-7.54.0.tar.bz2
cd curl-7.54.0
./configure
make
sudo make install
# Resolve any issues of C-level lib
# location caches ("shared library cache")
sudo ldconfig
cd ..

1837
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -40,20 +40,20 @@
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.5",
"babel-jest": "^23.0.1",
"babel-jest": "^23.2.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"cross-env": "^5.2.0",
"eslint": "^5.0.0",
"eslint": "^5.0.1",
"eslint-config-babel": "^7.0.2",
"eslint-plugin-babel": "^5.1.0",
"eslint-plugin-flowtype": "^2.49.3",
"jest": "^23.1.0",
"jest": "^23.2.0",
"lodash.clonedeep": "^4.5.0",
"mkdirp": "^0.5.1",
"socks": "^2.2.0"
"socks": "2.2.0"
},
"repository": {
"url": "https://github.com/blinksocks/blinksocks",

View File

@ -6,29 +6,40 @@ const exec = util.promisify(child_process.exec);
export default async function curl(args) {
const { proxyMethod = 'socks5', proxyHost, proxyPort, targetHost, targetPort } = args;
const { username, password } = args;
const proxy = {
'http': '-x',
'http_connect': '-px',
'socks': '--socks5',
'socks4': '--socks4',
'socks4a': '--socks4a',
'socks5': '--socks5-hostname',
}[proxyMethod];
try {
let command = `curl `;
let command = ['curl'];
if (username && password) {
command += `-U ${username}:${password} `;
command.push(`-U ${username}:${password}`);
}
if (proxy) {
command += `-L ${proxy} ${proxyHost}:${proxyPort} `;
switch (proxyMethod) {
case 'http':
command.push(`-x http://${proxyHost}:${proxyPort}`);
break;
case 'http_connect':
command.push(`-p -x http://${proxyHost}:${proxyPort}`);
break;
case 'https':
command.push(`--proxy-insecure -x https://${proxyHost}:${proxyPort}`);
break;
default:
const proxy = {
'socks': '--socks5',
'socks4': '--socks4',
'socks4a': '--socks4a',
'socks5': '--socks5-hostname',
}[proxyMethod];
if (proxy) {
command.push(`${proxy} ${proxyHost}:${proxyPort}`);
}
break;
}
if (proxyMethod === 'https') {
command += `--proxy-insecure -Lx https://${proxyHost}:${proxyPort} `;
command.push(`${targetHost}:${targetPort}`);
command = command.join(' ');
const { stdout, stderr } = await exec(command, { encoding: 'utf-8', timeout: 5e3 });
if (stderr) {
console.log(command);
console.log(stderr);
}
command += `${targetHost}:${targetPort} `;
// console.log(command);
const { stdout } = await exec(command, { encoding: 'utf-8', timeout: 5e3 });
return stdout;
} catch (err) {
console.log(err);