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>
这个提交包含在:
父节点
619e822d85
当前提交
23390570ef
@ -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<>();
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户