fix: 站点编辑实现编辑弹窗+PUT端点, 配置查看修复(加载失败)改用/content端点+DTO加submitterId

This commit is contained in:
mediabot-pt
2026-06-30 00:32:14 +08:00
parent 48d0e6a247
commit 550535f882
9 changed files with 158 additions and 10 deletions

View File

@@ -52,7 +52,34 @@ public class ConfigController {
}
/**
* 下载指定版本配置(支持 ETag 条件请求)
* 查看配置内容(管理员用,返回 ApiResponse 包装)
*/
@GetMapping("/{siteId}/{version}/content")
public ApiResponse<String> viewConfigContent(
@PathVariable("siteId") String siteId,
@PathVariable("version") String version) {
SiteConfig config = configService.getConfig(siteId, version);
if (config == null) {
return ApiResponse.error(404, "配置不存在: " + siteId + " v" + version);
}
String content;
try {
content = storageService.read(config.getStoragePath());
} catch (Exception e) {
log.error("Failed to read config: siteId={}, version={}", siteId, version, e);
return ApiResponse.error(500, "读取配置文件失败: " + e.getMessage());
}
if (content == null) {
return ApiResponse.error(404, "配置文件不存在: " + config.getStoragePath());
}
return ApiResponse.success(content);
}
/**
* 下载指定版本配置(支持 ETag 条件请求,供 mediabot 客户端使用)
*/
@GetMapping("/{siteId}/{version}")
public ResponseEntity<String> downloadConfig(

View File

@@ -38,6 +38,29 @@ public class SiteController {
return ApiResponse.success(siteService.toDTO(siteService.findBySiteId(siteId)));
}
/**
* 编辑站点基本信息(需 JWT 认证,管理员操作)
*/
@PutMapping("/{siteId}")
public ApiResponse<SiteDTO> updateSite(
@PathVariable("siteId") String siteId,
@RequestBody Map<String, Object> payload,
HttpServletRequest request) {
String name = (String) payload.get("name");
String description = (String) payload.get("description");
String baseUrl = (String) payload.get("baseUrl");
String siteType = (String) payload.get("siteType");
Long operatorId = (Long) request.getAttribute("accountId");
try {
Site site = siteService.updateSite(siteId, name, description, baseUrl, siteType, operatorId);
return ApiResponse.success(siteService.toDTO(site));
} catch (IllegalArgumentException e) {
return ApiResponse.error(404, e.getMessage());
}
}
/**
* 提交站点收录(需 HMAC 鉴权)
* 创建或更新站点信息,自动设置为活跃状态