fix: preview模式改为draft优先fallback到published(正式版+预览版并集)

This commit is contained in:
mediabot-pt
2026-07-07 11:38:52 +08:00
parent 5f58083074
commit e15e242153
3 changed files with 20 additions and 2 deletions

View File

@@ -34,7 +34,7 @@ public class SnapshotController {
* 获取站点当前生效配置快照(供 mediabot 使用) * 获取站点当前生效配置快照(供 mediabot 使用)
* 支持 ETag (If-None-Match) 实现增量更新 * 支持 ETag (If-None-Match) 实现增量更新
* 优先从 Caffeine 缓存读取,缓存未命中查数据库并回退七牛云 CDN * 优先从 Caffeine 缓存读取,缓存未命中查数据库并回退七牛云 CDN
* @param preview true=读取最新 draft(预览版),false/不传=读取最新 published(正式版) * @param preview false/不传=仅正式版(published),true=预览版优先(draft → published fallback)
*/ */
@GetMapping("/{siteId}") @GetMapping("/{siteId}")
public ResponseEntity<?> getSnapshot( public ResponseEntity<?> getSnapshot(
@@ -44,7 +44,7 @@ public class SnapshotController {
try { try {
String bundleJson = preview String bundleJson = preview
? snapshotService.getDraftBundleJson(siteId) ? snapshotService.getPreviewBundleJson(siteId)
: snapshotService.getActiveBundleJson(siteId); : snapshotService.getActiveBundleJson(siteId);
if (bundleJson == null || bundleJson.isEmpty()) { if (bundleJson == null || bundleJson.isEmpty()) {

View File

@@ -54,6 +54,14 @@ public interface SiteSnapshotService {
*/ */
String getDraftBundleJson(String siteId); String getDraftBundleJson(String siteId);
/**
* 获取预览版快照 JSON(draft 优先,无 draft 时 fallback 到 published)
* 即:正式版 + 预览版 的并集
* @param siteId 站点标识
* @return JSON 字符串,空串表示无任何快照
*/
String getPreviewBundleJson(String siteId);
/** /**
* 按 checksum 判断是否需要更新 * 按 checksum 判断是否需要更新
*/ */

View File

@@ -295,6 +295,16 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
}); });
} }
@Override
public String getPreviewBundleJson(String siteId) {
// 先查 draft,有则返回;无则 fallback 到 published
String draftJson = getDraftBundleJson(siteId);
if (draftJson != null && !draftJson.isEmpty()) {
return draftJson;
}
return getActiveBundleJson(siteId);
}
@Override @Override
public boolean isChanged(String siteId, String checksum) { public boolean isChanged(String siteId, String checksum) {
if (checksum == null) return true; if (checksum == null) return true;