fix(extensions): 内容审核管理端测试可绕过启用开关
后台测试此前受 content_audit_enabled/text_enabled 与 on_failure=allow 短路,未启用时恒为通过;强制 live 调用并返回可读失败原因。
This commit is contained in:
@@ -24,23 +24,34 @@ class AKSRT_Content_Audit {
|
||||
/**
|
||||
* 审核文本内容
|
||||
*
|
||||
* @param string $text 待审文本
|
||||
* @param bool $force 管理端测试用:跳过启用开关与失败放行策略,直接打服务商
|
||||
* @return array{passed: bool, reason: string, labels: array, raw: array}
|
||||
*/
|
||||
public function audit_text(string $text): array {
|
||||
public function audit_text(string $text, bool $force = false): array {
|
||||
$config = $this->get_config();
|
||||
|
||||
if (empty($config['content_audit_enabled']) || empty($config['content_audit_text_enabled'])) {
|
||||
if (
|
||||
!$force
|
||||
&& (empty($config['content_audit_enabled']) || empty($config['content_audit_text_enabled']))
|
||||
) {
|
||||
return $this->ok('disabled');
|
||||
}
|
||||
|
||||
$provider = sanitize_key((string) ($config['content_audit_provider'] ?? 'baidu'));
|
||||
$result = $this->call_text_api($provider, $text, $config);
|
||||
|
||||
if (!empty($config['content_audit_log_enabled'])) {
|
||||
// 管理端强制测试不写生产日志,避免污染审计流水
|
||||
if (!$force && !empty($config['content_audit_log_enabled'])) {
|
||||
$this->log_audit('text', $text, $result);
|
||||
}
|
||||
|
||||
if (!$result['passed'] && ($config['content_audit_on_failure'] ?? 'allow') === 'allow') {
|
||||
// 管理端强制测试保留服务商原始结论,不套用 on_failure=allow
|
||||
if (
|
||||
!$force
|
||||
&& !$result['passed']
|
||||
&& ($config['content_audit_on_failure'] ?? 'allow') === 'allow'
|
||||
) {
|
||||
$result['passed'] = true;
|
||||
$result['reason'] .= ' (failure_policy: allow)';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user