Spaces:
Paused
Paused
fix(tvchak): findLiveDomain도 NAS 프록시로 — play 15초 지연 제거
Browse files진단: /api/diag/proxy는 0.6초인데 /api/play는 15초. 원인은 fetchPlay가 부르는 findLiveDomain의 캐시검증/probe/announce가 여전히 Playwright(SOCKS5) 경로라 거기서 5~15초 소모(큰 ClientHello desync 지연). tvFetch만 프록시로 바꾸고 findLiveDomain은 안 바꿔서 누락.
findLiveDomain의 캐시검증 probe + announce fetch + 후보 probe 전부 nasFetch로 교체. 이제 play 전 경로가 프록시 사용.
server.js
CHANGED
|
@@ -1402,16 +1402,13 @@ async function findLiveDomain() {
|
|
| 1402 |
const cached = readCache('domain.json', 3600);
|
| 1403 |
if (cached && cached.domain) {
|
| 1404 |
try {
|
| 1405 |
-
// 캐시된
|
| 1406 |
-
const
|
| 1407 |
-
const
|
| 1408 |
-
timeout: 5000, maxRedirects: 0, failOnStatusCode: false,
|
| 1409 |
-
});
|
| 1410 |
-
const body = (await resp.text()) || '';
|
| 1411 |
const fakeLanderSig = /window\.location\.href\s*=\s*["']\/lander/i.test(body);
|
| 1412 |
const realSiteSig = /player_aaaa|vodlist|vod\/play|tvchak/i.test(body);
|
| 1413 |
-
if (
|
| 1414 |
-
console.warn(`[findLiveDomain] cached ${cached.domain} dead/fake (status=${
|
| 1415 |
} catch (e) {
|
| 1416 |
console.warn(`[findLiveDomain] cached ${cached.domain} probe error — rediscovering: ${e.message}`);
|
| 1417 |
}
|
|
@@ -1437,13 +1434,12 @@ async function findLiveDomain() {
|
|
| 1437 |
}
|
| 1438 |
|
| 1439 |
async function _findLiveDomainImpl(stale) {
|
| 1440 |
-
const ctx = await getContext();
|
| 1441 |
-
const p = await ctx.newPage();
|
| 1442 |
let announced = null;
|
| 1443 |
let counts = {};
|
| 1444 |
try {
|
| 1445 |
-
|
| 1446 |
-
const
|
|
|
|
| 1447 |
const re = /tvchak(\d+)\.com/gi;
|
| 1448 |
let m;
|
| 1449 |
while ((m = re.exec(html))) counts[m[1]] = (counts[m[1]] || 0) + 1;
|
|
@@ -1451,8 +1447,6 @@ async function _findLiveDomainImpl(stale) {
|
|
| 1451 |
if (best) announced = `tvchak${best[0]}.com`;
|
| 1452 |
} catch (e) {
|
| 1453 |
console.warn('domain detect failed:', e.message);
|
| 1454 |
-
} finally {
|
| 1455 |
-
await p.close().catch(() => {});
|
| 1456 |
}
|
| 1457 |
|
| 1458 |
// announce된 도메인 + 인접 번호를 후보군으로 만들어 실제 살아있는 도메인 선택.
|
|
@@ -1480,23 +1474,17 @@ async function _findLiveDomainImpl(stale) {
|
|
| 1480 |
// 후보들을 차례로 probe — context.request.get으로 본문까지 확인.
|
| 1481 |
// tvchak.org가 인접 번호에 가짜 lander 도메인을 깔아두는 패턴 발견 → 단순 200 판정 금지.
|
| 1482 |
// 진짜 tvchak는 본문에 maccms 마커("player_aaaa" or "vodlist" 등) 또는 사이트 navbar 존재.
|
| 1483 |
-
// probe
|
| 1484 |
-
const tvCtx = await getTvContext();
|
| 1485 |
let domain = null;
|
| 1486 |
let probeTrace = [];
|
| 1487 |
for (const cand of candidates.slice(0, 12)) {
|
| 1488 |
try {
|
| 1489 |
-
const
|
| 1490 |
-
|
| 1491 |
-
maxRedirects: 0,
|
| 1492 |
-
failOnStatusCode: false,
|
| 1493 |
-
});
|
| 1494 |
-
const status = resp.status();
|
| 1495 |
-
const body = (await resp.text()) || '';
|
| 1496 |
const fakeLanderSig = /window\.location\.href\s*=\s*["']\/lander/i.test(body);
|
| 1497 |
const realSiteSig = /player_aaaa|vodlist|vod\/play|tvchak/i.test(body);
|
| 1498 |
-
const isReal =
|
| 1499 |
-
probeTrace.push(`${cand}=${status}${fakeLanderSig ? ':lander' : ''}${realSiteSig ? ':real' : ''}`);
|
| 1500 |
if (isReal) {
|
| 1501 |
domain = cand;
|
| 1502 |
break;
|
|
|
|
| 1402 |
const cached = readCache('domain.json', 3600);
|
| 1403 |
if (cached && cached.domain) {
|
| 1404 |
try {
|
| 1405 |
+
// 캐시된 도메인 검증도 NAS fetch 프록시로 (SOCKS5 raw TLS 병목 회피).
|
| 1406 |
+
const r = await nasFetch(`https://${cached.domain}/`, 6000);
|
| 1407 |
+
const body = r.body || '';
|
|
|
|
|
|
|
|
|
|
| 1408 |
const fakeLanderSig = /window\.location\.href\s*=\s*["']\/lander/i.test(body);
|
| 1409 |
const realSiteSig = /player_aaaa|vodlist|vod\/play|tvchak/i.test(body);
|
| 1410 |
+
if (r.ok && !fakeLanderSig && realSiteSig) return cached;
|
| 1411 |
+
console.warn(`[findLiveDomain] cached ${cached.domain} dead/fake (ok=${r.ok} status=${r.status} lander=${fakeLanderSig} real=${realSiteSig}) — rediscovering`);
|
| 1412 |
} catch (e) {
|
| 1413 |
console.warn(`[findLiveDomain] cached ${cached.domain} probe error — rediscovering: ${e.message}`);
|
| 1414 |
}
|
|
|
|
| 1434 |
}
|
| 1435 |
|
| 1436 |
async function _findLiveDomainImpl(stale) {
|
|
|
|
|
|
|
| 1437 |
let announced = null;
|
| 1438 |
let counts = {};
|
| 1439 |
try {
|
| 1440 |
+
// announce 페이지도 NAS 프록시로 (SOCKS5 raw TLS 병목 회피).
|
| 1441 |
+
const r = await nasFetch('https://tvchak.org/', 10000);
|
| 1442 |
+
const html = r.body || '';
|
| 1443 |
const re = /tvchak(\d+)\.com/gi;
|
| 1444 |
let m;
|
| 1445 |
while ((m = re.exec(html))) counts[m[1]] = (counts[m[1]] || 0) + 1;
|
|
|
|
| 1447 |
if (best) announced = `tvchak${best[0]}.com`;
|
| 1448 |
} catch (e) {
|
| 1449 |
console.warn('domain detect failed:', e.message);
|
|
|
|
|
|
|
| 1450 |
}
|
| 1451 |
|
| 1452 |
// announce된 도메인 + 인접 번호를 후보군으로 만들어 실제 살아있는 도메인 선택.
|
|
|
|
| 1474 |
// 후보들을 차례로 probe — context.request.get으로 본문까지 확인.
|
| 1475 |
// tvchak.org가 인접 번호에 가짜 lander 도메인을 깔아두는 패턴 발견 → 단순 200 판정 금지.
|
| 1476 |
// 진짜 tvchak는 본문에 maccms 마커("player_aaaa" or "vodlist" 등) 또는 사이트 navbar 존재.
|
| 1477 |
+
// probe도 NAS fetch 프록시로 (SOCKS5 raw TLS 병목 회피, KT SNI는 NAS zapret이 처리).
|
|
|
|
| 1478 |
let domain = null;
|
| 1479 |
let probeTrace = [];
|
| 1480 |
for (const cand of candidates.slice(0, 12)) {
|
| 1481 |
try {
|
| 1482 |
+
const r = await nasFetch(`https://${cand}/`, 6000);
|
| 1483 |
+
const body = r.body || '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1484 |
const fakeLanderSig = /window\.location\.href\s*=\s*["']\/lander/i.test(body);
|
| 1485 |
const realSiteSig = /player_aaaa|vodlist|vod\/play|tvchak/i.test(body);
|
| 1486 |
+
const isReal = r.ok && !fakeLanderSig && realSiteSig;
|
| 1487 |
+
probeTrace.push(`${cand}=${r.status}${fakeLanderSig ? ':lander' : ''}${realSiteSig ? ':real' : ''}`);
|
| 1488 |
if (isReal) {
|
| 1489 |
domain = cand;
|
| 1490 |
break;
|