v0.1.0 核心功能: - 更新源管理 (SourceManager, SourceModel, SourceType) - 插件/主题更新器 (PluginUpdater, ThemeUpdater) - 缓存系统 (CacheManager, HealthChecker, FallbackStrategy) - 安全模块 (Validator, Encryption) - 管理界面 (AdminPage, templates, CSS, JS) - 预设源支持 (ArkPress, AspireCloud) v0.2.0 新增功能: - 性能优化 (ParallelRequestManager, RequestDeduplicator) - 条件请求 (ConditionalRequest - ETag/Last-Modified) - 后台更新 (BackgroundUpdater - WP-Cron) - Git 平台支持 (GitHub, GitLab, Gitee handlers) - WP-CLI 命令 (wp bridge source/check/cache/diagnose/config) 安全修复: - SQL 注入防护 ($wpdb->prepare) - GET 参数清理 (sanitize_text_field) - auth_token 加密存储 (AES-256-CBC) - 缓存键哈希 (md5 + site_url) - 卸载清理 (uninstall.php) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
112 lines
2.7 KiB
PHP
112 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* AspireCloud 处理器
|
|
*
|
|
* @package WPBridge
|
|
*/
|
|
|
|
namespace WPBridge\UpdateSource\Handlers;
|
|
|
|
use WPBridge\Core\Logger;
|
|
|
|
// 防止直接访问
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* AspireCloud 处理器
|
|
*/
|
|
class AspireCloudHandler extends AbstractHandler {
|
|
|
|
/**
|
|
* 获取能力列表
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_capabilities(): array {
|
|
return [
|
|
'auth' => 'token',
|
|
'version' => 'json',
|
|
'download' => 'direct',
|
|
'federation' => true,
|
|
'cdn' => true,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取检查 URL
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_check_url(): string {
|
|
return rtrim( $this->source->api_url, '/' ) . '/plugins/update-check/1.1';
|
|
}
|
|
|
|
/**
|
|
* 检查更新
|
|
*
|
|
* @param string $slug 插件/主题 slug
|
|
* @param string $version 当前版本
|
|
* @return UpdateInfo|null
|
|
*/
|
|
public function check_update( string $slug, string $version ): ?UpdateInfo {
|
|
$url = $this->build_plugin_url( $slug );
|
|
$data = $this->request( $url );
|
|
|
|
if ( null === $data ) {
|
|
return null;
|
|
}
|
|
|
|
// AspireCloud API 响应格式
|
|
$remote_version = $data['version'] ?? $data['new_version'] ?? '';
|
|
|
|
if ( empty( $remote_version ) ) {
|
|
Logger::warning( 'AspireCloud 响应缺少版本信息', [ 'url' => $url, 'slug' => $slug ] );
|
|
return null;
|
|
}
|
|
|
|
// 检查是否有更新
|
|
if ( ! $this->is_newer_version( $version, $remote_version ) ) {
|
|
Logger::debug( 'AspireCloud: 无可用更新', [
|
|
'slug' => $slug,
|
|
'current' => $version,
|
|
'remote' => $remote_version,
|
|
] );
|
|
return null;
|
|
}
|
|
|
|
// 构建更新信息
|
|
$info = UpdateInfo::from_array( $data );
|
|
$info->slug = $slug;
|
|
|
|
Logger::info( 'AspireCloud: 发现更新', [
|
|
'slug' => $slug,
|
|
'current' => $version,
|
|
'new' => $remote_version,
|
|
] );
|
|
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 获取项目信息
|
|
*
|
|
* @param string $slug 插件/主题 slug
|
|
* @return array|null
|
|
*/
|
|
public function get_info( string $slug ): ?array {
|
|
$url = $this->build_plugin_url( $slug );
|
|
return $this->request( $url );
|
|
}
|
|
|
|
/**
|
|
* 构建插件 URL
|
|
*
|
|
* @param string $slug 插件 slug
|
|
* @return string
|
|
*/
|
|
protected function build_plugin_url( string $slug ): string {
|
|
return rtrim( $this->source->api_url, '/' ) . '/plugins/info/1.2?slug=' . urlencode( $slug );
|
|
}
|
|
}
|