Skip to content

Commit

Permalink
默认不使用代理
Browse files Browse the repository at this point in the history
  • Loading branch information
terryso committed Dec 25, 2024
1 parent 164fb59 commit 2ba57f3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ ins-grab download --help
- `-u, --username`: Single account username
- `-t, --types`: Media types to download (image,video)
- `-m, --max-items`: Maximum items to download
- `-p, --proxy`: Proxy URL
- `-p, --proxy`: Proxy URL (optional)
- `--timeout`: Request timeout in milliseconds

4 changes: 4 additions & 0 deletions base/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class Request {
};

if (this.proxy) {
console.log(`使用代理: ${this.proxy}`);
reqOptions.agent = new HttpsProxyAgent(this.proxy);
}

Expand All @@ -54,6 +55,9 @@ export class Request {
if (error.type === 'request-timeout') {
throw new Error(`请求超时 (${this.timeout}ms): ${url}`);
}
if (this.proxy && error.code === 'ECONNREFUSED') {
throw new Error(`代理连接失败: ${this.proxy}`);
}
throw error;
}
}
Expand Down
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ program
.option('-u, --username <username>', 'Single account username')
.option('-t, --types <types>', 'Media types to download (image,video)', 'image,video')
.option('-m, --max-items <number>', 'Maximum items to download', '100')
.option('-p, --proxy <url>', 'Proxy URL', 'http://127.0.0.1:7890')
.option('-p, --proxy <url>', 'Proxy URL (optional)')
.option('--timeout <ms>', 'Request timeout in milliseconds', '30000')
.action(async (options) => {
try {
Expand Down

0 comments on commit 2ba57f3

Please sign in to comment.