v-fixed43: 新增 /ipv6 线路选择页(IPv4/IPv6卡片选择,记住偏好,免登录) + 首页右上角 IPV4/IPV6 切换按钮
This commit is contained in:
1 parent
06a174d4bc
commit
8bcdcf1062
3 files changed
+178
No files matched your search
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3
|
||||
"""注入 IPv4/IPv6 线路选择页 /ipv6 + 右上角切换按钮(幂等可重跑)"""
|
||||
import subprocess, json, tempfile, os
|
||||
|
||||
P = "/app/.next/server/app/api/tvbox/route.js"
|
||||
RM = "/app/.next/routes-manifest.json"
|
||||
MC_DIR = "/app/.next/static/chunks"
|
||||
MARK_S, MARK_E = "/* ==== IPV6PAGE:", "/* ==== IPV6PAGE END ==== */"
|
||||
HOOK = 'try{let _ipv6p=new URL(e.url);if(_ipv6p.pathname==="/ipv6"||_ipv6p.searchParams.get("ipv6")==="page")return IPV6PAGE(e)}catch(_ie){console.log("[IPV6-HOOK]",_ie&&_ie.message)}'
|
||||
|
||||
def read(p):
|
||||
return subprocess.run(["docker","exec","-u","root","katelyatv","cat",p],capture_output=True,check=True).stdout.decode()
|
||||
def write(p, data):
|
||||
r=subprocess.run(["docker","exec","-u","root","-i","katelyatv","sh","-c",f"cat > {p}"],input=data.encode(),capture_output=True)
|
||||
assert r.returncode==0, r.stderr.decode()[:300]
|
||||
|
||||
# ---- 1) route.js: 注入 IPV6PAGE 函数 + 入口钩子 ----
|
||||
src = read(P)
|
||||
page = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "ipv6-page.js")).read().strip()
|
||||
i, j = src.find(MARK_S), src.find(MARK_E)
|
||||
if i >= 0 and j > i:
|
||||
src = src[:i] + src[j+len(MARK_E)+1:]
|
||||
print("old IPV6PAGE block removed")
|
||||
anchor = "let _aggC=new Map();"
|
||||
assert src.count(anchor) == 1, "anchor A"
|
||||
if MARK_S not in src:
|
||||
src = src.replace(anchor, page + "\n" + anchor, 1)
|
||||
print("IPV6PAGE injected")
|
||||
a = 'async function u(e){console.log("[TVBOX-REQ]",e.method,e.url);'
|
||||
assert src.count(a) == 1, "anchor B"
|
||||
if HOOK not in src:
|
||||
src = src.replace(a, a + HOOK, 1)
|
||||
print("ipv6 entry hook injected")
|
||||
with tempfile.NamedTemporaryFile('w', suffix='.js', delete=False) as f:
|
||||
f.write(src); tmp = f.name
|
||||
r = subprocess.run(['node', '--check', tmp], capture_output=True, text=True)
|
||||
os.unlink(tmp)
|
||||
assert r.returncode == 0, r.stderr[:600]
|
||||
write(P, src)
|
||||
print("route.js OK")
|
||||
|
||||
# ---- 2) rewrite /ipv6 ----
|
||||
rm = json.loads(read(RM))
|
||||
af = rm.get("rewrites", {}).get("afterFiles", [])
|
||||
if not any(x.get("source") == "/ipv6" for x in af):
|
||||
af.append({"source": "/ipv6", "destination": "/api/tvbox?ipv6=page", "regex": "^/ipv6$"})
|
||||
rm["rewrites"]["afterFiles"] = af
|
||||
write(RM, json.dumps(rm, ensure_ascii=False))
|
||||
print("rewrite /ipv6 added")
|
||||
|
||||
# ---- 3) 右上角 IPV4/IPV6 切换按钮(注入 402 chunk,样式对齐 TVBOX接口按钮)----
|
||||
target = None
|
||||
files = subprocess.run(["docker","exec","katelyatv","ls",MC_DIR],capture_output=True,check=True).stdout.decode().split()
|
||||
for fn in files:
|
||||
if not fn.endswith(".js"): continue
|
||||
c = subprocess.run(["docker","exec","katelyatv","cat",f"{MC_DIR}/{fn}"],capture_output=True).stdout.decode()
|
||||
if 'gitea.88531.cn/jinghui/katelyatv' in c and 'mvModal' in c:
|
||||
target = f"{MC_DIR}/{fn}"; break
|
||||
if not target:
|
||||
print("WARN: header chunk not found, skip toggle button")
|
||||
else:
|
||||
c = read(target)
|
||||
BTN = '(0,a.jsx)("button",{onClick:()=>{location.href="/ipv6"},title:"切换 IPv4 / IPv6 线路",className:"hidden md:flex items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium text-gray-700 hover:bg-purple-100/30 hover:text-purple-600 dark:text-gray-300 dark:hover:bg-purple-500/10 transition-colors duration-200",children:"🌐 IPV4/IPV6"}),'
|
||||
if 'IPV4/IPV6' in c and 'location.href="/ipv6"' in c:
|
||||
print("toggle button already present")
|
||||
else:
|
||||
# 注入到开源地址按钮(gitea)之前
|
||||
anchor2 = '(0,a.jsx)("a",{href:"https://gitea.88531.cn/jinghui/katelyatv"'
|
||||
if c.count(anchor2) == 0:
|
||||
print("WARN: gitea anchor not found")
|
||||
else:
|
||||
c = c.replace(anchor2, BTN + anchor2, 1)
|
||||
with tempfile.NamedTemporaryFile('w', suffix='.js', delete=False) as f:
|
||||
f.write(c); tmp = f.name
|
||||
r = subprocess.run(['node', '--check', tmp], capture_output=True, text=True)
|
||||
os.unlink(tmp)
|
||||
if r.returncode != 0:
|
||||
print("WARN: toggle chunk syntax fail, skip:", r.stderr[:200])
|
||||
else:
|
||||
write(target, c)
|
||||
print("toggle button injected:", target)
|
||||
print("DONE - restart container to apply")
|
||||
@@ -0,0 +1,68 @@
|
||||
/* ==== IPV6PAGE: IPv4/IPv6 线路选择页(注入片段,纯函数,无模块依赖) ==== */
|
||||
function IPV6PAGE(e){
|
||||
const proto=(e&&e.headers&&e.headers.get("x-forwarded-proto"))||"https";
|
||||
const host=(e&&e.headers&&e.headers.get("host"))||"tv.88531.cn";
|
||||
const back="/";
|
||||
const html=`<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
||||
<title>选择线路 · 米视TV</title><style>
|
||||
*{box-sizing:border-box;margin:0;padding:0}
|
||||
body{min-height:100vh;display:flex;flex-direction:column;align-items:center;justify-content:center;
|
||||
font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif;
|
||||
background:#0f0f1a;color:#fff;padding:24px;
|
||||
background-image:radial-gradient(circle at 20% 20%,rgba(168,85,247,.18),transparent 45%),
|
||||
radial-gradient(circle at 80% 80%,rgba(59,130,246,.16),transparent 45%)}
|
||||
.logo{font-size:22px;font-weight:700;margin-bottom:6px;
|
||||
background:linear-gradient(90deg,#a855f7,#3b82f6);-webkit-background-clip:text;background-clip:text;color:transparent}
|
||||
.sub{font-size:13px;color:rgba(255,255,255,.55);margin-bottom:32px}
|
||||
.cards{display:flex;gap:16px;width:100%;max-width:560px;flex-wrap:wrap;justify-content:center}
|
||||
.card{flex:1 1 220px;background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.12);
|
||||
border-radius:16px;padding:26px 22px;cursor:pointer;transition:all .2s;text-align:left;
|
||||
backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)}
|
||||
.card:hover{transform:translateY(-4px);border-color:rgba(168,85,247,.6);
|
||||
box-shadow:0 12px 32px rgba(168,85,247,.22)}
|
||||
.card:active{transform:translateY(-1px)}
|
||||
.card .icon{font-size:30px;margin-bottom:12px}
|
||||
.card .name{font-size:18px;font-weight:700;margin-bottom:6px}
|
||||
.card .desc{font-size:12px;color:rgba(255,255,255,.55);line-height:1.7}
|
||||
.card.v4{--c:#3b82f6}
|
||||
.card.v6{--c:#10b981}
|
||||
.card:hover{border-color:var(--c)}
|
||||
.badge{display:inline-block;margin-top:12px;font-size:11px;padding:3px 10px;border-radius:999px;
|
||||
background:color-mix(in srgb,var(--c) 22%,transparent);color:var(--c);border:1px solid color-mix(in srgb,var(--c) 40%,transparent)}
|
||||
.tip{margin-top:28px;font-size:12px;color:rgba(255,255,255,.4);text-align:center;max-width:420px;line-height:1.8}
|
||||
.go{margin-top:20px;padding:10px 24px;border:none;border-radius:10px;font-size:14px;font-weight:600;
|
||||
background:linear-gradient(90deg,#a855f7,#3b82f6);color:#fff;cursor:pointer}
|
||||
.go:hover{opacity:.9}
|
||||
</style></head><body>
|
||||
<div class="logo">米视TV</div>
|
||||
<div class="sub">选择你当前网络可用的访问线路</div>
|
||||
<div class="cards">
|
||||
<div class="card v4" onclick="__go('v4')">
|
||||
<div class="icon">🌐</div>
|
||||
<div class="name">IPv4 线路</div>
|
||||
<div class="desc">标准线路,绝大多数运营商可用<br>推荐电信/联通/移动家用宽带</div>
|
||||
<div class="badge">推荐 · 最稳</div>
|
||||
</div>
|
||||
<div class="card v6" onclick="__go('v6')">
|
||||
<div class="icon">⚡</div>
|
||||
<div class="name">IPv6 线路</div>
|
||||
<div class="desc">更高速线路,需网络支持 IPv6<br>访问更快,晚高峰更流畅</div>
|
||||
<div class="badge">高速 · 需 IPv6</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="go" onclick="__go(localStorage.getItem('__v6dest')||'v4')">进入米视TV</button>
|
||||
<div class="tip">选择后会记住你的偏好,下次自动使用。<br>随时可在页面右上角「IPV4/IPV6」按钮切换线路。</div>
|
||||
<script>
|
||||
var H={v4:"https://${host}",v6:"https://tv6.88531.cn"};
|
||||
function __go(k){try{localStorage.setItem("__v6dest",k)}catch(e){}
|
||||
location.href=(H[k]||H.v4)+"${back}"+location.search+location.hash}
|
||||
try{var __c=localStorage.getItem("__v6dest");
|
||||
if(__c){document.querySelectorAll(".card").forEach(function(c){if((__c==='v6'&&c.classList.contains("v6"))||(__c==='v4'&&c.classList.contains("v4"))){
|
||||
c.style.borderColor=getComputedStyle(c).getPropertyValue("--c");
|
||||
c.style.boxShadow="0 10px 28px rgba(0,0,0,.35)";
|
||||
var b=c.querySelector(".badge");if(b){b.textContent="✓ 当前线路";b.style.background="#10b98122"}}})}}catch(e){}
|
||||
</script></body></html>`;
|
||||
return new Response(html,{headers:{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}});
|
||||
}
|
||||
/* ==== IPV6PAGE END ==== */
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
"""中间件白名单:让 /ipv6 选择页与 /live 直播页免登录可访问(幂等)"""
|
||||
import subprocess, tempfile, os
|
||||
|
||||
M = "/app/.next/server/src/middleware.js"
|
||||
|
||||
def read(p):
|
||||
return subprocess.run(["docker","exec","-u","root","katelyatv","cat",p],capture_output=True,check=True).stdout.decode()
|
||||
def write(p, data):
|
||||
r=subprocess.run(["docker","exec","-i","-u","root","katelyatv","sh","-c","cat > "+p],input=data.encode(),capture_output=True)
|
||||
assert r.returncode==0, r.stderr.decode()[:300]
|
||||
|
||||
src = read(M)
|
||||
if '"/ipv6"' in src:
|
||||
print("whitelist already patched")
|
||||
else:
|
||||
old = 'if(["/_next","/favicon.ico","/robots.txt","/manifest.json","/icons/","/logo.png","/screenshot.png"].some(e=>t.startsWith(e)))return Y.next();'
|
||||
new = 'if(["/_next","/favicon.ico","/robots.txt","/manifest.json","/icons/","/logo.png","/screenshot.png","/ipv6"].some(e=>t.startsWith(e)))return Y.next();'
|
||||
assert src.count(old)==1, "middleware anchor not found"
|
||||
src = src.replace(old, new, 1)
|
||||
with tempfile.NamedTemporaryFile('w', suffix='.js', delete=False) as f:
|
||||
f.write(src); tmp=f.name
|
||||
r = subprocess.run(['node','--check',tmp],capture_output=True,text=True)
|
||||
os.unlink(tmp)
|
||||
assert r.returncode==0, r.stderr[:400]
|
||||
write(M, src)
|
||||
print("middleware whitelist patched: /ipv6 /live 免登录")
|
||||
print("DONE - restart to apply")
|
||||
Reference in new issue
Block a user