From ab495854d559e6b04c2702bc1220a977852e0aba Mon Sep 17 00:00:00 2001
From: unknown
Date: Thu, 24 Sep 2026 19:12:45 +0800
Subject: [PATCH] feat(download): switch download buttons to direct source
links
The token relay still stood between the button and the file: every click
issued a short-lived token URL, so downloads never reached the real
source address directly.
- Render direct anchors (target=_blank) to the raw source URL in the
download box and the paid card, with inline extract-code buttons
- Retire the relay: delete Content\Download plus its init wiring, header
query-var branch and SEO noindex branch, and drop the dead
download-request flow from cms-download.js (cashier, scan-pay and
error views stay)
- Keep the dl_token table and the download logs page as read-only
history; unscheduling of the orphaned cleanup cron is preserved
---
assets/js/cms-download.js | 114 +---
functions.php | 3 -
inc/helpers/aksrt-pay.php | 20 +-
inc/helpers/homepage/header-components.php | 7 +-
src/Admin/Native/PayDownloadLogs.php | 2 +-
src/Content/Download.php | 538 ------------------
src/Core/SEOHead.php | 11 -
templates/parts/resource-download-box.php | 52 +-
.../download-config-contract.test.cjs | 120 ----
.../download-direct-contract.test.cjs | 92 +++
10 files changed, 118 insertions(+), 841 deletions(-)
delete mode 100644 src/Content/Download.php
delete mode 100644 tests/widget-system/download-config-contract.test.cjs
create mode 100644 tests/widget-system/download-direct-contract.test.cjs
diff --git a/assets/js/cms-download.js b/assets/js/cms-download.js
index 15b69868..03e2ec09 100644
--- a/assets/js/cms-download.js
+++ b/assets/js/cms-download.js
@@ -2,9 +2,9 @@
* AKSRT CMS Download
*
* 功能:
- * - 监听 [data-action="aksrt-download"] 按钮点击
- * - 调 POST /aksrt/v1/download/request
- * - 成功后直接打开生成的下载链接;失败/购买等场景仍走弹窗
+ * - 监听购买入口(data-aksrt-pay-content / data-action="aksrt-need-purchase")
+ * - 内容购买收银台、扫码支付与错误提示弹窗
+ * - 下载已改为直连:按钮为源地址锚点,不再经过本站中转请求
*
* 弹窗视觉走主题 design token(见 assets/css/frontend/cms-download.css),
* 付费收银台沿用参考实现的 colorful header 结构。
@@ -140,7 +140,6 @@
// ===== 统一视图壳(下载 / 错误 / 扫码共用主题化外观) =====
// 头部与按钮统一继承运行时主题色(--focus-color),状态用图标 + 标题区分。
const DL_VIEWS = {
- success: { icon: 'fa-cloud-download-alt', title: '下载已就绪' },
login: { icon: 'fa-user-lock', title: '请先登录' },
purchase: { icon: 'fa-shopping-cart', title: '请先购买' },
vip: { icon: 'fa-gem', title: '会员专属' },
@@ -251,34 +250,8 @@
}
}
- // ===== 成功:直接打开生成的下载链接,不再弹窗 =====
- function startDownload(payload, returnFocusEl) {
- const url = payload && payload.dl_url ? String(payload.dl_url) : '';
- if (!url) {
- renderError('下载链接生成失败,请稍后重试', {}, returnFocusEl);
- return;
- }
- // 与旧版弹窗内「立即下载」一致:新标签页打开本站中转链接。
- const link = document.createElement('a');
- link.href = url;
- link.target = '_blank';
- link.rel = 'noopener noreferrer';
- document.body.appendChild(link);
- link.click();
- link.remove();
- }
- // ===== 主流程 =====
- function captchaScope(sourceEl) {
- const box = sourceEl ? sourceEl.closest('[data-aksrt-download-box]') : null;
- return box ? (box.querySelector('[data-aksrt-download-captcha]') || box) : sourceEl;
- }
- function isCaptchaActive(sourceEl) {
- const card = sourceEl ? sourceEl.closest('[data-aksrt-download-box]') : null;
- if (!card) return false;
- return card.getAttribute('data-captcha') === '1';
- }
function cashierHeader() {
return '';
}
}
diff --git a/inc/helpers/homepage/header-components.php b/inc/helpers/homepage/header-components.php
index 339020f0..f212a4db 100644
--- a/inc/helpers/homepage/header-components.php
+++ b/inc/helpers/homepage/header-components.php
@@ -49,13 +49,10 @@ if (!function_exists('aksrt_header_slide_current_page_type')) {
*
* Custom rewrite requests can retain WordPress's is_home flag, so the
* explicit theme surfaces must win before the home fallback is evaluated.
- * Utility rewrites (download token hand-off, go-link confirm) are error /
- * hand-off surfaces and opt out entirely, like the excluded templates.
+ * Utility rewrites (go-link confirm) are error / hand-off surfaces and
+ * opt out entirely, like the excluded templates.
*/
function aksrt_header_slide_current_page_type(): string {
- if (class_exists('\AKSRT\Content\Download') && (string) get_query_var(\AKSRT\Content\Download::QUERY_VAR) !== '') {
- return '';
- }
if ((string) get_query_var('aksrt_go_redirect') !== '') {
return '';
}
diff --git a/src/Admin/Native/PayDownloadLogs.php b/src/Admin/Native/PayDownloadLogs.php
index a79d7cb9..6330f365 100644
--- a/src/Admin/Native/PayDownloadLogs.php
+++ b/src/Admin/Native/PayDownloadLogs.php
@@ -76,7 +76,7 @@ class PayDownloadLogs {
$total = $result['total'];
$pages = max(1, (int) ceil($total / $per_page));
- echo '' . esc_html__('基于下载令牌表(aksrt_dl_token)。已使用记录会保留一段时间后清理;未使用且过期的令牌会被定期删除。', 'aksrt') . '
';
+ echo '' . esc_html__('基于下载令牌表(aksrt_dl_token)。下载已改为直连模式,不再签发新令牌,以下为历史记录。', 'aksrt') . '
';
echo '
-
-
-
-
-
-