修复:全站图片 503 —— oss.enabled 派生写入被 has() 守卫拦掉
问题:attachment.storage 存成 oss,但 oss.enabled 一直停在 0。 media.php 判 fb_oss_enabled() 为 false,直接 503「对象存储未配置」, 所有 OSS 附件(历史 + 新增)全部打不开。 根因有两层: 1. oss.enabled 是派生字段,表单里没有对应 input,上一个提交加的 $save() 统一守卫用 $has() 判断「没提交」就 return,把它挡掉了; 2. 更根本的是两份状态描述同一件事 —— storage 和 enabled 迟早漂移。 修法: - 派生写入改用 $saveForce(),并整段包进 if ($has(attachment.storage)), 避免反向问题(没提交存储方式时被默认值改成 off); - fb_oss_enabled() 改为只看 attachment.storage 作单一事实来源, oss.enabled 仅在 storage 完全没配过的老库上作为回落。
This commit is contained in:
+18
-1
@@ -34,7 +34,24 @@ function fb_oss_cfg($k = null, $d = null) {
|
||||
*/
|
||||
function fb_oss_enabled() {
|
||||
$c = fb_oss_cfg();
|
||||
if (empty($c['enabled'])) { return false; }
|
||||
|
||||
/* 🔴 启用判据只看 attachment.storage(单一事实来源)。
|
||||
*
|
||||
* 原先这里只看 oss.enabled —— 而 oss.enabled 是个【派生字段】:
|
||||
* 后台表单里没有对应的 input,只能由保存逻辑“顺手”写一次。
|
||||
* 两份状态描述同一件事,就必然有漂移的一天,实际也真的漂了:
|
||||
* 2026-11-03 attachment.storage=oss 而 oss.enabled=0,
|
||||
* 结果上传/读取全被判成「对象存储未配置」,全站图片 503。
|
||||
*
|
||||
* 现在只有 storage 完全没配过(老库、安装向导中途)才回落到 oss.enabled。
|
||||
*/
|
||||
$storage = strtolower(trim((string)fb_cfg('attachment.storage', '')));
|
||||
if ($storage !== '') {
|
||||
if ($storage !== 'oss') { return false; } // local / off → OSS 一律不启用
|
||||
} elseif (empty($c['enabled'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (['bucket', 'endpoint'] as $k) {
|
||||
if (trim((string)(isset($c[$k]) ? $c[$k] : '')) === '') { return false; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user