WIP: integrate isolated beta update and diagnostic client; Release build passes, end-to-end validation pending
这个提交包含在:
1 父节点
f453508be6
当前提交
15d644c7e7
14 个文件已更改
+726
-18
没有与搜索条件相匹配的文件
+1
-1
@@ -4,7 +4,7 @@ LOCAL_PROJECT=/Users/mac/Downloads/dayumedia/dayu-color-beta
|
||||
NAS_ROOT=/Volumes/dayumedia (存储空间1)/wwwroot/dayu_media
|
||||
SOURCE_BACKUP=大鱼调色仓库 Backend/
|
||||
|
||||
映射:wp-content/mu-plugins/dayu-color-beta.php → 同相对路径;wp-content/uploads/dayu-color-beta/updates/manifest.json → 同相对路径。发行PKG不进Git,由产品Release及生产公测下载空间保存。部署工作副本仅含本专项文件,源码和脱敏交付记录由产品已有仓库保存。
|
||||
映射:wp-content/mu-plugins/dayu-color-beta.php → 同相对路径;wp-content/uploads/dayu-color-beta/updates/beta.json → 同相对路径。发行PKG不进Git,由产品Release及生产公测下载空间保存。部署工作副本仅含本专项文件,源码和脱敏交付记录由产品已有仓库保存。
|
||||
|
||||
2026-11-02盘点:目标MU插件不存在;本地工作目录新建,无未部署改动。生产共享已确认来自192.168.31.21、dayumedia (存储空间1)、smbfs且可读写。仅操作本产品命名空间,不改共享鉴权插件或其他APP。参考fcpx-qwen3-asr提交113069c74aff935db2082b5bcd8e1aa47fe1fbf2的更新校验、分批诊断与崩溃脱敏流程。
|
||||
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/** Plugin Name: 大鱼调色公测更新与诊断
|
||||
* Product-scoped beta endpoints. No changes to shared account/authentication code.
|
||||
*/
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Dayu_Color_Beta {
|
||||
const SCHEMA = '1';
|
||||
const BUNDLE = 'com.dayu.color';
|
||||
const MAX_BODY = 98304;
|
||||
const MAX_BATCH = 32;
|
||||
const EVENTS = array('process_start','process_exit','plugin_init','inspector_create','inspector_refresh',
|
||||
'device_prepare','gpu_pipeline','first_render','render_error','main_thread_stall',
|
||||
'operation_stall','previous_session_pending','crash_summary','registration','host_confirmed',
|
||||
'update_check','update_download','update_validation','update_installer','diagnostic_summary');
|
||||
const FIELDS = array('phase','stage','pipeline','duration_ms','status','error_domain','error_code',
|
||||
'exception','signal','frames','report_time','count','pending','model','os_version','fcp_version',
|
||||
'cpu_cores','memory_gb','gpu','main_delay_ms','active_stages','source_version');
|
||||
|
||||
public static function boot() {
|
||||
add_action('rest_api_init', array(__CLASS__, 'routes'));
|
||||
add_action('admin_menu', function () {
|
||||
add_management_page('大鱼调色公测', '大鱼调色公测', 'manage_options', 'dayu-color-beta', array(__CLASS__, 'admin'));
|
||||
});
|
||||
add_action('dayu_color_beta_cleanup', array(__CLASS__, 'cleanup'));
|
||||
}
|
||||
private static function table() { global $wpdb; return $wpdb->prefix . 'dayu_color_beta_events'; }
|
||||
public static function ensure_schema() {
|
||||
if (get_option('dayu_color_beta_schema') === self::SCHEMA) return;
|
||||
global $wpdb;
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
$table = self::table(); $collation = $wpdb->get_charset_collate();
|
||||
dbDelta("CREATE TABLE {$table} (
|
||||
event_id varchar(36) NOT NULL,
|
||||
installation_id varchar(36) NOT NULL,
|
||||
session_id varchar(36) NOT NULL,
|
||||
client_version varchar(32) NOT NULL,
|
||||
client_build bigint unsigned NOT NULL,
|
||||
source varchar(12) NOT NULL,
|
||||
event varchar(64) NOT NULL,
|
||||
fields_json text NOT NULL,
|
||||
occurred_at datetime NOT NULL,
|
||||
received_at datetime NOT NULL,
|
||||
PRIMARY KEY (event_id),
|
||||
KEY received_at (received_at),
|
||||
KEY client_event (client_build,event),
|
||||
KEY installation (installation_id)
|
||||
) {$collation};");
|
||||
if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table)) === $table) {
|
||||
update_option('dayu_color_beta_schema', self::SCHEMA, false);
|
||||
if (!wp_next_scheduled('dayu_color_beta_cleanup')) wp_schedule_event(time()+3600, 'daily', 'dayu_color_beta_cleanup');
|
||||
}
|
||||
}
|
||||
public static function routes() {
|
||||
self::ensure_schema();
|
||||
register_rest_route('dayu-color/v1', '/update', array('methods'=>'GET', 'permission_callback'=>'__return_true', 'callback'=>array(__CLASS__,'update')));
|
||||
register_rest_route('dayu-color/v1', '/diagnostics', array(
|
||||
array('methods'=>'POST', 'permission_callback'=>'__return_true', 'callback'=>array(__CLASS__,'ingest')),
|
||||
array('methods'=>'GET', 'permission_callback'=>function(){ return current_user_can('manage_options'); }, 'callback'=>array(__CLASS__,'events'))
|
||||
));
|
||||
}
|
||||
public static function manifest_path() {
|
||||
$upload = wp_upload_dir(null, false);
|
||||
return rtrim($upload['basedir'], '/\\') . '/dayu-color-beta/updates/beta.json';
|
||||
}
|
||||
public static function manifest() {
|
||||
$path = self::manifest_path();
|
||||
if (!is_file($path) || filesize($path)>32768) return array();
|
||||
$value = json_decode((string)file_get_contents($path), true);
|
||||
if (!is_array($value) || ($value['bundle_id']??'')!==self::BUNDLE || ($value['channel']??'')!=='beta') return array();
|
||||
if (!is_string($value['download_url']??null) || !is_string($value['sha256']??null) || !is_string($value['version']??null) || !is_int($value['build']??null) || !is_int($value['size']??null) || ($value['package_type']??'')!=='pkg' || ($value['install_mode']??'')!=='pkg_installer') return array();
|
||||
$url = $value['download_url'];
|
||||
if (!preg_match('~^https://dayu\.media/wp-content/uploads/dayu-color-beta/updates/[A-Za-z0-9_-]+\.pkg$~D', $url)) return array();
|
||||
if (!preg_match('/^[a-f0-9]{64}$/D', (string)($value['sha256']??'')) || intval($value['size']??0)<=0 || intval($value['build']??0)<=0 || intval($value['size'])>1073741824) return array();
|
||||
return $value;
|
||||
}
|
||||
public static function update($request) {
|
||||
if (($request->get_param('bundle_id')??'')!==self::BUNDLE || ($request->get_param('channel')??'beta')!=='beta') {
|
||||
return new WP_Error('product_mismatch','此通道仅用于大鱼调色公测。',array('status'=>400));
|
||||
}
|
||||
$manifest = self::manifest();
|
||||
if (!$manifest) return new WP_REST_Response(array('bundle_id'=>self::BUNDLE,'channel'=>'beta','update_available'=>false,'message'=>'当前没有公测更新。'),200,array('Cache-Control'=>'no-store'));
|
||||
$current = max(0, intval($request->get_param('current_build')));
|
||||
$manifest['update_available'] = intval($manifest['build']) > $current;
|
||||
$manifest['checked_at'] = gmdate('c');
|
||||
return new WP_REST_Response($manifest,200,array('Cache-Control'=>'no-store'));
|
||||
}
|
||||
public static function clean_fields($input) {
|
||||
if (!is_array($input)) return array();
|
||||
$out = array();
|
||||
foreach (self::FIELDS as $key) {
|
||||
if (!array_key_exists($key,$input) || !is_scalar($input[$key])) continue;
|
||||
if (in_array($key,array('duration_ms','main_delay_ms','memory_gb','cpu_cores','count','pending','error_code'),true)) {
|
||||
if (is_numeric($input[$key]) && is_finite((float)$input[$key])) $out[$key]=max(-1000000,min(86400000,(float)$input[$key]));
|
||||
continue;
|
||||
}
|
||||
$value = sanitize_textarea_field((string)$input[$key]);
|
||||
$value = preg_replace('~(?:https?://\S+|(?:/Users/|/Volumes/|/private/|/var/)[^\r\n]*)~i','[REDACTED]',$value);
|
||||
$value = preg_replace('/(?:bearer\s+\S+|(?:token|api[_-]?key|secret|password)\s*[=:]\s*\S+)/i','[REDACTED]',$value);
|
||||
$limit = $key==='frames' ? 6000 : ($key==='active_stages' ? 1000 : 200);
|
||||
$out[$key] = function_exists('mb_substr') ? mb_substr($value,0,$limit,'UTF-8') : substr($value,0,$limit);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
private static function uuid($value) { return is_string($value) && preg_match('/^[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}$/iD',$value); }
|
||||
public static function ingest($request) {
|
||||
if (strlen($request->get_body())>self::MAX_BODY) return new WP_Error('body_too_large','诊断批次过大。',array('status'=>413));
|
||||
$body = $request->get_json_params();
|
||||
if (!is_array($body) || ($body['bundle_id']??'')!==self::BUNDLE || !self::uuid($body['installation_id']??null)
|
||||
|| !isset($body['events']) || !is_array($body['events']) || count($body['events'])<1 || count($body['events'])>self::MAX_BATCH) {
|
||||
return new WP_Error('invalid_batch','诊断批次无效。',array('status'=>400));
|
||||
}
|
||||
// Anonymous beta diagnostics are untrusted input, never an authorization proof.
|
||||
$ip = (string)($_SERVER['REMOTE_ADDR']??'unknown');
|
||||
$bucket = 'dayu_color_rate_' . substr(hash_hmac('sha256',$ip,wp_salt('nonce')),0,32);
|
||||
$count = intval(get_transient($bucket));
|
||||
if ($count>=300) return new WP_Error('rate_limit','请稍后重试。',array('status'=>429));
|
||||
set_transient($bucket,$count+1,10*MINUTE_IN_SECONDS);
|
||||
$normalized = array();
|
||||
foreach ($body['events'] as $event) {
|
||||
if (!is_array($event) || !self::uuid($event['event_id']??null) || !self::uuid($event['session_id']??null)
|
||||
|| !in_array($event['event']??'',self::EVENTS,true) || !in_array($event['source']??'',array('app','plugin'),true)
|
||||
|| !is_string($event['version']??null) || strlen($event['version'])>32 || !preg_match('/^[0-9]+(?:\.[0-9A-Za-z_-]+){1,3}$/D',$event['version'])
|
||||
|| !is_int($event['build']??null) || $event['build']<1 || $event['build']>999999999
|
||||
|| !is_numeric($event['occurred_at']??null) || !is_finite((float)$event['occurred_at']) || abs((float)$event['occurred_at']-time())>366*DAY_IN_SECONDS) return new WP_Error('invalid_event','诊断事件无效。',array('status'=>400));
|
||||
$normalized[] = array('event_id'=>strtolower($event['event_id']),'installation_id'=>strtolower($body['installation_id']),
|
||||
'session_id'=>strtolower($event['session_id']),'client_version'=>substr($event['version'],0,32),
|
||||
'client_build'=>intval($event['build']),'source'=>$event['source'],'event'=>$event['event'],
|
||||
'fields_json'=>wp_json_encode(self::clean_fields($event['fields']??array()),JSON_UNESCAPED_UNICODE),
|
||||
'occurred_at'=>gmdate('Y-m-d H:i:s',(int)$event['occurred_at']), 'received_at'=>gmdate('Y-m-d H:i:s'));
|
||||
}
|
||||
global $wpdb; $table=self::table(); $accepted=array();
|
||||
foreach ($normalized as $row) {
|
||||
// Idempotent event IDs permit bounded retry after an ambiguous connection loss.
|
||||
if ($wpdb->get_var($wpdb->prepare("SELECT event_id FROM {$table} WHERE event_id=%s",$row['event_id']))) { $accepted[]=$row['event_id']; continue; }
|
||||
if ($wpdb->insert($table,$row)===false && !$wpdb->get_var($wpdb->prepare("SELECT event_id FROM {$table} WHERE event_id=%s",$row['event_id']))) return new WP_Error('storage_failed','诊断存储失败,请稍后重试。',array('status'=>503));
|
||||
$accepted[]=$row['event_id'];
|
||||
}
|
||||
return new WP_REST_Response(array('accepted'=>true,'event_ids'=>$accepted,'received_at'=>gmdate('c')),200,array('Cache-Control'=>'no-store'));
|
||||
}
|
||||
public static function cleanup() {
|
||||
global $wpdb; $table=self::table();
|
||||
$wpdb->query($wpdb->prepare("DELETE FROM {$table} WHERE received_at < %s",gmdate('Y-m-d H:i:s',time()-30*DAY_IN_SECONDS)));
|
||||
}
|
||||
public static function events($request) {
|
||||
global $wpdb; $table=self::table(); $where='1=1'; $values=array();
|
||||
foreach (array('build'=>'client_build','event'=>'event','installation'=>'installation_id') as $param=>$column) {
|
||||
$raw=$request->get_param($param);$value = is_scalar($raw)?sanitize_text_field((string)$raw):'';
|
||||
if ($value!=='') { $where.=" AND {$column}=%s"; $values[]=$value; }
|
||||
}
|
||||
$page=max(1,min(1000,intval($request->get_param('page'))));
|
||||
$sql="SELECT event_id,installation_id,session_id,client_version,client_build,source,event,fields_json,occurred_at,received_at FROM {$table} WHERE {$where} ORDER BY received_at DESC LIMIT 50 OFFSET " . (($page-1)*50);
|
||||
$rows=$wpdb->get_results($values?$wpdb->prepare($sql,$values):$sql,ARRAY_A);
|
||||
return array('events'=>$rows?:array(),'page'=>$page,'retention_days'=>30);
|
||||
}
|
||||
public static function admin() {
|
||||
if (!current_user_can('manage_options')) return;
|
||||
self::ensure_schema(); global $wpdb; $table=self::table();
|
||||
$request = new WP_REST_Request('GET');
|
||||
foreach (array('build','event','installation') as $key) $request->set_param($key,is_string($_GET[$key]??null)?sanitize_text_field(wp_unslash($_GET[$key])):'');
|
||||
$request->set_param('page',max(1,intval($_GET['paged']??1)));
|
||||
$result=self::events($request);$manifest=self::manifest();
|
||||
$devices=intval($wpdb->get_var($wpdb->prepare("SELECT COUNT(DISTINCT installation_id) FROM {$table} WHERE received_at >= %s",gmdate('Y-m-d H:i:s',time()-7*DAY_IN_SECONDS))));
|
||||
echo '<div class="wrap"><h1>大鱼调色公测</h1><p>近7天报告设备:<strong>'.esc_html($devices).'</strong> · 诊断保留30天。匿名公测标识用于关联问题,不代表账号或设备授权。</p>';
|
||||
echo '<h2>公测更新</h2><p>'.($manifest?'当前版本:'.esc_html($manifest['version']).'('.esc_html($manifest['build']).')':'尚未发布更新包').'</p>';
|
||||
echo '<h2>诊断事件</h2><form method="get"><input type="hidden" name="page" value="dayu-color-beta">';
|
||||
foreach (array('build'=>'构建号','event'=>'事件','installation'=>'完整报告标识') as $key=>$label) echo '<label>'.esc_html($label).' <input name="'.esc_attr($key).'" value="'.esc_attr($request->get_param($key)).'"></label> ';
|
||||
echo '<button class="button">筛选</button></form><table class="widefat striped"><thead><tr><th>时间(UTC)</th><th>版本</th><th>报告标识</th><th>来源/事件</th><th>内容</th></tr></thead><tbody>';
|
||||
foreach ($result['events'] as $row) {
|
||||
echo '<tr><td>'.esc_html($row['received_at']).'</td><td>'.esc_html($row['client_version'].' ('.$row['client_build'].')').'</td><td><code>'.esc_html($row['installation_id']).'</code><br>会话 '.esc_html(substr($row['session_id'],0,8)).'</td><td>'.esc_html($row['source'].' / '.$row['event']).'</td><td><pre style="white-space:pre-wrap;max-width:760px">'.esc_html(wp_json_encode(json_decode($row['fields_json'],true),JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)).'</pre></td></tr>';
|
||||
}
|
||||
echo '</tbody></table><p>';
|
||||
$base=array('page'=>'dayu-color-beta','build'=>$request->get_param('build'),'event'=>$request->get_param('event'),'installation'=>$request->get_param('installation'));
|
||||
if ($result['page']>1) echo '<a class="button" href="'.esc_url(add_query_arg(array_merge($base,array('paged'=>$result['page']-1)),admin_url('tools.php'))).'">上一页</a> ';
|
||||
if (count($result['events'])===50) echo '<a class="button" href="'.esc_url(add_query_arg(array_merge($base,array('paged'=>$result['page']+1)),admin_url('tools.php'))).'">下一页</a>';
|
||||
echo '</p><p>仅包含产品版本、环境、阶段耗时、错误代码及本插件崩溃摘要,不接收素材、预设、硬件UUID或账户凭据。</p></div>';
|
||||
}
|
||||
}
|
||||
Dayu_Color_Beta::boot();
|
||||
在新工单中引用
屏蔽一个用户