登录居中 · 个人 slogan · 三种生日 · 称呼视角化 · 附件统一走代理

按九点反馈一次性改造:

1. 登录页「图标 + 用手机号登录你的家书」包进 .auth-head 并真正居中
   (以前只加了个 class 名,没有样式,看着像做了其实没做)。

2. slogan 改成两段式:系统级 slogan 作兜底,每个人可在自己的资料里写一个,
   填了就显示自己的、留空就回落到系统那句。settings 里「家庭名称」字段去掉
   (只在安装时归档,不参与展示)。

3. 三个生日:身份证生日(从证件号截取,永不改动)/真实阳历/农历。
   同一人填了其一即自动推出另一个(靠 birthday_source 指明填的是哪一侧,
   不依赖 JS)。三者落在同一天时合并成一条提醒,否则分别提醒。
   农历表不是照抄流传的那份 lunarInfo(它在 5 个年份上是错的)——
   用五个独立实现按 7.3 万天多数表决重新推导,再要求 100% 重现。

4. 称呼改成「视角属性」:nicknames(family_id, viewer_id, target_id, nickname)。
   「小明」不是某个人的属性——同一个人被不同人叫法不同,所以是「谁看」的属性。
   旧的 persons.nickname 由 Nickname::migrateLegacy() 搬到新表,只搬一次。

5. 点自己的头像/名字直接进「我的资料」,不必再绕
   「名册 → 找到自己 → 编辑资料」三步。

6. 附件(头像与其它上传)一律走 media.php 代理,不再直连 uploads/ 或云端地址:
   可读性由登录态决定而不是「知道文件名」,Content-Type/缓存/下载头由服务端统一给。
   uploads/ 整个目录 deny(含历史遗留备份文件),并有真实探针验证。

7. OSS 设置页加「连通性测试」(本地 / 云端两个按钮),逐步给出结论与耗时。

8. 生日输入改用「原生日期框 + 24 小时制时:分:秒 三个下拉」:
   datetime-local 的格式由浏览器 UI 语言决定(中文环境渲染成「下午 03:30」,
   没有秒、还容易把上下午填反)。点输入框任意一处都能弹出选择器(showPicker)。

9. 结构版本号收敛成 Schema::VERSION 一处,安装时即盖章,避免首次请求白跑升级。

验证(全部为「先注入 bug 证伪、再跑通过」):
  php -l 42 个文件;e2e 149 条;老库升级专测 37 条;反向验证 23 个注入全被抓;
  桌面几何 108 条(768/1280/1920/2560);移动端真机几何 212 条(360/375/390/414);
  交互检查 49 条(生日整框可点、登录居中)。
This commit is contained in:
2026-09-30 09:44:55 +08:00
parent 1669ab48d0
commit 7e9b4520c0
26 changed files with 2561 additions and 204 deletions
+140
View File
@@ -335,4 +335,144 @@ final class OssDriver implements StorageDriver
}
return $this->objectUrl($key);
}
// ---------------- 连通性诊断 ----------------
/**
* 一步一步把「连不上 OSS」的原因定位到具体的哪一环。
*
* 为什么不能只用一个"测试存储是否可用"的按钮:
* 失败时它只会说"写入失败" —— 而失败可能是 6 种完全不同的原因
* (没填 bucket / 凭据取不到 / 桶地域与本机不同 / 内网域名解析不了 /
* AK 没这个桶的权限 / 桶 ACL 不是私有…),用户根本无从下手。
* 这里把每一步的**结论与耗时**都摊开,一眼能看出卡在哪。
*
* @return array<int, array{name:string,ok:bool,detail:string,ms:int}>
*/
public function diagnose(): array
{
$steps = [];
// ① 配置完整性(纯本地判断,最快,先挡掉一半问题)
$err = $this->validateConfig();
$steps[] = [
'name' => '配置完整性',
'ok' => $err === '',
'detail' => $err !== '' ? $err : sprintf('bucket=%s endpoint=%s 前缀=%s 凭据方式=%s',
$this->cfg['bucket'] ?: '(空)',
$this->endpoint() ?: '(空)',
trim((string)($this->cfg['prefix'] ?? '')) !== '' ? trim((string)$this->cfg['prefix']) : '(无)',
($this->cfg['auth_mode'] ?? 'ak') === 'ecs_role' ? '服务器绑定角色' : 'AccessKey'),
'ms' => 0,
];
if ($err !== '') {
return $steps; // 配置都没填全,后面每一步都会以同样的原因失败,不必刷屏
}
// ② 凭据
$t0 = microtime(true);
$cred = $this->credentials();
$ms = (int)round((microtime(true) - $t0) * 1000);
$steps[] = [
'name' => '取凭据',
'ok' => !empty($cred['ok']),
'detail' => !empty($cred['ok'])
? (($this->cfg['auth_mode'] ?? 'ak') === 'ecs_role'
? '已从实例 RAM 角色取到临时凭据' : '使用填写的 AccessKey')
: (string)($cred['error'] ?? '取不到凭据'),
'ms' => $ms,
];
if (empty($cred['ok'])) {
return $steps;
}
// ③ 地域比对 —— 跨地域时内网域名能解析但永远连不上,必须先说出来
$bucketRegion = $this->bucketRegion();
$ecsRegion = EcsMeta::region($this->familyId);
$sameRegion = ($bucketRegion === '' || $ecsRegion === '' || $bucketRegion === $ecsRegion);
$steps[] = [
'name' => '地域',
'ok' => $sameRegion,
'detail' => $bucketRegion === '' || $ecsRegion === ''
? sprintf('本机地域=%s 桶地域=%s(信息不全,跳过内网加速)',
$ecsRegion ?: '未知', $bucketRegion ?: '未知')
: ($sameRegion
? "本机与桶都在 {$bucketRegion},内网可达"
: "本机在 {$ecsRegion}、桶在 {$bucketRegion} —— **不是同一地域**,内网走不通,只能走公网"),
'ms' => 0,
];
// ④ 公网 endpoint 可达性(HEAD 桶,即使 403 也证明网络通了)
$url = $this->scheme() . '://' . $this->host() . '/';
$res = Http::send('HEAD', $url, $this->readHeaders('/', $cred, [], 'HEAD'), null, 10, 5);
$steps[] = [
'name' => '公网 endpoint 可达',
'ok' => (int)$res['status'] > 0,
'detail' => (int)$res['status'] > 0
? sprintf('%s → HTTP %d%s', $url, (int)$res['status'],
(int)$res['status'] === 403 ? '(可达;403 只是没有 ListBucket 权限,正常)' : '')
: (string)($res['error'] ?? '连不上'),
'ms' => (int)($res['ms'] ?? 0),
];
if ((int)$res['status'] === 0) {
return $steps; // 公网都不通,后面没意义
}
// ⑤ 内网 endpoint(只在同地域且配了内网时才测;跨地域测它是白等超时)
$internal = $this->internalEndpoint();
if ($internal !== '') {
if (!$sameRegion) {
$steps[] = ['name' => '内网 endpoint', 'ok' => true,
'detail' => '跳过:跨地域时内网域名能解析但连不上,测了只会白等一次超时', 'ms' => 0];
} else {
$iurl = $this->scheme() . '://' . trim((string)$this->cfg['bucket']) . '.' . $internal . '/';
$ires = Http::send('HEAD', $iurl, $this->readHeaders('/', $cred, [], 'HEAD'), null, 5, 2);
$steps[] = [
'name' => '内网 endpoint(服务端读取更快且免流量费)',
'ok' => (int)$ires['status'] > 0,
'detail' => (int)$ires['status'] > 0
? sprintf('%s → HTTP %d', $iurl, (int)$ires['status'])
: sprintf('%s → %s(会自动回退公网,功能不受影响)', $iurl, (string)($ires['error'] ?? '连不上')),
'ms' => (int)($ires['ms'] ?? 0),
];
}
}
// ⑥ 真写一个对象再读回来再删掉 —— 唯一能证明"有权限"的一步
$probeKey = 'avatars/.diag-' . bin2hex(random_bytes(6)) . '.txt';
$payload = 'familybook-diag-' . time();
$t0 = microtime(true);
$put = $this->putContents($payload, $probeKey, 'text/plain');
$putMs = (int)round((microtime(true) - $t0) * 1000);
if (empty($put['ok'])) {
$steps[] = ['name' => '写入(PUT)', 'ok' => false,
'detail' => (string)($put['error'] ?? '写入失败')
. ' —— 常见原因:这个 AK 对这个桶没有 PutObject 权限,或桶 ACL 不是私有/公共读写。',
'ms' => $putMs];
return $steps;
}
$steps[] = ['name' => '写入(PUT)', 'ok' => true, 'detail' => '对象已写入 ' . $probeKey, 'ms' => $putMs];
$get = $this->get($probeKey);
$same = !empty($get['ok']) && trim((string)$get['body']) === $payload;
$steps[] = [
'name' => '读回(GET)',
'ok' => $same,
'detail' => $same
? '读回内容与写入一致'
: sprintf('写入成功但读回来对不上(HTTP %d)—— 多半是内网/外网 endpoint 指错,或桶有版本/加密设置',
(int)($get['status'] ?? 0)),
'ms' => (int)($get['ms'] ?? 0),
];
$del = $this->delete($probeKey);
$steps[] = [
'name' => '删除(DELETE)',
'ok' => !empty($del['ok']),
'detail' => !empty($del['ok']) ? '探针对象已清理' : (string)($del['error'] ?? '删不掉(会留下垃圾文件)'),
'ms' => 0,
];
return $steps;
}
}