mtproto-checker 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/check.js +27 -12
- package/package.json +1 -1
package/check.js
CHANGED
|
@@ -435,7 +435,14 @@ function loadProxiesFromFile(filePath) {
|
|
|
435
435
|
async function checkProxiesFromURIs(uris, opts) {
|
|
436
436
|
const list = Array.isArray(uris) ? uris : [uris]
|
|
437
437
|
console.error(`[mtproto-checker] Loading ${list.length} source(s)...`)
|
|
438
|
+
const directProxies = []
|
|
438
439
|
const texts = await Promise.all(list.map(uri => {
|
|
440
|
+
const parsed = parseLink(uri)
|
|
441
|
+
if (parsed) {
|
|
442
|
+
console.error(` ⚡ ${parsed.server}:${parsed.port}`)
|
|
443
|
+
directProxies.push(parsed)
|
|
444
|
+
return Promise.resolve('')
|
|
445
|
+
}
|
|
439
446
|
if (/^https?:\/\//i.test(uri)) {
|
|
440
447
|
console.error(` ↓ ${uri}`)
|
|
441
448
|
return fetchText(uri).catch(err => { console.error(` ✗ Skipping ${uri}: ${err.message}`); return '' })
|
|
@@ -443,7 +450,15 @@ async function checkProxiesFromURIs(uris, opts) {
|
|
|
443
450
|
console.error(` ◈ ${uri}`)
|
|
444
451
|
return Promise.resolve(fs.readFileSync(uri, 'utf8'))
|
|
445
452
|
}))
|
|
446
|
-
const
|
|
453
|
+
const fromTexts = mergeProxies(texts)
|
|
454
|
+
const seen = new Set(fromTexts.map(p => `${p.server}:${p.port}:${p.secret}`))
|
|
455
|
+
const proxies = [...fromTexts]
|
|
456
|
+
for (const p of directProxies) {
|
|
457
|
+
const key = `${p.server}:${p.port}:${p.secret}`
|
|
458
|
+
if (seen.has(key)) continue
|
|
459
|
+
seen.add(key)
|
|
460
|
+
proxies.push(p)
|
|
461
|
+
}
|
|
447
462
|
if (proxies.length === 0) {
|
|
448
463
|
console.error('[mtproto-checker] No valid proxy links found.')
|
|
449
464
|
return []
|
|
@@ -645,9 +660,10 @@ function createServer({ auth, checkUrl, logger = console.error }) {
|
|
|
645
660
|
}
|
|
646
661
|
|
|
647
662
|
const body = await readJsonBody(req)
|
|
648
|
-
|
|
663
|
+
const uris = body.url || body.urls || body.uri || body.uris
|
|
664
|
+
if (!uris || (typeof uris === 'string' && uris.trim() === '') || (Array.isArray(uris) && uris.length === 0)) {
|
|
649
665
|
statusCode = 400
|
|
650
|
-
jsonResponse(res, statusCode, { error: 'Request body must include url' })
|
|
666
|
+
jsonResponse(res, statusCode, { error: 'Request body must include url (string or array)' })
|
|
651
667
|
return
|
|
652
668
|
}
|
|
653
669
|
const iterations = body.iterations === undefined ? 1 : body.iterations
|
|
@@ -663,10 +679,10 @@ function createServer({ auth, checkUrl, logger = console.error }) {
|
|
|
663
679
|
return
|
|
664
680
|
}
|
|
665
681
|
|
|
666
|
-
const
|
|
682
|
+
const input = Array.isArray(uris) ? uris.map(u => u.trim()) : [uris.trim()]
|
|
667
683
|
let results
|
|
668
684
|
try {
|
|
669
|
-
results = await checkUrl(
|
|
685
|
+
results = await checkUrl(input, { iterations, concurrency })
|
|
670
686
|
} catch (err) {
|
|
671
687
|
statusCode = 502
|
|
672
688
|
jsonResponse(res, statusCode, {
|
|
@@ -675,15 +691,14 @@ function createServer({ auth, checkUrl, logger = console.error }) {
|
|
|
675
691
|
})
|
|
676
692
|
return
|
|
677
693
|
}
|
|
678
|
-
const report = toReport(results)
|
|
679
694
|
statusCode = 200
|
|
680
695
|
jsonResponse(res, statusCode, {
|
|
681
|
-
|
|
696
|
+
uris: input,
|
|
682
697
|
iterations,
|
|
683
698
|
concurrency,
|
|
684
|
-
count:
|
|
685
|
-
working:
|
|
686
|
-
results
|
|
699
|
+
count: results.length,
|
|
700
|
+
working: results.filter(item => item.ok).length,
|
|
701
|
+
results
|
|
687
702
|
})
|
|
688
703
|
} catch (err) {
|
|
689
704
|
statusCode = err.statusCode || 500
|
|
@@ -719,7 +734,7 @@ async function startServer(opts = {}) {
|
|
|
719
734
|
|
|
720
735
|
const server = createServer({
|
|
721
736
|
auth: { user, password },
|
|
722
|
-
checkUrl: async (url, requestOpts) =>
|
|
737
|
+
checkUrl: async (url, requestOpts) => checkProxiesFromURIs(url, {
|
|
723
738
|
apiId,
|
|
724
739
|
apiHash,
|
|
725
740
|
iterations: requestOpts.iterations,
|
|
@@ -804,7 +819,7 @@ async function main() {
|
|
|
804
819
|
}
|
|
805
820
|
|
|
806
821
|
module.exports = { checkProxyLink, checkProxiesFromURIs, startServer }
|
|
807
|
-
module.exports._internals = { checkRequestUrl, checkSingleUrl, configureTdlibOnce, createServer, parseArgs, resolveInputProxies, runIterativeChecks, shouldStartServer }
|
|
822
|
+
module.exports._internals = { checkRequestUrl, checkSingleUrl, configureTdlibOnce, createServer, parseArgs, resolveInputProxies, runIterativeChecks, shouldStartServer, parseLink, normalizeSecret, faketlsSni, mergeProxies, loadProxiesFromFile }
|
|
808
823
|
|
|
809
824
|
if (require.main === module) (shouldStartServer(process.argv.slice(2)) ? startServer() : main()).catch(err => {
|
|
810
825
|
console.error(err)
|