fix: preview模式改为draft优先fallback到published(正式版+预览版并集)
This commit is contained in:
@@ -34,7 +34,7 @@ public class SnapshotController {
|
||||
* 获取站点当前生效配置快照(供 mediabot 使用)
|
||||
* 支持 ETag (If-None-Match) 实现增量更新
|
||||
* 优先从 Caffeine 缓存读取,缓存未命中查数据库并回退七牛云 CDN
|
||||
* @param preview true=读取最新 draft(预览版),false/不传=读取最新 published(正式版)
|
||||
* @param preview false/不传=仅正式版(published),true=预览版优先(draft → published fallback)
|
||||
*/
|
||||
@GetMapping("/{siteId}")
|
||||
public ResponseEntity<?> getSnapshot(
|
||||
@@ -44,7 +44,7 @@ public class SnapshotController {
|
||||
|
||||
try {
|
||||
String bundleJson = preview
|
||||
? snapshotService.getDraftBundleJson(siteId)
|
||||
? snapshotService.getPreviewBundleJson(siteId)
|
||||
: snapshotService.getActiveBundleJson(siteId);
|
||||
|
||||
if (bundleJson == null || bundleJson.isEmpty()) {
|
||||
|
||||
@@ -54,6 +54,14 @@ public interface SiteSnapshotService {
|
||||
*/
|
||||
String getDraftBundleJson(String siteId);
|
||||
|
||||
/**
|
||||
* 获取预览版快照 JSON(draft 优先,无 draft 时 fallback 到 published)
|
||||
* 即:正式版 + 预览版 的并集
|
||||
* @param siteId 站点标识
|
||||
* @return JSON 字符串,空串表示无任何快照
|
||||
*/
|
||||
String getPreviewBundleJson(String siteId);
|
||||
|
||||
/**
|
||||
* 按 checksum 判断是否需要更新
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
public boolean isChanged(String siteId, String checksum) {
|
||||
if (checksum == null) return true;
|
||||
|
||||
Reference in New Issue
Block a user