feat(ov): public read api on replicas with hot sorting
P2 Task 6(ov 公开读 API + viewer 切换):
- ov 装配 PublicOvModule(仅 app-ov.module):/public/albums/{token}、
/photos、/photos/{id} 三端点同契约读 ov 副本——translations/categories
自 JSON 列解析(防御性过滤),banner 经 ov 侧 STORAGE_PORT_OV 预签名
(同本地 MinIO;只读属约定,真实 OSS 只读凭证 P5),viewCount 取
album_stats 权威累计(无行默认 0;计数端点 Task 8 接线)
- 排序:latest=发布时间 keyset(shared/cursor.ts 同 cn);hot=likeTotal
desc + photoId desc 决胜,顺序按 `${albumId}|${category}` 短期快照
(内存 TTL 默认 30s,HOT_SORT_TTL_MS 惰性读取)——计数逐请求现读、
顺序冻结窗口内一致,偏移游标(base64url 整数)在快照内严格稳定;
非法 sort 400 VALIDATION_FAILED(cn 不感知该参数)
- 契约:viewCount 放宽为 integer|null(cn null、ov 权威值);
listPublicPhotos 增 sort 枚举(latest|hot,缺省 latest);
PhotoPublishedPayload 增 categoryId——补上 Tasks 3/4 管线缺口
(payloads/publish.service/sync-inbox 投影 + 关联测试随改)
- e2e(services/api/test/public-ov.e2e-spec.ts,7 用例):双入口同进程
起 cn+ov,cn API 种子→真实发送管线投递;断言相册/列表/单图与 cn
深等(仅签名 URL 剔除)、banner 真字节、参数矩阵 400/404、hot 排序
TTL 内快照(计数新/顺序旧)+TTL 过期翻转+偏移翻页、隐藏/下线/紧急
停用逐态撤下
- viewer 切 ov:API 基址 VITE_API_BASE(缺省 http://127.0.0.1:8081,
空串=同源网关;Vite 只读 apps/viewer/.env*,根 .env 对前端无效),
移除 /v1 dev 代理(CORS_ORIGINS 增 127.0.0.1:5175 直连两形);
playwright webServer 增 dev:ov;e2e 夹具 flushSync(albumId)=cn
bootstrap 快照 + deliverPendingOnce(sender 新导出)经真实管线投影
种子,deleteSeededPhoto 改软删让墓碑可同步;14 个 Playwright 全绿
(journey 管理/staffB 腿仍走 cn 8080)
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import { expect, test, type Page } from '@playwright/test';
|
||||
import { cleanupSeededAlbums, deleteSeededPhoto, seedAlbum, seedPhoto } from './helpers';
|
||||
import {
|
||||
cleanupSeededAlbums,
|
||||
deleteSeededPhoto,
|
||||
flushSync,
|
||||
seedAlbum,
|
||||
seedPhoto,
|
||||
} from './helpers';
|
||||
|
||||
// Task 8 大图查看器 Playwright(真实后端):点击开大图(browse 经签名 URL 取回
|
||||
// 真实字节)→ 左右切换保持列表序列 → 滚轮缩放(受控 transform)→ 关闭回原滚动
|
||||
// 位置 → 深链直达(单图先行 + 背后列表构成序列)→ 404 深链本地化提示 → 越过
|
||||
// 末页边界的导航扩展序列。
|
||||
// 末页边界的导航扩展序列。种子直种 cn 侧后 flushSync 投影到 ov(viewer 读 ov)。
|
||||
|
||||
test.afterAll(async () => {
|
||||
await cleanupSeededAlbums();
|
||||
@@ -19,8 +25,11 @@ const RATIOS: Array<{ width: number; height: number }> = [
|
||||
];
|
||||
|
||||
/** 种「查看器相册」:count 张已发布照片,publishedAt 逐张递减 60s(列表顺序确定)。
|
||||
* 返回 token 与按列表顺序排列的 photoId。 */
|
||||
async function seedViewerAlbum(alias: string, count: number): Promise<{ token: string; photoIds: string[] }> {
|
||||
* 返回 token 与按列表顺序排列的 photoId。种子后 flushSync 投影到 ov。 */
|
||||
async function seedViewerAlbum(
|
||||
alias: string,
|
||||
count: number,
|
||||
): Promise<{ albumId: string; token: string; photoIds: string[] }> {
|
||||
const album = await seedAlbum({
|
||||
alias,
|
||||
translations: [{ locale: 'zh-CN', title: '大图查看测试相册' }],
|
||||
@@ -37,7 +46,8 @@ async function seedViewerAlbum(alias: string, count: number): Promise<{ token: s
|
||||
}),
|
||||
);
|
||||
}
|
||||
return { token: album.publicToken, photoIds };
|
||||
await flushSync(album.id);
|
||||
return { albumId: album.id, token: album.publicToken, photoIds };
|
||||
}
|
||||
|
||||
async function openLocale(page: Page, token: string, path = ''): Promise<void> {
|
||||
@@ -135,9 +145,11 @@ test('deep link opens on the target photo with the list loaded behind', async ({
|
||||
|
||||
test('deep link to a removed photo shows the localized notice and a working back link', async ({ page }) => {
|
||||
test.setTimeout(90_000);
|
||||
const { token, photoIds } = await seedViewerAlbum('viewer-404', 2);
|
||||
const { token, albumId, photoIds } = await seedViewerAlbum('viewer-404', 2);
|
||||
const gone = photoIds[1]!;
|
||||
await deleteSeededPhoto(gone); // 模拟照片已下线(旧分享链接)
|
||||
// 模拟照片已下线(旧分享链接):软删 + flushSync 让墓碑走真实管线撤下 ov 副本。
|
||||
await deleteSeededPhoto(gone);
|
||||
await flushSync(albumId);
|
||||
|
||||
await openLocale(page, token, `/p/${gone}`);
|
||||
const notice = page.locator('.deep-link-notice');
|
||||
|
||||
Reference in New Issue
Block a user