fix(download): pin frontend link generation to fixed relay config

The runtime kept reading aksrt_download_config after the settings page was
removed, so the frontend still issued download links per the stale option
values instead of the built-in defaults.

- Pin endpoint, per-token uses and TTL to built-in constants and drop all
  option reads plus the is_enabled() master switch
- Remove the now-unreachable direct-download branches from the download
  box template and the paid-card download helper
- Lock the pinned contract in the download contract tests
This commit is contained in:
kate522 committed 2026-09-24 18:45:08 +08:00
1 parent 800baca0ca
commit d49fd9f6a4
4 files changed
+51 -130

No files matched your search

+1 -25
View File
@@ -27,9 +27,6 @@ if ($pay_type !== 'download' || empty($downloads)) {
$is_resource_context = function_exists('aksrt_is_resource_post') && aksrt_is_resource_post($post_id);
$context_variant = $is_resource_context ? 'resource' : 'content';
// 下载总开关关闭 = 直连模式:下载按钮直接输出原始地址,不走本站中转链接。
$direct_download = class_exists('\AKSRT\Content\Download')
&& !\AKSRT\Content\Download::get_instance()->is_enabled();
$subject_label = trim((string) ($meta['subject_label'] ?? ''));
if ($subject_label === '') {
$subject_label = $is_resource_context ? __('资源', 'aksrt') : __('内容', 'aksrt');
@@ -60,9 +57,7 @@ $pay_modo = is_array($priced)
$user_amount = is_array($priced) ? (float) ($priced['amount'] ?? 0) : (float) ($meta['price'] ?? 0);
$cost = function_exists('aksrt_resource_download_cost') ? (int) aksrt_resource_download_cost($post_id) : 0;
// 直连模式下没有“获取链接”请求,验证码容器不会被打开,属死 UI 不渲染。
$captcha_active = !$direct_download
&& function_exists('aksrt_is_captcha_enabled_for')
$captcha_active = function_exists('aksrt_is_captcha_enabled_for')
&& aksrt_is_captcha_enabled_for('download');
$balance = (int) ($gate_data['balance'] ?? (is_user_logged_in() ? \AKSRT\Ledger\LedgerService::get_instance()->balance(get_current_user_id(), \AKSRT\Ledger\AssetType::POINTS) : 0));
$login_url = (string) ($gate_data['login_url'] ?? wp_login_url(get_permalink($post_id)));
@@ -350,10 +345,6 @@ if ($is_need_purchase && $user_amount > 0) {
}
$type = isset($row['type']) ? (string) $row['type'] : 'direct';
$url = isset($row['url']) ? (string) $row['url'] : '';
if ($direct_download && $url === '') {
// 直连模式没有可用的原始地址,空源不渲染。
continue;
}
$extract_code = isset($row['extract_code']) ? trim((string) $row['extract_code']) : '';
$has_extract = $extract_code !== '';
@@ -371,15 +362,6 @@ if ($is_need_purchase && $user_amount > 0) {
$btn_action = '';
$btn_target = '';
$btn_rel = '';
} elseif ($direct_download) {
$btn_tag = 'a';
$btn_href = $url;
$btn_text = __('立即下载', 'aksrt');
$btn_icon = 'fa-download';
$btn_modifier = $has_paid_access ? ' resource-download-box__btn--owned' : '';
$btn_action = '';
$btn_target = ' target="_blank"';
$btn_rel = ' rel="nofollow noopener"';
} else {
$btn_tag = 'button';
$btn_href = '';
@@ -406,12 +388,6 @@ if ($is_need_purchase && $user_amount > 0) {
<?php echo esc_html($service['name']); ?>
</span>
</a>
<?php if ($direct_download && $has_extract) : ?>
<button type="button" class="resource-download-box__btn resource-download-box__btn--extract"
data-clipboard-tag="<?php esc_attr_e('提取码', 'aksrt'); ?>"
data-clipboard-text="<?php echo esc_attr($extract_code); ?>"
><?php echo esc_html($extract_code); ?></button>
<?php endif; ?>
<?php else : ?>
<button
type="button"