feat: 默认页面模板增加上传按钮+对应后端接口
This commit is contained in:
@@ -17,6 +17,7 @@ public class SitePagesController {
|
||||
|
||||
private final SitePagesService sitePagesService;
|
||||
private final com.par.core.mapper.SiteMapper siteMapper;
|
||||
private final com.par.core.storage.CachedStorageService storageService;
|
||||
|
||||
@GetMapping("/api/v1/sites/{siteId}/pages")
|
||||
public ApiResponse<Map<String, Object>> getPages(@PathVariable String siteId) {
|
||||
@@ -109,6 +110,21 @@ public class SitePagesController {
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
/** 发布默认页面模板到云存储 */
|
||||
@PutMapping("/api/v1/admin/default-pages/{type}/upload")
|
||||
public ApiResponse<Void> uploadDefaultPages(
|
||||
@PathVariable String type, @RequestBody Map<String, Object> payload, HttpServletRequest request) {
|
||||
checkAdmin(request);
|
||||
@SuppressWarnings("unchecked")
|
||||
var entries = (List<Map<String, Object>>) payload.get("entries");
|
||||
sitePagesService.savePages("default:" + type, entries != null ? entries : List.of());
|
||||
String json = payload.containsKey("entries")
|
||||
? new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(entries)
|
||||
: "[]";
|
||||
storageService.store("pages/default/" + type + ".json", json);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
private void checkAdmin(HttpServletRequest request) {
|
||||
var level = request.getAttribute("trustLevel");
|
||||
if (level == null || !"ADMIN".equals(level.toString())) {
|
||||
|
||||
Reference in New Issue
Block a user