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
ff5abf31
Commit
ff5abf31
authored
Jul 01, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update proxy check
parent
f5b9360d
Pipeline
#211
passed with stages
in 1 minute and 26 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
25 deletions
+38
-25
src/proxy.ts
src/proxy.ts
+38
-25
No files found.
src/proxy.ts
View file @
ff5abf31
...
...
@@ -8,6 +8,24 @@ for (let i = 1; i <= 2000; ++i) {
proxySourceList
.
push
(
`http://www.xiladaili.com/http/
${
i
}
/`
);
}
async
function
checkProxy
(
proxy
:
AxiosProxyConfig
)
{
let
isProxyUsable
=
false
;
try
{
await
axios
.
get
(
"
http://mirrors.aliyun.com/debian/pool
"
,
{
proxy
});
isProxyUsable
=
true
;
}
catch
(
e
)
{
console
.
error
(
`Proxy
${
proxy
.
host
}
is broken:
${
e
.
toString
()}
`
);
}
return
isProxyUsable
;
}
async
function
filterProxies
(
proxies
:
AxiosProxyConfig
[])
{
const
proxiesUsableList
=
await
Promise
.
all
(
proxies
.
map
(
checkProxy
));
return
proxies
.
filter
((
proxy
,
index
)
=>
{
return
proxiesUsableList
[
index
];
});
}
export
class
ProxyFetcher
{
proxies
:
AxiosProxyConfig
[];
counter
:
number
;
...
...
@@ -19,36 +37,31 @@ export class ProxyFetcher {
if
(
process
.
env
.
NO_PROXY
)
{
return
;
}
console
.
log
(
`Fetching proxies from
${
url
}
.`
)
//while (true) {
try
{
const
proxyPage
:
string
=
(
await
axios
.
get
(
url
,
{
responseType
:
"
document
"
})).
data
;
const
proxyMatches
:
string
[]
=
proxyPage
.
match
(
/
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
:
\d{1,5}
/g
);
for
(
let
proxyString
of
proxyMatches
)
{
const
[
host
,
_port
]
=
proxyString
.
split
(
"
:
"
);
const
port
=
parseInt
(
_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
()}
`
)
try
{
const
proxyPage
:
string
=
(
await
axios
.
get
(
url
,
{
responseType
:
"
document
"
})).
data
;
const
proxies
:
AxiosProxyConfig
[]
=
proxyPage
.
match
(
/
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
:
\d{1,5}
/g
).
map
(
proxyString
=>
{
const
[
host
,
_port
]
=
proxyString
.
split
(
"
:
"
);
const
port
=
parseInt
(
_port
);
const
proxy
=
{
host
,
port
};
return
proxy
;
});
const
usableProxies
=
await
filterProxies
(
proxies
);
for
(
let
proxy
of
usableProxies
)
{
this
.
proxies
.
push
(
proxy
);
}
console
.
error
(
`Got
${
usableProxies
.
length
}
proxies from
${
url
}
.`
);
return
;
}
catch
(
e
)
{
console
.
error
(
`Failed fetching proxy list from
${
url
}
:
${
e
.
toString
()}
`
)
}
//}
}
async
initProxies
()
{
await
Promise
.
race
(
[
"
http://www.89ip.cn/tqdl.html?api=1&num=9999
"
,
"
http://www.66ip.cn/mo.php?tqsl=9999
"
]
.
map
((
m
)
=>
{
await
Promise
.
race
(
proxySourceList
.
map
((
m
)
=>
{
return
this
.
initProxiesFrom
(
m
);
}));
}
...
...
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