feat(pay): wire VIP-tier pricing into cost, gates, and download box

Resolve user-facing pay amounts via aksrt_get_user_pay_price (cash/points +
VIP1/2 tiers), surface pay_modo/pay_limit through download meta and REST policy,
and tighten content-visibility / download-box UX for member-only and purchase
gates while improving local stream throttle math.
This commit is contained in:
kate522 committed 2026-07-14 11:13:17 +08:00
1 parent 1c8e4d3919
commit abe2f57417
5 files changed
+459 -127

No files matched your search

+24 -6
View File
@@ -114,6 +114,11 @@ class AKSRT_Download {
$paid_settings = AKSRT_Settings::get_paid_content_settings();
$cost = aksrt_resource_download_cost($post);
$uid = get_current_user_id();
$priced = function_exists('aksrt_get_user_pay_price') ? aksrt_get_user_pay_price($post, $uid) : null;
$pay_modo = is_array($priced)
? ((($priced['modo'] ?? '0') === 'points') ? 'points' : '0')
: ((($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0');
$display_price = is_array($priced) ? (float) ($priced['amount'] ?? 0) : (float) ($meta['price'] ?? 0);
$need_captcha = !empty($paid_settings['download_captcha']) || !empty($meta['require_captcha']);
if ($need_captcha && function_exists('aksrt_is_captcha_enabled_for') && !aksrt_is_captcha_enabled_for('download')) {
@@ -122,7 +127,10 @@ class AKSRT_Download {
return new WP_REST_Response([
'post_id' => $post_id,
'price' => (float) $meta['price'],
'price' => $display_price,
'base_price' => is_array($priced) ? (float) ($priced['base'] ?? $display_price) : (float) ($meta['price'] ?? 0),
'pay_modo' => $pay_modo,
'pay_limit' => (int) ($meta['pay_limit'] ?? 0),
'cost' => $cost,
'require_login' => !empty($paid_settings['download_login']) || !empty($meta['require_login']) || (!empty($paid_settings['free_logged_show']) && $cost <= 0),
'require_captcha' => $need_captcha,
@@ -139,7 +147,7 @@ class AKSRT_Download {
'type' => $row['type'] ?? 'direct',
'has_extract' => $extract_code !== '',
];
}, $meta['downloads'], array_keys($meta['downloads'])),
}, $meta['downloads'] ?? [], array_keys($meta['downloads'] ?? [])),
], 200);
}
@@ -354,14 +362,25 @@ class AKSRT_Download {
header('Content-Length: ' . (string) $size);
$chunk = 1024 * 64; // 64KB
$sleep_us = 0;
if ($speed_kb > 0) {
$chunk = max(1024, min($chunk, $speed_kb * 1024));
// Emit ~speed_kb KB per second using fixed 64KB chunks when possible.
$bytes_per_sec = max(1024, $speed_kb * 1024);
$chunk = min(1024 * 64, $bytes_per_sec);
$chunk = max(1024, $chunk);
// Sleep so chunk_bytes / second ≈ bytes_per_sec.
$sleep_us = (int) max(0, (int) round(($chunk / $bytes_per_sec) * 1000000) - 1000);
}
$fh = fopen($path, 'rb');
if (!$fh) {
$this->fail_410();
}
// Disable output compression for accurate Content-Length / throttle.
if (function_exists('apache_setenv')) {
@apache_setenv('no-gzip', '1');
}
@ini_set('zlib.output_compression', 'Off');
while (!feof($fh)) {
$buf = fread($fh, $chunk);
if ($buf === false) {
@@ -371,9 +390,8 @@ class AKSRT_Download {
if (function_exists('flush')) {
flush();
}
if ($speed_kb > 0) {
// Approximate throttle: sleep 1s per speed_kb window when chunk ~= speed_kb KB.
usleep(200000); // 0.2s per chunk for smoother throttle
if ($sleep_us > 0) {
usleep($sleep_us);
}
}
fclose($fh);