Restore unified paid download model

This commit is contained in:
2026-07-04 19:24:04 +08:00
parent ca0a550af8
commit b98faa965a
9 changed files with 246 additions and 154 deletions
+8 -8
View File
@@ -106,11 +106,11 @@ class AKSRT_Download {
public function rest_policy(WP_REST_Request $request) {
$post_id = (int) $request['id'];
$post = get_post($post_id);
if (!$post || !aksrt_is_resource_post($post)) {
return new WP_Error('aksrt_invalid', __('资源不存在', 'aksrt'), ['status' => 404]);
if (!$post || !function_exists('aksrt_is_downloadable_content') || !aksrt_is_downloadable_content($post)) {
return new WP_Error('aksrt_invalid', __('内容不存在或未启用下载能力', 'aksrt'), ['status' => 404]);
}
$meta = aksrt_get_resource_meta($post);
$meta = function_exists('aksrt_get_download_box_meta') ? aksrt_get_download_box_meta($post) : [];
$paid_settings = AKSRT_Settings::get_paid_content_settings();
$cost = aksrt_resource_download_cost($post);
$uid = get_current_user_id();
@@ -148,11 +148,11 @@ class AKSRT_Download {
$source_index = isset($params['source_index']) ? (int) $params['source_index'] : 0;
$post = get_post($post_id);
if (!$post || !aksrt_is_resource_post($post)) {
return new WP_Error('aksrt_invalid', __('资源不存在', 'aksrt'), ['status' => 404]);
if (!$post || !function_exists('aksrt_is_downloadable_content') || !aksrt_is_downloadable_content($post)) {
return new WP_Error('aksrt_invalid', __('内容不存在或未启用下载能力', 'aksrt'), ['status' => 404]);
}
$meta = aksrt_get_resource_meta($post);
$meta = function_exists('aksrt_get_download_box_meta') ? aksrt_get_download_box_meta($post) : [];
if (empty($meta['downloads'][$source_index])) {
return new WP_Error('aksrt_no_source', __('下载源不存在', 'aksrt'), ['status' => 404]);
}
@@ -245,8 +245,8 @@ class AKSRT_Download {
if (!empty($row['ua_hash']) && $row['ua_hash'] !== $ua_hash) $this->fail_410();
$post = get_post((int) $row['post_id']);
if (!$post || !aksrt_is_resource_post($post)) $this->fail_410();
$meta = aksrt_get_resource_meta($post);
if (!$post || !function_exists('aksrt_is_downloadable_content') || !aksrt_is_downloadable_content($post)) $this->fail_410();
$meta = function_exists('aksrt_get_download_box_meta') ? aksrt_get_download_box_meta($post) : [];
$idx = (int) $row['source_index'];
if (empty($meta['downloads'][$idx]['url'])) $this->fail_410();