v-fixed44: 修复管理页用户配置 React #31(用户对象当用户名写入列表) + 全新用户管理面板
根因: getAllUsers() 返回 User 对象数组,config.ts 当作用户名字符串使用,
导致 Users[].username 变成对象,管理页渲染对象触发 Minified React error #31。
- 修编译产物 chunks/{3498,8583}.js 与源码 src/lib/config.ts(两处)
- 清理 Redis admin:config 嵌套脏数据 41 -> 23 条
- 新增原生 JS 用户管理面板 public-live/user-admin.js(列表/添加/改密/设为管理/封禁/删除)
- middleware 放行 /user-admin.js; layout 注入面板加载器
- 新增幂等补丁脚本 patches/fix_userlist_usernames.py
- 镜像 katelyatv:fixed44
This commit is contained in:
1 parent
f3eacaad08
commit
7dc23a29ed
7 files changed
+522
-12
No files matched your search
@@ -12,3 +12,9 @@ git.push
|
||||
node_modules/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# 上游源码克隆(体积大,单独存放)
|
||||
source/
|
||||
# 手工备份
|
||||
*.bak
|
||||
*.bak.*
|
||||
@@ -2,6 +2,23 @@
|
||||
|
||||
格式参考本机发版惯例:按日期分条,`🐛修复` / `✨新功能`。
|
||||
|
||||
## v-fixed44 (2026-11-06)
|
||||
|
||||
### ✨ 新功能
|
||||
- 👥 全新「用户管理」面板:管理页「用户配置」入口改为「用户管理」,点击打开独立面板,支持
|
||||
用户列表(用户名/角色/状态/创建时间)、添加用户、修改密码、设为管理/取消管理、封禁/解封、删除
|
||||
|
||||
### 🐛 修复
|
||||
- 🚨 管理页点击「用户配置」直接崩溃(React #31):根因是 `getAllUsers()` 返回用户对象数组,
|
||||
而配置模块把它当作用户名字符串使用,导致用户列表里 `username` 字段被写成对象,页面渲染对象报错
|
||||
- 修补编译产物 `chunks/{3498,8583}.js`,统一取用户名字符串后再补全列表
|
||||
- 同步修复源码 `src/lib/config.ts`(两处),以后重新构建不会再写坏
|
||||
- 清理 Redis `admin:config` 里 18 条嵌套脏数据,用户数 41 → 去重后 23
|
||||
|
||||
### 📦 安装/升级
|
||||
- 网页用户刷新即生效,无需清缓存;体验地址:https://tv.88531.cn
|
||||
- 重建容器后执行 `python3 patches/fix_userlist_usernames.py --repair-data` 可一键恢复全部修补
|
||||
|
||||
## v-fixed43 (2026-11-01)
|
||||
|
||||
### ✨ 新功能
|
||||
|
||||
@@ -54,7 +54,7 @@ git clone https://gitea.88531.cn/jinghui/katelyatv.git && cd katelyatv
|
||||
docker pull gitea.88531.cn/jinghui/katelyatv:latest
|
||||
# 国内慢可换腾讯云镜像(东京):
|
||||
# docker pull jpccr.ccs.tencentyun.com/jinghui/katelyatv:latest
|
||||
docker tag gitea.88531.cn/jinghui/katelyatv:latest katelyatv:fixed42 # 对齐 compose 的 image 名
|
||||
docker tag gitea.88531.cn/jinghui/katelyatv:latest katelyatv:fixed44 # 对齐 compose 的 image 名
|
||||
|
||||
cp .env.example .env
|
||||
vi .env # 至少填:PASSWORD(站点密码)、NEXTAUTH_SECRET(随机串)
|
||||
@@ -86,6 +86,8 @@ docker restart katelyatv
|
||||
|
||||
## 📝 更新日志(最近)
|
||||
|
||||
- **2026-11-06 v-fixed44**:管理页「用户配置」点击崩溃(React #31)彻底修复 —— 根因是配置模块把用户对象当用户名写进列表,已修编译产物与源码并清理 18 条脏数据;新增**全新「用户管理」面板**(用户列表 / 添加 / 改密 / 设为管理 / 封禁 / 删除)
|
||||
- **2026-11-01 v-fixed43**:IPv6 智能跳转恢复(家宽有 IPv6 自动切到 tv6 高速线路);电脑端与移动端新增「AI短剧」入口;`/live` 直播页点击画面可暂停/继续;首页公告改为授权中心动态推送
|
||||
- **2026-10-30 v-fixed38**:首页右上角新增「📺 TVBOX接口」一键复制配置地址;⭐ 开源地址与菜单版本按钮改指自建 Gitea(`https://gitea.88531.cn/jinghui/katelyatv`)
|
||||
- **2026-10-30 v-fixed37**:TVBOX 公告兼容 —— 配置同时下发 `notice` + `warning` 双字段;版本角标改由环境变量注入
|
||||
- **2026-10-30 v-fixed36**:首页右上角统一信息区(版本角标 + 🔔通知铃铛 + ⭐开源地址,仅首页显示);直播页只保留 TVBOX 接入入口
|
||||
@@ -93,13 +95,6 @@ docker restart katelyatv
|
||||
- **2026-10-29 v-fixed34**:新增访问日志与使用统计 —— 外网访问者真实 IP/UA 全记录,`./usage-stats.sh [24h|all]` 一键查看独立 IP 数、按天分布、直播观看人数
|
||||
- **2026-10-29 v-fixed33**:桌面导航与直播页右上角新增「⭐ 开源地址」入口;镜像发布至 `gitea.88531.cn/jinghui/katelyatv` 公共仓库(免登录 `docker pull`)
|
||||
- **2026-10-26 v-fixed32**:站点更名为「米视TV」(界面 / 标题 / TVBOX 内置名称 / manifest 全量替换,支持 `SITE_NAME` 环境变量自定义)
|
||||
- **2026-10-26 v-fixed31**:加载提示文字改为白色 19px 加粗 + 阴影,播放器内更醒目
|
||||
- **2026-10-26 v-fixed30**:直播页右上角新增「📺 TVBOX接入」入口,配置地址 / 直播源地址一键复制
|
||||
- **2026-10-26 v-fixed29**:直播页新增频道节目单(EPG)面板,默认隐藏、点击展开,当前节目高亮
|
||||
- **2026-10-26 v-fixed28**:播放器右下角新增暂停 / 静音悬浮按钮
|
||||
- **2026-10-26 v-fixed27**:即点即播——服务端预热线路,点击频道直接有声播放,无需再点画面
|
||||
- **2026-10-26 v-fixed26**:移除首页顶部大 Logo 区域
|
||||
- **2026-10-26 v-fixed25**:首页最新港剧扩到 10 部、按年份倒序,「查看更多」携带筛选条件
|
||||
|
||||
完整历史见 [CHANGELOG.md](CHANGELOG.md)。
|
||||
|
||||
@@ -140,14 +135,14 @@ docker/katelyatv/
|
||||
| `patch_access_log.js` | 访问日志注入([ACCESS] IP/UA/路径,供 `usage-stats.sh` 统计使用人数) |
|
||||
| `patch_license.js` | 授权系统:CardAuth 装机/心跳/公告/版本推送、`/api/license-config` 路由、首页右上角四件套(版本角标+🔔通知铃铛+📺TVBOX接口一键复制配置地址+⭐开源地址指向自建Gitea,仅首页显示;直播页移除开源按钮)、每 IP 限流 429;运行时组件见 `license-hub.js` |
|
||||
|
||||
补丁固化在本地镜像(compose 引用,当前 `katelyatv:fixed42`)。上游大版本升级后重放补丁:
|
||||
补丁固化在本地镜像(compose 引用,当前 `katelyatv:fixed44`)。上游大版本升级后重放补丁:
|
||||
|
||||
```bash
|
||||
bash patches/apply.sh # 重放补丁
|
||||
python3 patches/inject_live.py # 重放直播注入(幂等)
|
||||
docker cp license-hub.js katelyatv:/app/license-hub.js
|
||||
node patches/patch_license.js # 重放授权/角标/限流(幂等)
|
||||
docker commit katelyatv katelyatv:fixed42 # 固化新镜像
|
||||
docker commit katelyatv katelyatv:fixed44 # 固化新镜像
|
||||
docker compose -f docker-compose.redis.yml up -d
|
||||
```
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ version: '3.8'
|
||||
services:
|
||||
# KatelyaTV 应用服务
|
||||
katelyatv:
|
||||
image: katelyatv:fixed42
|
||||
image: katelyatv:fixed44
|
||||
container_name: katelyatv
|
||||
ports:
|
||||
- "3030:3000"
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
修复「管理页 → 用户配置」React #31 崩溃 + 新增独立用户管理面板。
|
||||
|
||||
根因:redis.db.ts 的 getAllUsers() 返回 User 对象数组,而 config.ts 把它当用户名
|
||||
字符串使用,导致 Users[].username 被写成 {username, role, created_at} 对象,
|
||||
管理页把该对象当文本渲染 → Minified React error #31。
|
||||
|
||||
本脚本对**运行中的容器**做幂等修补(重建镜像/重新 docker run 后需再跑一次):
|
||||
1. /app/.next/server/chunks/{3498,8583}.js —— getAllUsers 结果取用户名字符串
|
||||
2. /app/.next/server/src/middleware.js —— 放行 /user-admin.js
|
||||
3. layout chunk —— 在 /admin 注入 /user-admin.js 加载器
|
||||
4. /app/public/user-admin.js —— 全新用户管理面板(原生 JS)
|
||||
5. Redis admin:config 的 Users 去嵌套 / 去重(先备份)
|
||||
|
||||
用法: python3 patches/fix_userlist_usernames.py [--repair-data]
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
CT = os.environ.get("KAT_CONTAINER", "katelyatv")
|
||||
REDIS = os.environ.get("KAT_REDIS", "katelyatv-redis")
|
||||
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
LAYOUT = "layout-7c2e94ab10d85f36.js"
|
||||
LOADER_TAG = "USER-MGMT-LOADER-V1"
|
||||
|
||||
|
||||
def sh(cmd, **kw):
|
||||
return subprocess.run(cmd, shell=isinstance(cmd, str), check=False,
|
||||
capture_output=True, text=True, **kw)
|
||||
|
||||
|
||||
def node(script):
|
||||
r = sh(["docker", "exec", "-u", "0", CT, "node", "-e", script])
|
||||
print(r.stdout.strip() or r.stderr.strip())
|
||||
return r.returncode == 0
|
||||
|
||||
|
||||
def patch_server_chunks():
|
||||
script = r'''
|
||||
const fs=require('fs');
|
||||
const files=['3498','8583'].map(n=>'/app/.next/server/chunks/'+n+'.js');
|
||||
const from='userNames=await storage.getAllUsers()}';
|
||||
const to='userNames=(await storage.getAllUsers()).map(e=>typeof e=="string"?e:(e&&typeof e.username=="string"?e.username:"")).filter(Boolean)}';
|
||||
let touched=0;
|
||||
for(const f of files){
|
||||
if(!fs.existsSync(f)){console.log('skip missing',f);continue}
|
||||
let s=fs.readFileSync(f,'utf8');
|
||||
if(s.includes('typeof e=="string"?e:')){console.log('already patched',f);continue}
|
||||
const c=s.split(from).length-1;
|
||||
if(!c){console.log('ANCHOR MISS',f);continue}
|
||||
fs.writeFileSync(f,s.split(from).join(to)); touched+=c;
|
||||
console.log('patched',f,'x'+c);
|
||||
}
|
||||
console.log('total',touched);
|
||||
'''
|
||||
return node(script)
|
||||
|
||||
|
||||
def patch_middleware():
|
||||
script = r'''
|
||||
const fs=require('fs');const p='/app/.next/server/src/middleware.js';
|
||||
if(!fs.existsSync(p)){console.log('no middleware.js');process.exit(0)}
|
||||
let s=fs.readFileSync(p,'utf8');
|
||||
if(s.includes('"/user-admin.js"')){console.log('already allowlisted');process.exit(0)}
|
||||
if(!s.includes('"/hls.min.js",')){console.log('ANCHOR MISS middleware');process.exit(0)}
|
||||
s=s.replace('"/hls.min.js",','"/hls.min.js","/user-admin.js",');
|
||||
fs.writeFileSync(p,s);console.log('middleware allowlisted');
|
||||
'''
|
||||
return node(script)
|
||||
|
||||
|
||||
def patch_layout():
|
||||
script = r'''
|
||||
const fs=require('fs');const p='/app/.next/static/chunks/app/%(layout)s';
|
||||
if(!fs.existsSync(p)){console.log('no layout chunk');process.exit(0)}
|
||||
let s=fs.readFileSync(p,'utf8');
|
||||
if(s.includes('%(tag)s')){console.log('loader already present');process.exit(0)}
|
||||
s += '\n/*%(tag)s*/(function(){function go(){try{if(location.pathname!=="/admin")return;'
|
||||
+ 'if(document.getElementById("kat-um"))return;var s=document.createElement("script");s.id="kat-um";'
|
||||
+ 's.src="/user-admin.js?v=3";s.async=true;document.head.appendChild(s);}catch(e){}}'
|
||||
+ 'go();setInterval(go,1500);})();\n';
|
||||
fs.writeFileSync(p,s);console.log('loader injected');
|
||||
''' % {"layout": LAYOUT, "tag": LOADER_TAG}
|
||||
ok = node(script)
|
||||
sh(["docker", "exec", "-u", "0", CT, "sh", "-c",
|
||||
"chown 1001:1001 /app/.next/static/chunks/app/%s; chmod 644 /app/.next/static/chunks/app/%s" % (LAYOUT, LAYOUT)])
|
||||
return ok
|
||||
|
||||
|
||||
def copy_panel():
|
||||
src = os.path.join(BASE, "public-live", "user-admin.js")
|
||||
if not os.path.exists(src):
|
||||
print("missing", src)
|
||||
return False
|
||||
r = sh(["docker", "cp", src, "%s:/app/public/user-admin.js" % CT])
|
||||
if r.returncode != 0:
|
||||
print(r.stderr)
|
||||
return False
|
||||
sh(["docker", "exec", "-u", "0", CT, "sh", "-c",
|
||||
"chown 1001:1001 /app/public/user-admin.js; chmod 644 /app/public/user-admin.js"])
|
||||
print("panel copied")
|
||||
return True
|
||||
|
||||
|
||||
def repair_data():
|
||||
out = os.path.join("/vol1/1000/HD1/APP/hermes/cache/scratch/kat",
|
||||
"cfg_before_repair_%d.json" % int(time.time()))
|
||||
with open(out, "wb") as fh:
|
||||
r = subprocess.run(["docker", "exec", REDIS, "redis-cli", "--raw", "GET", "admin:config"],
|
||||
capture_output=True)
|
||||
fh.write(r.stdout)
|
||||
cfg = json.loads(r.stdout.decode("utf-8"))
|
||||
users = cfg["UserConfig"]["Users"]
|
||||
rank = {"user": 0, "admin": 1, "owner": 2}
|
||||
out_users, order, flattened = {}, [], 0
|
||||
for e in users:
|
||||
if not isinstance(e, dict):
|
||||
continue
|
||||
uname, role = e.get("username"), e.get("role") or "user"
|
||||
created, banned, d = e.get("created_at") or "", bool(e.get("banned")), 0
|
||||
while isinstance(uname, dict) and d < 10:
|
||||
flattened += 1
|
||||
role = uname.get("role") or role
|
||||
created = uname.get("created_at") or created
|
||||
banned = banned or bool(uname.get("banned"))
|
||||
uname, d = uname.get("username"), d + 1
|
||||
if not isinstance(uname, str) or not uname.strip():
|
||||
continue
|
||||
uname = uname.strip()
|
||||
role = role if role in rank else "user"
|
||||
rec = out_users.get(uname)
|
||||
if rec is None:
|
||||
rec = {"username": uname, "role": role}
|
||||
if created:
|
||||
rec["created_at"] = created
|
||||
if banned:
|
||||
rec["banned"] = True
|
||||
out_users[uname] = rec
|
||||
order.append(uname)
|
||||
else:
|
||||
if rank[role] > rank.get(rec["role"], 0):
|
||||
rec["role"] = role
|
||||
if created and not rec.get("created_at"):
|
||||
rec["created_at"] = created
|
||||
if banned:
|
||||
rec["banned"] = True
|
||||
cfg["UserConfig"]["Users"] = [out_users[u] for u in order]
|
||||
payload = json.dumps(cfg, ensure_ascii=False).encode("utf-8")
|
||||
r2 = subprocess.run(["docker", "exec", "-i", REDIS, "redis-cli", "-x", "SET", "admin:config"],
|
||||
input=payload, capture_output=True)
|
||||
print("data repair: %d -> %d users (flattened %d), backup %s, redis: %s"
|
||||
% (len(users), len(order), flattened, out, r2.stdout.decode().strip()))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
patch_server_chunks()
|
||||
patch_middleware()
|
||||
patch_layout()
|
||||
copy_panel()
|
||||
if "--repair-data" in sys.argv:
|
||||
repair_data()
|
||||
print("restarting app…")
|
||||
sh(["docker", "restart", CT])
|
||||
print("done")
|
||||
+23
-1
@@ -1 +1,23 @@
|
||||
if(!self.define){let e,s={};const n=(n,t)=>(n=new URL(n+".js",t).href,s[n]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=s,document.head.appendChild(e)}else e=n,importScripts(n),s()}).then(()=>{let e=s[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e}));self.define=(t,a)=>{const c=e||("document"in self?document.currentScript.src:"")||location.href;if(s[c])return;let i={};const r=e=>n(e,c),d={module:{uri:c},exports:i,require:r};s[c]=Promise.all(t.map(e=>d[e]||r(e))).then(e=>(a(...e),i))}}define(["./workbox-e9849328"],function(e){"use strict";importScripts(),self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"/_next/app-build-manifest.json",revision:"91f275d530cb6b9f82b3f622107ba69f"},{url:"/_next/static/VzjdBH-1tWUTABuCZb9nx/_buildManifest.js",revision:"85aecd8a55db42fc901f52386fd2a680"},{url:"/_next/static/VzjdBH-1tWUTABuCZb9nx/_ssgManifest.js",revision:"b6652df95db52feb4daf4eca35380933"},{url:"/_next/static/chunks/151-8711dd3ec7fbfa61.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/242-5a0502f47346ed4a.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/256-f3994669d49867be.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/273-fffc7e5390a1c642.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/402-3f8ac71d6e5b0924.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/609-46d66c37b95adf6a.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/78-b091442d784a205f.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/866-7f5b3d6941560701.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/_not-found/page-2f2263c5b98c190a.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/admin/page-82bf968fc882a918.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/config/page-c5444985ef9acb1a.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/douban/page-8ab598f0d244e9ae.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/filter/page-4d01a87b20ac1a73.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/layout-7c2e94ab10d85f36.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/login/page-47c06d2438938131.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/page-1a01a64271e1f47e.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/play/page-89b0997603e2bb9c.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/search/page-fe31cf3d4e57ebfd.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/settings/page-031109c02196f08e.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/tvbox/page-adec05c5925c4c37.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/app/warning/page-e6b20b93b37dc516.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/b145b63a-d75d6adf389a7589.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/c72274ce-909438a8a5dd87a5.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/da9543df-c2ce5269243dd748.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/framework-6e06c675866dc992.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/main-19765309852faad8.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/main-app-2cdcfd0e548fd0e6.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/pages/_app-3fcac1a2c632f1ef.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/pages/_error-d3fe151bf402c134.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/chunks/polyfills-42372ed130431b0a.js",revision:"846118c33b2c0e922d7b3a7676f81f6f"},{url:"/_next/static/chunks/webpack-f732225cafd52a05.js",revision:"VzjdBH-1tWUTABuCZb9nx"},{url:"/_next/static/css/23100062f5d4aac0.css",revision:"23100062f5d4aac0"},{url:"/_next/static/css/86f54169992d5771.css",revision:"86f54169992d5771"},{url:"/_next/static/css/da6e9b4a73108890.css",revision:"da6e9b4a73108890"},{url:"/_next/static/media/19cfc7226ec3afaa-s.woff2",revision:"9dda5cfc9a46f256d0e131bb535e46f8"},{url:"/_next/static/media/21350d82a1f187e9-s.woff2",revision:"4e2553027f1d60eff32898367dd4d541"},{url:"/_next/static/media/8e9860b6e62d6359-s.woff2",revision:"01ba6c2a184b8cba08b0d57167664d75"},{url:"/_next/static/media/ba9851c3c22cd980-s.woff2",revision:"9e494903d6b0ffec1a1e14d34427d44d"},{url:"/_next/static/media/c5fe6dc8356a8c31-s.woff2",revision:"027a89e9ab733a145db70f09b8a18b42"},{url:"/_next/static/media/df0a9ae256c0569c-s.woff2",revision:"d54db44de5ccb18886ece2fda72bdfe0"},{url:"/_next/static/media/e4af272ccee01ff0-s.p.woff2",revision:"65850a373e258f1c897a2b3d75eb74de"},{url:"/favicon.ico",revision:"c5de6e56c5664adda146825f75ea6ecf"},{url:"/icons/icon-192x192.png",revision:"4a56c090828a1ad254c903c7aec0389d"},{url:"/icons/icon-256x256.png",revision:"f6409eb1a001f754121e3a8281c0319c"},{url:"/icLine truncated
|
||||
// Self-destruct service worker: drops all old Workbox caches so browsers stop
|
||||
// serving stale Next.js chunks (source of React #31 on /admin).
|
||||
self.addEventListener('install', (event) => {
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil((async () => {
|
||||
try {
|
||||
const keys = await caches.keys();
|
||||
await Promise.all(keys.map((k) => caches.delete(k)));
|
||||
} catch (e) {}
|
||||
try {
|
||||
await self.registration.unregister();
|
||||
} catch (e) {}
|
||||
try {
|
||||
const clients = await self.clients.matchAll({ type: 'window' });
|
||||
clients.forEach((c) => c.navigate(c.url));
|
||||
} catch (e) {}
|
||||
})());
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', () => {});
|
||||
@@ -0,0 +1,301 @@
|
||||
/* 米视TV 全新用户管理面板 V1 —— 原生JS,独立于React,点击“用户配置”打开 */
|
||||
(function () {
|
||||
if (window.__KAT_USERMGMT__) return;
|
||||
window.__KAT_USERMGMT__ = 1;
|
||||
|
||||
var API_CFG = '/api/admin/config';
|
||||
var API_USER = '/api/admin/user';
|
||||
var state = { users: [], allowRegister: false, loading: false, open: false };
|
||||
|
||||
function el(tag, attrs, kids) {
|
||||
var n = document.createElement(tag);
|
||||
if (attrs) for (var k in attrs) {
|
||||
if (k === 'style') n.style.cssText = attrs[k];
|
||||
else if (k === 'text') n.textContent = attrs[k];
|
||||
else if (k.slice(0, 2) === 'on') n.addEventListener(k.slice(2).toLowerCase(), attrs[k]);
|
||||
else n.setAttribute(k, attrs[k]);
|
||||
}
|
||||
(kids || []).forEach(function (c) { if (c) n.appendChild(c); });
|
||||
return n;
|
||||
}
|
||||
|
||||
function toast(msg, ok) {
|
||||
var t = el('div', {
|
||||
text: msg,
|
||||
style: 'position:fixed;left:50%;top:24px;transform:translateX(-50%);z-index:2147483647;' +
|
||||
'background:' + (ok === false ? '#dc2626' : '#059669') + ';color:#fff;padding:10px 20px;border-radius:10px;' +
|
||||
'font-size:14px;box-shadow:0 8px 24px rgba(0,0,0,.25);font-family:inherit'
|
||||
});
|
||||
document.body.appendChild(t);
|
||||
setTimeout(function () { t.remove(); }, 2200);
|
||||
}
|
||||
|
||||
function api(action, targetUsername, targetPassword, extra) {
|
||||
var body = { action: action };
|
||||
if (targetUsername) body.targetUsername = targetUsername;
|
||||
if (targetPassword) body.targetPassword = targetPassword;
|
||||
if (extra) for (var k in extra) body[k] = extra[k];
|
||||
return fetch(API_USER, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
}).then(function (r) { return r.json().then(function (j) { return { ok: r.ok, data: j }; }).catch(function () { return { ok: r.ok, data: {} }; }); });
|
||||
}
|
||||
|
||||
function load() {
|
||||
state.loading = true; render();
|
||||
return fetch(API_CFG, { headers: { 'Cache-Control': 'no-cache' } })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (cfg) {
|
||||
var root = (cfg && cfg.Config) ? cfg.Config : (cfg || {});
|
||||
var uc = root.UserConfig || {};
|
||||
var list = Array.isArray(uc.Users) ? uc.Users : [];
|
||||
state.users = list.filter(function (u) { return u && typeof u === 'object'; }).map(function (u) {
|
||||
return {
|
||||
username: String(typeof u.username === 'object' && u.username ? (u.username.username || '') : (u.username || '')),
|
||||
role: String(u.role || 'user'),
|
||||
banned: !!u.banned,
|
||||
created_at: u.created_at ? String(u.created_at) : ''
|
||||
};
|
||||
});
|
||||
state.allowRegister = !!uc.AllowRegister;
|
||||
})
|
||||
.catch(function () { toast('读取用户列表失败', false); })
|
||||
.then(function () { state.loading = false; render(); });
|
||||
}
|
||||
|
||||
function roleLabel(r) { return r === 'owner' ? '站长' : r === 'admin' ? '管理员' : '普通用户'; }
|
||||
|
||||
function fmtDate(v) {
|
||||
if (!v) return '-';
|
||||
var d = new Date(v);
|
||||
if (isNaN(d.getTime())) return String(v).slice(0, 10);
|
||||
var p = function (n) { return (n < 10 ? '0' : '') + n; };
|
||||
return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate());
|
||||
}
|
||||
|
||||
function btn(text, color, fn, disabled) {
|
||||
var colors = {
|
||||
green: 'background:#059669;color:#fff',
|
||||
red: 'background:#dc2626;color:#fff',
|
||||
gray: 'background:#e5e7eb;color:#111827',
|
||||
purple: 'background:#7c3aed;color:#fff',
|
||||
blue: 'background:#2563eb;color:#fff'
|
||||
};
|
||||
var b = el('button', {
|
||||
text: text,
|
||||
style: 'border:0;border-radius:6px;padding:5px 10px;font-size:12px;cursor:pointer;margin:2px 3px;' +
|
||||
(colors[color] || colors.gray) + ';font-family:inherit' + (disabled ? ';opacity:.5;cursor:not-allowed' : '')
|
||||
}, []);
|
||||
if (!disabled) b.addEventListener('click', function () { fn(); });
|
||||
return b;
|
||||
}
|
||||
|
||||
function ask(title, fields, cb) {
|
||||
var wrap = el('div', { style: 'position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:2147483646;display:flex;align-items:center;justify-content:center' });
|
||||
var box = el('div', { style: 'background:#fff;border-radius:12px;padding:20px;min-width:300px;max-width:92vw;box-shadow:0 20px 50px rgba(0,0,0,.3);font-family:inherit' });
|
||||
box.appendChild(el('div', { text: title, style: 'font-size:16px;font-weight:600;margin-bottom:14px;color:#111827' }));
|
||||
var inputs = {};
|
||||
fields.forEach(function (f) {
|
||||
var lab = el('div', { text: f.label, style: 'font-size:12px;color:#6b7280;margin:8px 0 4px' });
|
||||
var inp = el('input', { type: f.password ? 'password' : 'text', placeholder: f.placeholder || '', style: 'width:100%;box-sizing:border-box;border:1px solid #d1d5db;border-radius:8px;padding:8px 10px;font-size:14px;outline:none' });
|
||||
if (f.value) inp.value = f.value;
|
||||
if (f.readonly) inp.readOnly = true;
|
||||
inputs[f.key] = inp;
|
||||
box.appendChild(lab); box.appendChild(inp);
|
||||
});
|
||||
var bar = el('div', { style: 'display:flex;justify-content:flex-end;gap:8px;margin-top:18px' });
|
||||
bar.appendChild(el('button', { text: '取消', style: 'border:0;background:#e5e7eb;color:#111827;padding:8px 16px;border-radius:8px;cursor:pointer;font-size:14px', onclick: function () { wrap.remove(); } }));
|
||||
bar.appendChild(el('button', { text: '确定', style: 'border:0;background:#059669;color:#fff;padding:8px 16px;border-radius:8px;cursor:pointer;font-size:14px', onclick: function () { cb(inputs, wrap); } }));
|
||||
box.appendChild(bar); wrap.appendChild(box); document.body.appendChild(wrap);
|
||||
var first = inputs[fields[0].key]; if (first) first.focus();
|
||||
}
|
||||
|
||||
function confirmDo(msg, fn) {
|
||||
var wrap = el('div', { style: 'position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:2147483646;display:flex;align-items:center;justify-content:center' });
|
||||
var box = el('div', { style: 'background:#fff;border-radius:12px;padding:20px;min-width:280px;max-width:92vw;box-shadow:0 20px 50px rgba(0,0,0,.3);font-family:inherit' });
|
||||
box.appendChild(el('div', { text: msg, style: 'font-size:15px;color:#111827;margin-bottom:16px;line-height:1.5' }));
|
||||
var bar = el('div', { style: 'display:flex;justify-content:flex-end;gap:8px' });
|
||||
bar.appendChild(el('button', { text: '取消', style: 'border:0;background:#e5e7eb;color:#111827;padding:8px 16px;border-radius:8px;cursor:pointer;font-size:14px', onclick: function () { wrap.remove(); } }));
|
||||
bar.appendChild(el('button', { text: '确定', style: 'border:0;background:#dc2626;color:#fff;padding:8px 16px;border-radius:8px;cursor:pointer;font-size:14px', onclick: function () { wrap.remove(); fn(); } }));
|
||||
box.appendChild(bar); wrap.appendChild(box); document.body.appendChild(wrap);
|
||||
}
|
||||
|
||||
var overlay, bodyBox;
|
||||
|
||||
function render() {
|
||||
if (!overlay) return;
|
||||
bodyBox.innerHTML = '';
|
||||
var me = '';
|
||||
try { var u = JSON.parse(localStorage.getItem('user') || '{}'); me = u && u.username ? String(u.username) : ''; } catch (e) { }
|
||||
|
||||
bodyBox.appendChild(el('div', {
|
||||
text: state.loading ? '加载中…' : '共 ' + state.users.length + ' 个用户',
|
||||
style: 'font-size:12px;color:#6b7280;margin-bottom:10px'
|
||||
}));
|
||||
|
||||
var table = el('table', { style: 'width:100%;border-collapse:collapse;font-size:13px' });
|
||||
var thead = el('thead', {}, [el('tr', {}, ['用户名', '角色', '状态', '注册时间', '操作'].map(function (h) {
|
||||
return el('th', { text: h, style: 'text-align:left;padding:8px 6px;color:#6b7280;font-weight:600;border-bottom:1px solid #e5e7eb;white-space:nowrap' });
|
||||
}))]);
|
||||
table.appendChild(thead);
|
||||
var tbody = el('tbody', {}, []);
|
||||
state.users.forEach(function (u) {
|
||||
var isOwner = u.role === 'owner';
|
||||
var isSelf = me && u.username === me;
|
||||
var ops = el('div', { style: 'display:flex;flex-wrap:wrap' }, []);
|
||||
ops.appendChild(btn('修改密码', 'blue', function () {
|
||||
ask('修改用户密码 - ' + u.username, [{ key: 'pwd', label: '新密码', password: true, placeholder: '请输入新密码' }], function (inp, w) {
|
||||
var pwd = inp.pwd.value.trim();
|
||||
if (!pwd) { toast('密码不能为空', false); return; }
|
||||
api('changePassword', u.username, pwd).then(function (r) {
|
||||
w.remove();
|
||||
if (r.ok) { toast('密码已修改'); } else { toast((r.data && r.data.error) || '修改失败', false); }
|
||||
});
|
||||
});
|
||||
}));
|
||||
if (!isOwner && !isSelf) {
|
||||
if (u.role === 'admin') {
|
||||
ops.appendChild(btn('取消管理', 'gray', function () {
|
||||
confirmDo('确定取消 ' + u.username + ' 的管理员权限?', function () {
|
||||
api('cancelAdmin', u.username).then(function (r) { toast(r.ok ? '已取消管理' : ((r.data && r.data.error) || '操作失败'), r.ok); load(); });
|
||||
});
|
||||
}));
|
||||
} else {
|
||||
ops.appendChild(btn('设为管理', 'purple', function () {
|
||||
confirmDo('确定将 ' + u.username + ' 设为管理员?', function () {
|
||||
api('setAdmin', u.username).then(function (r) { toast(r.ok ? '已设为管理员' : ((r.data && r.data.error) || '操作失败'), r.ok); load(); });
|
||||
});
|
||||
}));
|
||||
}
|
||||
ops.appendChild(btn(u.banned ? '解封' : '封禁', u.banned ? 'green' : 'red', function () {
|
||||
confirmDo((u.banned ? '确定解封 ' : '确定封禁 ') + u.username + '?', function () {
|
||||
api(u.banned ? 'unban' : 'ban', u.username).then(function (r) { toast(r.ok ? '操作成功' : ((r.data && r.data.error) || '操作失败'), r.ok); load(); });
|
||||
});
|
||||
}));
|
||||
ops.appendChild(btn('删除', 'red', function () {
|
||||
confirmDo('确定删除用户 ' + u.username + '?此操作不可恢复。', function () {
|
||||
api('deleteUser', u.username).then(function (r) { toast(r.ok ? '已删除' : ((r.data && r.data.error) || '删除失败'), r.ok); load(); });
|
||||
});
|
||||
}));
|
||||
} else if (isSelf) {
|
||||
ops.appendChild(el('span', { text: '当前登录账号', style: 'font-size:12px;color:#9ca3af;padding:6px 4px' }));
|
||||
}
|
||||
var tr = el('tr', {}, [
|
||||
el('td', { text: u.username, style: 'padding:8px 6px;border-bottom:1px solid #f3f4f6;font-weight:500;color:#111827;white-space:nowrap' }),
|
||||
el('td', { text: roleLabel(u.role), style: 'padding:8px 6px;border-bottom:1px solid #f3f4f6;color:#374151;white-space:nowrap' }),
|
||||
el('td', { text: u.banned ? '已封禁' : '正常', style: 'padding:8px 6px;border-bottom:1px solid #f3f4f6;color:' + (u.banned ? '#dc2626' : '#059669') + ';white-space:nowrap' }),
|
||||
el('td', { text: fmtDate(u.created_at), style: 'padding:8px 6px;border-bottom:1px solid #f3f4f6;color:#6b7280;white-space:nowrap' }),
|
||||
el('td', { style: 'padding:8px 6px;border-bottom:1px solid #f3f4f6' }, [ops])
|
||||
]);
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
table.appendChild(tbody);
|
||||
bodyBox.appendChild(el('div', { style: 'overflow-x:auto;border:1px solid #f3f4f6;border-radius:10px' }, [table]));
|
||||
|
||||
// 底部操作区
|
||||
var bar = el('div', { style: 'display:flex;flex-wrap:wrap;gap:8px;margin-top:14px;align-items:center' }, []);
|
||||
bar.appendChild(btn('➕ 添加用户', 'green', function () {
|
||||
ask('添加用户', [
|
||||
{ key: 'u', label: '用户名', placeholder: '字母/数字' },
|
||||
{ key: 'p', label: '密码', password: true, placeholder: '初始密码' }
|
||||
], function (inp, w) {
|
||||
var un = inp.u.value.trim(), pw = inp.p.value.trim();
|
||||
if (!un || !pw) { toast('用户名和密码不能为空', false); return; }
|
||||
api('add', un, pw).then(function (r) {
|
||||
if (r.ok) { w.remove(); toast('用户已添加'); load(); }
|
||||
else { toast((r.data && r.data.error) || '添加失败', false); }
|
||||
});
|
||||
});
|
||||
}));
|
||||
var regBtn = btn(state.allowRegister ? '注册:已开放(点击关闭)' : '注册:已关闭(点击开放)', state.allowRegister ? 'green' : 'gray', function () {
|
||||
api('setAllowRegister', null, null, { allowRegister: !state.allowRegister }).then(function (r) {
|
||||
toast(r.ok ? '注册设置已更新' : ((r.data && r.data.error) || '操作失败'), r.ok); load();
|
||||
});
|
||||
});
|
||||
bar.appendChild(regBtn);
|
||||
bar.appendChild(btn('刷新', 'blue', function () { load(); }));
|
||||
bodyBox.appendChild(bar);
|
||||
}
|
||||
|
||||
function openPanel() {
|
||||
if (state.open) return;
|
||||
state.open = true;
|
||||
overlay = el('div', {
|
||||
style: 'position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:2147483600;display:flex;align-items:flex-start;justify-content:center;padding:5vh 12px;overflow:auto'
|
||||
});
|
||||
overlay.addEventListener('click', function (e) { if (e.target === overlay) closePanel(); });
|
||||
var panel = el('div', {
|
||||
style: 'background:#fff;border-radius:14px;padding:18px;width:100%;max-width:900px;box-shadow:0 24px 60px rgba(0,0,0,.35);font-family:inherit'
|
||||
});
|
||||
var head = el('div', { style: 'display:flex;align-items:center;justify-content:space-between;margin-bottom:12px' }, []);
|
||||
head.appendChild(el('div', { text: '用户管理', style: 'font-size:18px;font-weight:700;color:#111827' }));
|
||||
head.appendChild(el('button', {
|
||||
text: '关闭', style: 'border:0;background:#f3f4f6;color:#374151;padding:6px 14px;border-radius:8px;cursor:pointer;font-size:13px',
|
||||
onclick: closePanel
|
||||
}));
|
||||
panel.appendChild(head);
|
||||
bodyBox = el('div', {}, []);
|
||||
panel.appendChild(bodyBox);
|
||||
overlay.appendChild(panel);
|
||||
document.body.appendChild(overlay);
|
||||
document.addEventListener('keydown', escClose);
|
||||
load();
|
||||
}
|
||||
|
||||
function escClose(e) { if (e.key === 'Escape') closePanel(); }
|
||||
|
||||
function closePanel() {
|
||||
state.open = false;
|
||||
if (overlay) { overlay.remove(); overlay = null; bodyBox = null; }
|
||||
document.removeEventListener('keydown', escClose);
|
||||
}
|
||||
|
||||
function findCardHeader() {
|
||||
var nodes = document.querySelectorAll('div,button,h3,span');
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var n = nodes[i];
|
||||
if (n.childElementCount === 0 && n.textContent.trim() === '用户配置') return n;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function hook() {
|
||||
var header = findCardHeader();
|
||||
if (!header || header.__katHooked) return !!header;
|
||||
header.__katHooked = 1;
|
||||
var card = header.closest('div');
|
||||
// 捕获阶段拦截,阻止 React 展开已经损坏的旧组件
|
||||
var stop = function (e) { e.preventDefault(); e.stopPropagation(); openPanel(); };
|
||||
header.addEventListener('click', stop, true);
|
||||
if (card) card.addEventListener('click', function (e) {
|
||||
// 卡片内部点空白也打开我们的面板
|
||||
if (!e.target.closest('#__kat_um_root')) { e.preventDefault(); e.stopPropagation(); openPanel(); }
|
||||
}, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start);
|
||||
else start();
|
||||
|
||||
function start() {
|
||||
if (location.pathname !== '/admin') return;
|
||||
setTimeout(function () {
|
||||
var h = findCardHeader();
|
||||
if (!h || h.__katCosmetic) return;
|
||||
h.__katCosmetic = 1;
|
||||
try { h.textContent = '用户管理'; } catch (e) {}
|
||||
try {
|
||||
var hint = document.createElement('span');
|
||||
hint.textContent = ' · 点击打开管理面板';
|
||||
hint.style.cssText = 'font-size:12px;color:#9ca3af;font-weight:400;margin-left:6px';
|
||||
if (h.parentNode) h.parentNode.appendChild(hint);
|
||||
} catch (e) {}
|
||||
}, 4000);
|
||||
var tries = 0;
|
||||
var timer = setInterval(function () {
|
||||
tries++;
|
||||
if (hook() || tries > 120) clearInterval(timer);
|
||||
}, 250);
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user