feat: auto-generate license file on download if missing

Add AppService.ensureLicenseFile() that generates and persists a license
file when the app doesn't have one yet. Update AppController.downloadLicenseFile
to use it instead of throwing "License file not generated yet".

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
这个提交包含在:
XuqmGroup 2026-05-22 19:47:53 +08:00
父节点 619e822d85
当前提交 23390570ef
共有 2 个文件被更改,包括 14 次插入4 次删除

查看文件

@ -164,10 +164,7 @@ public class AppController {
public ResponseEntity<byte[]> downloadLicenseFile(@PathVariable String appKey, public ResponseEntity<byte[]> downloadLicenseFile(@PathVariable String appKey,
@AuthenticationPrincipal String tenantId) { @AuthenticationPrincipal String tenantId) {
AppEntity app = appService.getByAppKey(appKey, tenantId); AppEntity app = appService.getByAppKey(appKey, tenantId);
String encrypted = app.getLicenseFileContent(); String encrypted = appService.ensureLicenseFile(appKey, tenantId);
if (encrypted == null || encrypted.isBlank()) {
throw new BusinessException("License file not generated yet");
}
String filename = sanitizeFileName(app.getName()) + ".xuqmlicense"; String filename = sanitizeFileName(app.getName()) + ".xuqmlicense";
return ResponseEntity.ok() return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM) .contentType(MediaType.APPLICATION_OCTET_STREAM)

查看文件

@ -12,6 +12,7 @@ import com.xuqm.tenant.config.PrivateDeploymentProperties;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -89,6 +90,18 @@ public class AppService {
return saved; return saved;
} }
@Transactional
public String ensureLicenseFile(String appKey, String tenantId) {
AppEntity app = getByAppKey(appKey, tenantId);
String content = app.getLicenseFileContent();
if (content == null || content.isBlank()) {
content = generateLicenseFileContent(app);
app.setLicenseFileContent(content);
appRepository.save(app);
}
return content;
}
public AppEntity update(String appKey, String tenantId, CreateAppRequest req) { public AppEntity update(String appKey, String tenantId, CreateAppRequest req) {
AppEntity app = getByAppKey(appKey, tenantId); AppEntity app = getByAppKey(appKey, tenantId);
Map<String, Object> before = new LinkedHashMap<>(); Map<String, Object> before = new LinkedHashMap<>();