Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tx3-bang-reader
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
tx3-bang-reader
Commits
f5b9360d
Commit
f5b9360d
authored
Jul 01, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check proxy
parent
31890961
Pipeline
#210
passed with stages
in 1 minute and 23 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
7 deletions
+25
-7
src/proxy.ts
src/proxy.ts
+25
-7
No files found.
src/proxy.ts
View file @
f5b9360d
import
axios
,
{
AxiosProxyConfig
,
AxiosRequestConfig
}
from
"
axios
"
;
const
proxySourceList
=
[
"
http://www.89ip.cn/tqdl.html?api=1&num=9999
"
,
"
http://www.66ip.cn/mo.php?tqsl=9999
"
]
for
(
let
i
=
1
;
i
<=
2000
;
++
i
)
{
proxySourceList
.
push
(
`http://www.xiladaili.com/http/
${
i
}
/`
);
}
export
class
ProxyFetcher
{
proxies
:
AxiosProxyConfig
[];
counter
:
number
;
...
...
@@ -11,7 +19,7 @@ export class ProxyFetcher {
if
(
process
.
env
.
NO_PROXY
)
{
return
;
}
while
(
true
)
{
//
while (true) {
try
{
const
proxyPage
:
string
=
(
await
axios
.
get
(
url
,
{
responseType
:
"
document
"
...
...
@@ -20,17 +28,27 @@ export class ProxyFetcher {
for
(
let
proxyString
of
proxyMatches
)
{
const
[
host
,
_port
]
=
proxyString
.
split
(
"
:
"
);
const
port
=
parseInt
(
_port
);
this
.
proxies
.
push
({
host
,
port
});
const
proxy
=
{
host
,
port
};
let
isProxyUsable
=
false
;
try
{
await
axios
.
get
(
"
http://mirrors.aliyun.com/debian/pool
"
,
{
proxy
});
isProxyUsable
=
true
;
}
catch
(
e
)
{
console
.
error
(
`Proxy
${
proxyString
}
is broken:
${
e
.
toString
()}
`
);
}
if
(
isProxyUsable
)
{
this
.
proxies
.
push
(
proxy
);
}
}
console
.
error
(
`Got
${
proxyMatches
.
length
}
proxies from
${
url
}
.`
);
return
;
}
catch
(
e
)
{
console
.
error
(
`Failed fetching proxy list from
${
url
}
:
${
e
.
toString
()}
`
)
}
}
//
}
}
async
initProxies
()
{
await
Promise
.
all
([
"
http://www.89ip.cn/tqdl.html?api=1&num=9999
"
,
"
http://www.66ip.cn/mo.php?tqsl=9999
"
].
map
((
m
)
=>
{
await
Promise
.
race
([
"
http://www.89ip.cn/tqdl.html?api=1&num=9999
"
,
"
http://www.66ip.cn/mo.php?tqsl=9999
"
].
map
((
m
)
=>
{
return
this
.
initProxiesFrom
(
m
);
}));
}
...
...
@@ -52,10 +70,10 @@ export class ProxyFetcher {
})).
data
;
return
data
;
}
catch
(
e
)
{
/*
if (!process.env.NO_PROXY) {
if
(
!
process
.
env
.
NO_PROXY
)
{
this
.
proxies
.
splice
(
proxyIndex
,
1
);
}
*/
console
.
error
(
`Failed fetching data from
${
url
}
:
${
e
.
toString
()}
`
)
}
console
.
error
(
`Failed fetching data from
${
url
}
:
${
e
.
toString
()}
${
this
.
proxies
.
length
}
proxies left.
`
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment