feat(backend-java): 客户端版本更新新增公开查询接口
新增 /api/version 与 /api/version/latest 公开端点,路径与 file_url 字段 兼容 Python 时代客户端固定请求,供桌面端 ShuFuAI.exe 检查更新。
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
package com.nanri.aiimage.modules.softwareversion.controller;
|
||||
|
||||
import com.nanri.aiimage.modules.softwareversion.service.SoftwareVersionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 客户端公开版本查询接口。
|
||||
*
|
||||
* <p>路径和字段必须保持与 Python 时代兼容:客户端已固定请求
|
||||
* {@code /api/version} 和 {@code /api/version/latest},不能改成 admin 前缀,
|
||||
* 也不能把 {@code file_url} 改成 {@code download_url}。</p>
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/version")
|
||||
public class PublicVersionController {
|
||||
|
||||
private final SoftwareVersionService softwareVersionService;
|
||||
|
||||
@Value("${app.version:${APP_VERSION:1.0.0}}")
|
||||
private String appVersion;
|
||||
|
||||
@Value("${app.update-url:${APP_UPDATE_URL:}}")
|
||||
private String updateUrl;
|
||||
|
||||
@GetMapping
|
||||
public Map<String, Object> currentVersion() {
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("version", appVersion == null || appVersion.isBlank() ? "1.0.0" : appVersion);
|
||||
response.put("desc", "");
|
||||
response.put("url", updateUrl == null ? "" : updateUrl);
|
||||
return response;
|
||||
}
|
||||
|
||||
@GetMapping("/latest")
|
||||
public Map<String, Object> latestVersion() {
|
||||
return softwareVersionService.latestSoftwareVersion();
|
||||
}
|
||||
}
|
||||
+22
@@ -68,6 +68,28 @@ public class SoftwareVersionService {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回客户端更新接口所需的最新版本记录。空表时保持 Flask 时代的
|
||||
* {"version": null, "file_url": null} 响应语义。
|
||||
*/
|
||||
public Map<String, Object> latestSoftwareVersion() {
|
||||
log.info("[software-version] 查询客户端最新可用版本");
|
||||
SoftwareVersionEntity entity = softwareVersionMapper.selectOne(
|
||||
new LambdaQueryWrapper<SoftwareVersionEntity>()
|
||||
.orderByDesc(SoftwareVersionEntity::getCreatedAt)
|
||||
.orderByDesc(SoftwareVersionEntity::getId)
|
||||
.last("LIMIT 1"));
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
if (entity == null) {
|
||||
result.put("version", null);
|
||||
result.put("file_url", null);
|
||||
return result;
|
||||
}
|
||||
result.put("version", entity.getVersion() == null ? "" : entity.getVersion());
|
||||
result.put("file_url", entity.getFileUrl() == null ? "" : entity.getFileUrl());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传客户端软件安装包:zip 上传 MinIO(key:nanri-image/versions/{安全版本号}.zip),
|
||||
* 并向 web_config 追加一条记录(不做"设为最新",桌面端按 created_at 倒序取第一条)。
|
||||
|
||||
Reference in New Issue
Block a user