✨ feat(video): 新增视频 CENC 解密与流式代理播放
- 逆向 SpadeA(黑桃A) PlayAuth 混淆,从 spade_a 还原 AES-128 内容密钥
- 实现 cenc-aes-ctr MP4 解密(senc 逐样本 CTR + stsd entry 修复),实测可播放
- 新增 /video/proxy/{key} 代理:稳定 key + 磁盘缓存(二次命中提速 130x)+
http.ServeContent 支持 Range/206/seek 流式播放
- /video 接口新增 output(url/proxy,默认 proxy) 与 quality(max/720p/档位key) 参数,
可由 config fanqie.video.* 配置默认值;无匹配清晰度时明确报错
- 代理映射复用 audio_cache 存储,抽取 loadMediaProxyEntry 共用;挂接 7 天缓存清理
- deploy.sh 新增 --sync-nginx:备份→重写→校验→失败自动回滚,同步视频代理段配置
This commit is contained in:
1 parent
162dde9222
commit
0aed60713a
13 files changed
+1000
-78
No files matched your search
@@ -11,6 +11,7 @@
|
||||
# ./deploy.sh --rollback # 交互式回滚到指定版本
|
||||
# ./deploy.sh --rollback v1.0.0 # 直接回滚到指定版本
|
||||
# ./deploy.sh --list # 列出所有已部署版本
|
||||
# ./deploy.sh --sync-nginx # 更新线上 nginx 配置(备份+校验+失败回滚)
|
||||
# ./deploy.sh --help # 显示帮助
|
||||
# ============================================================
|
||||
|
||||
@@ -61,6 +62,7 @@ ROLLBACK=false
|
||||
ROLLBACK_VERSION=""
|
||||
LIST=false
|
||||
FORCE=false
|
||||
SYNC_NGINX=false
|
||||
|
||||
print_help() {
|
||||
cat <<EOF
|
||||
@@ -73,6 +75,7 @@ print_help() {
|
||||
--force, -f 允许覆盖已存在的同名版本(默认报错退出)
|
||||
--rollback [版本] 回滚到指定版本(不带版本号则交互式选择)
|
||||
--list 列出所有已部署的版本
|
||||
--sync-nginx 只更新 nginx 配置(备份旧配置,校验失败自动回滚)
|
||||
--help, -h 显示此帮助
|
||||
|
||||
示例:
|
||||
@@ -103,6 +106,7 @@ while [ $i -lt ${#ARGS[@]} ]; do
|
||||
fi
|
||||
;;
|
||||
--list) LIST=true ;;
|
||||
--sync-nginx) SYNC_NGINX=true ;;
|
||||
--force|-f) FORCE=true ;;
|
||||
--help|-h) print_help; exit 0 ;;
|
||||
v*) VERSION="$arg" ;;
|
||||
@@ -206,12 +210,89 @@ restart_and_verify() {
|
||||
$SUDO journalctl -u "${APP_NAME}" -n 15 --no-pager || true
|
||||
}
|
||||
|
||||
|
||||
# 写入 nginx 配置(--init 与 --sync-nginx 共用的唯一模板来源)
|
||||
write_nginx_conf() {
|
||||
$SUDO tee "${NGINX_CONF}" >/dev/null <<NGINX_EOF
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${DOMAIN};
|
||||
|
||||
access_log /var/log/nginx/${APP_NAME}.access.log;
|
||||
error_log /var/log/nginx/${APP_NAME}.error.log;
|
||||
|
||||
# 视频解密代理:关闭缓冲,分片(Range/206)直通,避免 nginx 对大文件二次落盘
|
||||
location /video/proxy/ {
|
||||
proxy_pass http://127.0.0.1:${APP_PORT};
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host \$host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto \$scheme;
|
||||
proxy_buffering off;
|
||||
proxy_read_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:${APP_PORT};
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host \$host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto \$scheme;
|
||||
proxy_set_header Upgrade \$http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_read_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
}
|
||||
}
|
||||
NGINX_EOF
|
||||
}
|
||||
# 更新已部署服务器的 nginx 配置:备份 → 重写 → 校验 → 失败回滚
|
||||
sync_nginx_conf() {
|
||||
local backup=""
|
||||
if [ -f "${NGINX_CONF}" ]; then
|
||||
backup="${NGINX_CONF}.bak.$(date +%Y%m%d%H%M%S)"
|
||||
$SUDO cp "${NGINX_CONF}" "${backup}"
|
||||
log "已备份原配置: ${backup}"
|
||||
else
|
||||
warn "nginx 配置不存在,将写入全新配置: ${NGINX_CONF}"
|
||||
fi
|
||||
|
||||
write_nginx_conf
|
||||
log "已写入新配置: ${NGINX_CONF}"
|
||||
|
||||
if $SUDO nginx -t; then
|
||||
$SUDO systemctl reload nginx 2>/dev/null || $SUDO nginx -s reload 2>/dev/null || true
|
||||
log "nginx 配置已更新并重载"
|
||||
else
|
||||
err "nginx -t 校验失败"
|
||||
if [ -n "${backup}" ] && [ -f "${backup}" ]; then
|
||||
$SUDO cp "${backup}" "${NGINX_CONF}"
|
||||
if $SUDO nginx -t >/dev/null 2>&1; then
|
||||
$SUDO systemctl reload nginx 2>/dev/null || $SUDO nginx -s reload 2>/dev/null || true
|
||||
warn "已回滚到备份配置: ${backup}"
|
||||
fi
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# ==================== --list ====================
|
||||
if [ "$LIST" = true ]; then
|
||||
list_versions
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ==================== --sync-nginx ====================
|
||||
# 只更新 nginx 配置(给已部署服务器同步模板变更用),不动二进制与服务
|
||||
if [ "$SYNC_NGINX" = true ]; then
|
||||
command -v nginx >/dev/null 2>&1 || { err "未找到 nginx"; exit 1; }
|
||||
sync_nginx_conf
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ==================== --rollback ====================
|
||||
if [ "$ROLLBACK" = true ]; then
|
||||
if [ ! -d "${BIN_DIR}" ]; then
|
||||
@@ -326,28 +407,7 @@ WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
log "初始化 Nginx 配置: ${NGINX_CONF}"
|
||||
$SUDO tee "${NGINX_CONF}" >/dev/null <<EOF
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${DOMAIN};
|
||||
|
||||
access_log /var/log/nginx/${APP_NAME}.access.log;
|
||||
error_log /var/log/nginx/${APP_NAME}.error.log;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:${APP_PORT};
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host \$host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto \$scheme;
|
||||
proxy_set_header Upgrade \$http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_read_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
write_nginx_conf
|
||||
|
||||
|
||||
# ---- Certbot 续期后自动重载 Nginx(deploy-hook 只在续期成功时执行)----
|
||||
|
||||
Reference in new issue
Block a user